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.
386
questions
0
votes
0
answers
10
views
How to switch between 2 languages with a button and not a dropdown with WPML?
It's silly to have dropdown when you have only two languages. Makes sense if there are more. I want to have just a simple button that will switch to the other language and I can't find any guide on ...
1
vote
1
answer
50
views
Node.js: How to import/require a file, run its commands and access its updated variables like in Python?
In python you can just have file1.py with a class called "class1" like this:
class class1:
def __init_(self, var1, var2):
self.var3 = var1
self.var4 = var2
...
2
votes
1
answer
47
views
Why does passing a large dictionary from python to julia flatten contained multidimensional lists?
Okay so...I'm in the process of creating a python client for a coding game I play. This game is originally created in javascript and employs a json object of game data found at https://adventure.land/...
0
votes
2
answers
115
views
trying to convert C to Lisp
I am trying to convert this code to lisp code.
But don't know how to do it
is it right?
for (j=i-1; j>=0 && list[j]>key; j--) {
list[j+1] = list[j];
}
(loop (set j (- i 1))
(setq (...
0
votes
1
answer
153
views
Java to Solidity translator: is there a possibility to write smart contracts in Java?
Is there a tool out there that can automatically convert Java to Solidity? And can we convert Java file to Solidity?
I found that there exists Jthereum that is in its beta version now. Is there a ...
0
votes
0
answers
70
views
Calculating euclidean distance in a matrix
I am trying to calculate the euclidean distance in a matrix in C, I saw a similar post and tried it on my own matrix but as it is different I do not know how to make it work. This is my code:
#include ...
0
votes
0
answers
35
views
Real-time translation between s-expressions and sweet expressions
What would it take to enable real-time (in-editor) translation between regular LISP S-expressions and an alternative notation such as using indentation to indicate parentheses or infix notation? The ...
0
votes
1
answer
137
views
Translate back to english before sending the search parameter using weglot
I am using Weglot in my single-page application (Angular). The following code adds a language switcher in my application on all pages.
<script type="text/javascript" src="https://cdn....
-3
votes
1
answer
172
views
is there any way to convert this python code into php [closed]
what i need to accomplish is to reach a way in which i can convert the basics on any python code into php functions and conditions and so on
def BitmapHoles(strArr):
bitmap = {}
for i in ...
-2
votes
1
answer
129
views
Converting Visual Basic 6 source code into Java [closed]
I have a task to do code-translation of some parts of the application that is written in VB6 into Java. Now, I have two problems, first is that I have never done such a thing, so I'm inexperienced, ...
1
vote
0
answers
467
views
Converting from PyTorch to Tensorflow for Self-Attention Pooling Layer
I have found an implementation of the said layer from this paper, "Self-Attention Encoding and Pooling for Speaker Recognition", available at here via Pytorch. However, due to CUDA ...
1
vote
1
answer
110
views
Count runs lazily in Python translate from Haskell
I'm trying to write a generator function (or achieve the equivalent) which takes an iterable xs in Python and counts the "runs". (This is a problem in Thinking Functionally with Haskell by ...
1
vote
0
answers
103
views
Do-expression expansion in Haskell [duplicate]
I have a fragment of code from the Get Programming with Haskell book which looks as follows:
listToSTUArray :: [Int] -> ST s (STUArray s Int Int)
listToSTUArray vals = do
let end = length vals ...
2
votes
1
answer
188
views
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 ...
0
votes
2
answers
134
views
python slicing vs matlab slicing
I'm trying to cnvert this line to python:
xx=wqtran((nn-1)*N*2/K+nN,(mm-1)*N*2/K+nN,kk-1);
both (nn-1)*N*2/K+nN and (mm-1)*N*2/K+nN are [[1..128]] meaning array of 2D array with the shape ...
0
votes
0
answers
77
views
Trying to encode String in Java/NodeJS(One Time Password)
I have wrote a pice of code in NodeJS that encodes a secret string to otp key to use in another application. Now I want to make the same thing in Java for several uses.
NodeJS:
const crypto = require(&...
0
votes
0
answers
157
views
How to exclude/ignore file/folder in angular i18n
When I extract the translation by ng extract-i18n there are some messages from external libs have been included like:
node_modules/@ng-bootstrap/ng-bootstrap/src/alert/alert.ts
Do we have any option ...
4
votes
1
answer
158
views
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 ...
-2
votes
1
answer
102
views
what is the Maple translation for this Matlab code?
uu = polyval(polyfit(x,u,N),xx); % interpolate grid data
The code above is written in Matlab. How to write this statement in Maple?
0
votes
1
answer
210
views
Translate Typescript to Java [closed]
I'm trying to change a code that is in Typescript into Java. I really don't know much about Typescript and got stuck on this function. I reduced the code into a simpler case. In this case CustomType1 ...
4
votes
2
answers
154
views
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) {
...
4
votes
1
answer
90
views
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 ...
0
votes
1
answer
103
views
Circular reference of templates in C++
Consider something like this in C#:
class C<T> {}
class D : C<E> {}
class E : C<D> {}
Is an equivalent construction possible in C++ using templates?
1
vote
0
answers
35
views
What is the PyQuery equivalent of jQuery's ._data.map()?
I've been tasked to learn to code by translating this program https://github.com/metacoglab/metacognition-task-online from javascript to Python... big undertaking and I only know R so sorry if this is ...
0
votes
2
answers
279
views
How do I write the init function from Haskell in Prolog [closed]
init :: [a] -> [a]
init [_] = []
init (x:xs) = x : init xs
Formulate the appropriate Prolog rule init(Xs,Ys) which is true if
(and only if) Ys is the initial part of Xs.
That is, the query
init([1,...
2
votes
1
answer
381
views
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....
1
vote
1
answer
96
views
Where does my translation of this code into processing differ from the original?
I have translated the prime testing code from this paper (here is a link to just the original code) into processing. When testing it I found it works for numbers below 10,000,000 but it skips some ...
-1
votes
1
answer
521
views
Translation from C# to Delphi
I need help translating part of the C# code to Delphi.
I would very much appreciate any help or advice.
unsafe {
fixed (byte* bpt = &buff[140]) {
byte b1 = bpt[0];
byte b2 = ...
0
votes
0
answers
242
views
Translate Python export_text decision rules to SAS IF THEN DO; END code
I am attempting to translate Python's sklearn.tree export_text output into SAS conditions.
There has been a solution given in Python for this problem here (at the very end of the page) : How to ...
2
votes
1
answer
186
views
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 ...
0
votes
0
answers
66
views
Convert C# unsafe code to its VB.NET equivalent [duplicate]
Given the limitations of VB.NET, how do I get the VB code to successfully function as closely as possible to this C# code?:
// ImageData -> Bitmap (unsafe)
public static unsafe Bitmap ToBitmap(this ...
1
vote
2
answers
576
views
Converting from C to Racket Scheme
I have written the following C code to recursively solve for a given problem, which is to take in a non-empty list of integers and a target value, and return the closest positive value without going ...
1
vote
4
answers
165
views
Idiomatic way to run nested loop with passing value
I want to do something like this
int n=0
for(int i=xs; i<xe; i++){
for(int j=ys; j<ye; j++){
n++
}
}
return n;
in Clojure way. Since all values are immutable, I think the value n should ...
1
vote
3
answers
210
views
How to create mutually referencing data structures in Haskell?
I've exploited the fact that when the JVM creates an object (immutable or not), its pointer is created before its fields are initialized.
That allows me to create something like this:
class ...
-1
votes
3
answers
182
views
How do you run equivalent of nested for loops in scheme
I am looking on how to translate this pseudocode to idiomatic scheme:
for c in range(1, 1000):
for b in range(1, c):
for a in range(1, b):
do something if condition is true
0
votes
1
answer
114
views
Translate Fortran binary output to Visual Basic .NET
We have a small Fortran program based on the Intel compiler that outputs binary data. I am trying to refactor that code to .NET. I researched how the binary writing in Fortran works but am a bit lost. ...
-5
votes
2
answers
218
views
How To Convert C++ loops into C style loops? [closed]
How can I translate a loop like the below one to C style?
for (auto element : vector) {
Do_Somethin();
}
1
vote
2
answers
92
views
Python Returning Types Translated to C++
I inherited a bit of code in Python to convert to C++. The Python code throws an exception based on a error code returned by other functions. The Python code uses a utility function called errors(...) ...
0
votes
0
answers
28
views
Translate C# to VB.Net for a Salesforce REST call example [duplicate]
I am trying to call a REST service on Salesforce. I found a great example with C#, and I am attempting to translate it to VB.Net. So far I did well translating, but one line is giving me trouble.
...
2
votes
2
answers
382
views
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 ...
0
votes
1
answer
161
views
Translating one DSL to another
I have a specific application DSL query language which I need to translate to Cypher.
This means I get in runtime a string with my domain query language query (SQL like for the example) and need to ...
1
vote
1
answer
45
views
Is there a way of processing list of number integers entered via terminal without saving them into list?
I am trying to write a similar code in Python, but I am new to it.
int counts[] = { 0, 0, 0, 0, 0 };
for (int i = 0; i < groups; i++) {
int groups_size;
scanf(" %d", &groups_size);
...
0
votes
0
answers
655
views
Why MATLAB's imclose and Opencv Python's MORPH_CLOSE show different outputs?
I was trying to convert some MATLAB codes to Python codes which are related to some image-processing.
When I did imclose in MATLAB with a disc shape of 7, the hole in the original binary image was ...
2
votes
2
answers
68
views
"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 * ...
-1
votes
1
answer
538
views
Equivalent of C# BeginInvoke((Action)) in VB.NET
I need to convert the following C# code to VB.NET:
if (this.InvokeRequired)
{
this.BeginInvoke((Action)(() =>
{
imageMutex.WaitOne();
pbCamera.Image = (Bitmap)imageCamera....
0
votes
1
answer
108
views
Running Python functions in CLISP
Are there any CLISP sources available? I could only find references to Stack.
I'm trying to run a python definition in CLISP - any suggestions on how I go about doing this? I'm fairly familiar in ...
0
votes
1
answer
71
views
C to MIPS Code translation problem with nested procedure
I need to tranlate piece of C code
int main(){
int a, b, result;
if(a == b)
result = a*b;
else
result = assess(a, b);
return result;
}
int assess(int a, int b){
if(b<a)
return upgrade(a, b);
else
...
2
votes
1
answer
332
views
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
...
1
vote
2
answers
132
views
Converting expression with >>= to do notation
I have the following code
newtype State s a = State { runState :: s -> (s,a) }
evalState :: State s a -> s -> a
evalState sa s = snd $ runState sa s
instance Functor (State s) where
...
1
vote
0
answers
87
views
Cascading the bind (`>>=`) operator
I have the following function
bar :: (Monad m, Num b) => m b -> m b -> m b -> m b
bar x y z = do
x' <- x
y' <- y
z' <- z
...