Questions tagged [code-translation]

For questions regarding the translation of code from one programming language to another. NOTE that asking to have your code translated is not suitable for Stack Overflow.

Translating code from one programming language to another can be as tricky as translating between natural languages. This is due to the fact that languages implement different sets of features and are often designed with very different goals. What comes as a built-in function in one language may have to be developed from scratch (or at least require a library) to achieve the same functionality in another.

An appropriately formed question might be "How do I translate this statement", or "What are the differences between these two statements in different languages". It is not appropriate to ask for your code to be translated.

388 questions
6
votes
2 answers

Convert closure to es6 module

I'm using a javascript build environment that supports es6 modules (using es6-module-transpiler) so you can simply import stuff across different files. Now I got a third party library that I'd like to be "importable". The library populates its…
Doe Johnson
  • 1,374
  • 13
  • 34
6
votes
2 answers

Expressing do block using only monadic bind syntax

As far as I know, do blocks in Haskell are just some kind of syntactic sugar for monadic bind operators. For example, one could convert main = do f <- readFile "foo.txt" print f print "Finished" to main = readFile "foo.txt" >>=…
Uli Köhler
  • 13,012
  • 16
  • 70
  • 120
6
votes
1 answer

Translation of PL/SQL code to Java using Antlr 4 and stringtemplate 4

I am trying to construct a translator that could convert PL/SQL code to Java using Antlr 4 and StringTemplate 4. I have the grammar of PL/SQl and have already build a parser for PL/SQL but i have no idea how to approach the problem further. I found…
ayush narula
  • 11,275
  • 2
  • 15
  • 18
6
votes
1 answer

Is there a program that translates Scheme/Java/Ruby code to english sentences?

I found this article about converting english sentences to Scheme, but can't seem to find any efforts to do the inverse (i.e. Scheme to english sentences): ftp://ftp.cs.utexas.edu/.snapshot/hourly.2/pub/AI-Lab/tech-reports/UT-AI-TR-87-48.pdf Plus, I…
6
votes
3 answers

Translating code from Python to Smalltalk

Let me say first that I'm NOT searching for automagical solutions here. I want to translate code from Python to Smalltalk because I've noticed some very simple sentences can be automatically translated, examples: Assigning a variable to a…
user183928
  • 783
  • 3
  • 9
5
votes
2 answers

Is it possible to / How to get the c++ code generated from running pythran on python

Pythran is a Python-to-C++ compiler for a subset of Python that includes partial numpy support. It acts a little like Numba and Cython—you annotate a function’s arguments, and then it takes over with further type annotation and code…
ntg
  • 12,950
  • 7
  • 74
  • 95
5
votes
3 answers

Translate matlab to python/numpy

I am looking for an automatic code translator for Matlab to Python. I downloaded and installed LiberMate but it is not documented anywhere and I wasn't able to make it work. Has anybody dealt with this kind of challenge before? Any advice welcome.
Mermoz
  • 14,898
  • 17
  • 60
  • 85
5
votes
2 answers

How do we avoid boilerplate code in files transpiled by Babel?

For example, if I run babel src --source-maps --out-dir . --modules common on the src folder of my project, it output all the files in ., but each and every file contains things like var _createClass = (function () { function…
trusktr
  • 44,284
  • 53
  • 191
  • 263
5
votes
0 answers

Efficient MATLAB cart2sph and sph2cart functions in python

I translated the MATLAB cart2sph and sph2cart functions to python in this way. import numpy as np def cart2sph(x,y,z): azimuth = np.arctan2(y,x) elevation = np.arctan2(z,np.sqrt(x**2 + y**2)) r = np.sqrt(x**2 + y**2 + z**2) return…
overcomer
  • 2,244
  • 3
  • 26
  • 39
5
votes
5 answers

Advice on translating code from very unrelated languages (in this case Scheme to Python)?

Reasoning: I'm trying to convert a large library from Scheme to Python Are there any good strategies for doing this kind of conversion? Specifically cross-paradigm in this case since Python is more OO and Scheme is Functional. Totally subjective so…
Michael
  • 313
  • 2
  • 8
5
votes
4 answers

How to "Export" code the right way?

I have a project in Java and I need to make a code listing in part of my LaTeX documentation with all my classes and code. What is the best way to export the code? Is it simply just copy and paste, or is there a way to export the code properly to…
KP65
  • 13,315
  • 13
  • 45
  • 46
5
votes
1 answer

Preserving comments in `Text.Parsec.Token` tokenizers

I'm writing a source-to-source transformation using parsec, So I have a LanguageDef for my language and I build a TokenParser for it using Text.Parsec.Token.makeTokenParser: myLanguage = LanguageDef { ... commentStart = "/*" , commentEnd = "*/" …
Lambdageek
  • 12,465
  • 1
  • 25
  • 33
5
votes
2 answers

Transpiler and compiler

I was wondering between the transpiler and compiler. For example, I have a language('let's call it foo') and it will be transpiled to javascript. foo -----transpiled-----> javascript However, is foo limited under javascript? Such as: "JavaScript…
Lok Jun
  • 1,315
  • 2
  • 9
  • 16
5
votes
1 answer

Equivalent of (IntPtr)1 in VBNET?

I've taken a piece of code from a @Hans Passant code from here: Bold text in MessageBox this is the C# code: SendMessage(hText, WM_SETFONT, mFont.ToHfont(), (IntPtr)1) Which would be the translation into vb.net? This will not work (cant be…
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
5
votes
2 answers

Is it possible to automatically convert JavaScript into TypeScript?

I wrote a game using coffeescript but I would have preferred to write it in typescript. The brute force way to resolve this is to convert the code by hand. But I'm wondering if there's a way to take the coffeescript or the javascript generated by…
Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356