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
2
votes
1 answer

Translate a project under Git

I have a small Python project (a few hundred lines) in a Git repository. I started it myself, and wrote it in French. That is, all identifiers, comments, and text strings. Now, in order for other, non-French speaking people, to be able to use it, I…
Axel
  • 811
  • 6
  • 15
2
votes
1 answer

Help me translate this Java to Scheme to get things going in my head

I am learning Scheme, and I've read the basics but I still can't figure how to "map" a Java class to Scheme code. Could any of you guys help me out here? I just need someone to show me how this looks in Scheme to grasp the final details and get…
Tsundoku
  • 9,104
  • 29
  • 93
  • 127
2
votes
1 answer

How can I use data.table in a package without importing all functions?

I'm building an R package in which I would like to use dtplyr to perform various bits of data manipulation. My issue is that dtplyr seems to only work if I import the whole of data.table (i.e. using the roxygen #' @import data.table). Without this I…
wurli
  • 2,314
  • 10
  • 17
2
votes
4 answers

How can I put an array inside a struct in C#?

C++ code: struct tPacket { WORD word1; WORD word2; BYTE byte1; BYTE byte2; BYTE array123[8]; } static char data[8192] = {0}; ... some code to fill up the array ... tPacket * packet = (tPacket *)data; We can't do that as easy in…
Ivan Prodanov
  • 34,634
  • 78
  • 176
  • 248
2
votes
1 answer

Recursion and Backtracking in Haskell

I decided to teach myself Haskell and tried to translate some code from Java to Haskell so I can get more familiar with recursion, backtracking and search tree pruning. Java Code : private static boolean isListOkay(ArrayList numbers) { …
2
votes
3 answers

Why can terminals have synthesized attributes but not inherited attributes?

In Aho et al's Compilers: Principles, Techniques, and Tools on page 305 it says "Terminals can have synthesized attributes, but not inherited attributes." Here's my hang up: if synthesized attributes are attributes that can be computed based on a…
2
votes
2 answers

"Cartiesian Product" Method in C++

I have the following code in come C++ I need to translate to C# int** _cartesianProduct(int sizeA, int sizeB) { int** array = (int**)malloc(sizeof(int*) * sizeA * sizeB + sizeof(int) * 2 * sizeA * sizeB); int* ptr = (int*)(array + sizeA *…
MoonKnight
  • 23,214
  • 40
  • 145
  • 277
2
votes
1 answer

MIPS: Translating C code to MIPS problem in function calls and returns

I need to change C code from below to a MIPS code but I am new to MIPS and stuck with it. Here is the C code: int main() { int a, b, result; if(a == b) result = a*b; else result = assess(a, b); return result; } int…
asd dsa
  • 31
  • 4
2
votes
0 answers

Converting binary file reading (fread) code from MATLAB to C#

I need to reproduce in C# a MATLAB code I found, which reads a binary file. The code is: % Skip header fread(fid, 1, 'int32=>double', 0, 'b'); % Read one property at the time i = 0; while ~feof(fid) i = i + 1; % Read field name (keyword) and…
calarez
  • 55
  • 5
2
votes
1 answer

Translate scheme to java

During the reading SICP I encouraged with Exercise 2.32. We can represent a set as a list of distinct elements, and we can represent the set of all subsets of the set as a list of lists. For example, if the set is (1 2 3 4), then the set of all…
2
votes
1 answer

Haskell Function to Clojure function conversion

Trying to convert Haskell function to Clojure. But facing difficulties. Not sure what's happening. Here's recursive Haskell function. mapWidth :: [[Char]] -> Int mapWidth [] = 0 mapWidth (x:xs) | length xs == 0 = length x | length x /=…
Aravind
  • 534
  • 1
  • 6
  • 18
2
votes
1 answer

AS3 delete dictionary[key] in Haxe

I have come across this when using as3hx to port my AS3 code to Haxe: delete classMemberDictionary[key] as3hx can't translate this to Haxe, you have to do it manually. I've read the as3hx README and it says if it is a local variable, replace…
frostbyte
  • 103
  • 2
  • 8
2
votes
5 answers

Can a scripting language be translated into other languages?

Can a scripting language be translated into C, C++, or Java so it can be run on an IDE without rewriting the code?
2
votes
3 answers

Translating Haskell to C for use on iPhone

I've written a Haskell library I would like to include in an iPhone app. It makes heavy use of Haskell's functional abilities, currying, etc. and rewriting in Objective-C would be tough. Is it possible to automatically translate Haskell to C? or…
hosiers
  • 39
  • 3
2
votes
1 answer

How are expressions allowed inside Haskell do blocks

In the following code, line 4, I have an expression sandwiched between two IO actions in a do block: 1 doubleX :: (Show x, Num x) => x -> IO () …