In R you can use NULL arguments in functions like myfun = function (a=NULL, b, c) can you do this in Julia? I'm asking because I'd like variable a as a condition : if a = NULL do this, else do that. I can just write different functions of course but they would mostly repeat each other. I can also just assign arbitrary numbers but it seems using NULL is more clear. Thanks!.
There is no predefined value called null in Julia, so it is not clear what you want here. Rather than using ' ' for missing values, missing or nothing (depending on the semantics you need) would allow you to interface with more functionality in the ecosystem.
Method Tables Every function in Julia is a generic function. A generic function is conceptually a single function, but consists of many definitions, or methods. The methods of a generic function are stored in a method table.
A return type can be specified in the function declaration using the :: operator. This converts the return value to the specified type. This function will always return an Int8 regardless of the types of x and y .
One of the most common questions from people coming to a new language is how to code exactly like in the language they come from. But testing for NULL is not likely to be the best way to implement this in Julia. Mostly you'll define two methods for your function:
function myfun(a, b, c)
...
end
function myfun(b, c)
...
end
With the different behaviours.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With