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
5
votes
2 answers

How to convert python source code to C++ source code

I have been trying to find a way to convert .py source file to .cpp source (as a time saver from doing it manually). I've never used python before and was hoping for a quick way to convert it, and cleanup any code the converter might not do well. So…
quandrei
  • 204
  • 1
  • 3
  • 10
5
votes
1 answer

Tool to convert Java source to C++ source

Before someone shoots me down, I am aware of the Java to binary compilers and I'm not after one of those. I also know there will be no perfect tool that converts everything without any problems. I am aware that missing Java libraries are a major…
mP.
  • 18,002
  • 10
  • 71
  • 105
4
votes
1 answer

Translating a fixed-point operator to Haskell language

I am trying to translate this JS fixed-point operator into Haskell. JS: const fix = F => { const D = X => F( t => X(X)(t) ) return D(D) }; My attempt is (Haskell): fix' f = d d where d x = f (\t -> x x t) However, I get…
4
votes
2 answers

What are good techniques for rewriting nested for loops in Haskell?

I'm learning Haskell and currently trying to rewrite this code: case class Coord(x: Int, y: Int) def buildBoard(coords: [Coord]): String = { var str = "" for (i <- 0 to 30) { for (j <- 0 to 40) { if (coords.exists(c => c.x…
4
votes
1 answer

How to translate this JavaScript code snippet to Parenscript?

I have this code snippet working on the browser using JavaScript: document.querySelectorAll('[rel="next"]'); It returns an array that is empty or filled depending on the current web page. I am trying to translate it to Parenscript inside a function…
Pedro Delfino
  • 2,421
  • 1
  • 15
  • 30
4
votes
1 answer

Implement interface but having different property names

I though it would be easy, but I have a code like this one in VB.Net: Sub Main Dim foo As IMyInterface(Of String) = New Cander() foo.Items.Add("Hello") Debug.WriteLine(foo.Items.First()) End Sub Interface IMyInterface(Of Out T) …
rasputino
  • 691
  • 1
  • 8
  • 24
4
votes
2 answers

Is the unchecked keyword necessary in the VB.NET version of this C# statement?

I'm converting to VB.NET, which doesn't provide the unchecked keyword. But it appears to be unnecessary in this statement: const int dwAccess = unchecked((int)0xC0000000); I have two observations here: dwAccess is declared as a constant The value…
InteXX
  • 6,135
  • 6
  • 43
  • 80
4
votes
2 answers

Common Lisp code for a C++ program with nested loops

I am a Common Lisp beginner, but not so in C++. There's a simple C++ program that I am trying to mirror in CL (see Pollard's Rho algorithm variant example in C++ ). The C++ program runs without errors. One requirement is that all the outputs from…
Subham Burnwal
  • 310
  • 2
  • 17
4
votes
4 answers

Allowing a method to lock its parent Object in Java

Is there a way in Java to get a method to lock (mutex) the object which it is in? I know this sounds confusing but basically I wan't an equivelent to this snippet of C# but in Java. lock(this) { // Some code here... } I've been tasked with…
Omar Kooheji
  • 54,530
  • 68
  • 182
  • 238
4
votes
2 answers

Equivalent PyQt code for C++ Qt Snippet

I'm using PyQt and understand enough OOP to get by comfortably in Python. However, the documentation and useful forum posts are all in C++. I know that the best route would probably be to just re-learn C++. I'm trying but It's taking a long time to…
pbreach
  • 16,049
  • 27
  • 82
  • 120
4
votes
2 answers

Assignment Insertion in ROSE compiler after AssignOp

Lately I've been working with the ROSE compiler and I was able to apply a few insertions of code into C source and get a successful output. However, I haven't been able to insert an assignment statement when visiting SgAssignOps. This is a…
4
votes
1 answer

Converting CRC 8 function written in C to Java

I am trying to translate a CRC8 function from C to Java. I got this code from the hardware manufacturer: uint8_t CRCCalc (uint8_t* pointer, uint16_t len) { uint8_t CRC = 0x00; uint16_t tmp; while(len > 0) { tmp = CRC << 1; …
Nikita G.
  • 65
  • 1
  • 8
4
votes
1 answer

Setting up LESS file watcher in webstorm

If I add a "File Watcher" to compile .less files into .css files in webstorm with the default option it makes the .less file becomes a "node" and the .css file is created inside it. The macro system seems to me a little tricky, I just want to create…
Plastic
  • 9,874
  • 6
  • 32
  • 53
4
votes
2 answers

Converting C to PHP?

Is there any tool available that takes C code as input and outputs valid PHP files? I'd like to use the SAC API but all the implementations currently available are in C, Java, Ruby and Perl. I wonder if the C implementation can be converted to PHP…
eozzy
  • 66,048
  • 104
  • 272
  • 428
4
votes
3 answers

printing array values in js

I'm trying to create a function that will run through an array and collect it's value to a string that looks like this: '[1,2,3]'. I also need it to present only part of the array in some cases, according to a given index. For example: the array…
user1545072