Using parameters inside a function

dgagnon
Thu, 22 Dec 2022 13:53:18 +0000
General Usage

Hello

I want to use a function using parameters.jl. Inside REPL I simply type:

julia> called_function(param1=4, param2=0)

The function “called_function” has other parameters but those have default values which are good enough for me.
However I want to create a wrapper that will take some arguments and transfer them to the called function:

function my_function( a::Int64, b::Int64, other arguments)
    ...
    called_function(a, b) # <= How can I say that 'a' is for param1 and 'b' for param2?
    ...
end

I get an error like this:

ERROR: MethodError: no method matching called_function(::Int64, ::Int64)

If I specify the 4 arguments of “called_function” I don’t need to state the name of the parameters:

called_function(4, 0, UUID("51d35f80-81ee-11ed-1a59-6be8ccc438a2"), [])

My fallback plan is of course to state all parameters within “my_function”. I nevertheless would like to know how I can work around this and use default values.

Thants for your help.

5 posts - 2 participants