matlab-to-julia icon indicating copy to clipboard operation
matlab-to-julia copied to clipboard

Function calls aren't translated correctly

Open nilshg opened this issue 5 years ago • 3 comments

MATLAB: my_function(arg1, arg2) Julia: my_function[arg1, arg2]

Came across this bug from a user report on: https://discourse.julialang.org/t/methoderror-no-method-matching-getindex/22496/3

nilshg avatar Mar 29 '19 10:03 nilshg

Hi! Thanks so much for letting me know about this. It's tricky to know whether something is a function or a matrix in MATLAB. The script tries to guess, using a list of common functions and using functions that it sees are defined in the block of code being translated. If the translator misses something, names of functions can be added to the "interpret as functions" list in the advanced options below the translator.

I definitely don't recommend translating code and running it as is. The translator is meant to be a time-saver, but still requires learning Julia, manually correcting the translated code, and actually optimizing the code once it is translated.

That said, the translator does not currently recognize some functions that don't return anything (second option in the answer here: https://stackoverflow.com/questions/12992619/can-a-function-be-created-in-matlab-that-returns-nothing )—I'll look into fixing that!

Thanks again!

lakras avatar Mar 29 '19 13:03 lakras

Sure, do understand that - I don't think there's necessarily a solution here apart from maybe mentioning this prominently somewhere, as this is probably a reasonably common problem!

nilshg avatar Mar 29 '19 13:03 nilshg

I added support for functions that don't return anything. Assuming all the code is pasted in together, the function in Aquaman's code should now actually be recognized as a function (yay!). If the function call and the actual function are not entered in together then, of course, the function will not be recognized as a function.

Leaving this open (?) since this is a problem that cannot really solved, but can be gradually improved upon. Any ideas or pull requests to make things better are absolutely welcome. (I'm opening a related issue on mapping common MATLAB functions and packages to Julia.)

lakras avatar Mar 31 '19 01:03 lakras