lakras / matlab-to-julia

Translates MATLAB source code into Julia. Can be accessed here: https://lakras.github.io/matlab-to-julia
MIT License
123 stars 19 forks source link

Function calls aren't translated correctly #4

Open nilshg opened 5 years ago

nilshg commented 5 years ago

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

lakras commented 5 years ago

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!

nilshg commented 5 years ago

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!

lakras commented 5 years ago

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.)