Using parameters inside a function

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.

Maybe called_function(param1=a, param2=b)?

If that doesn’t work, please post a complete, minimal example that shows the problem.

Does not work. I get the same message.
Here’s a complete example with the used package:

Pkg.add(url="https://github.com/anyonlabs/Snowflake.jl", rev="main")
using Snowflake
function my_function(a::Int64, b::Int64)
    c = QuantumCircuit(qubit_count=a, bit_count=b)
end

julia> my_function(2,0)
ERROR: MethodError: no method matching my_function(::Int64, ::Int64)
Closest candidates are:
  my_function(::Int64, ::Int64, ::Int64) at REPL[83]:1
Stacktrace:
 [1] top-level scope
   @ REPL[84]:1

Your example works for me:

julia> my_function(2,0)
Quantum Circuit Object:
   id: c6f6da90-8206-11ed-1053-3bc9d78927f5 
   qubit_count: 2 
   bit_count: 0 
q[1]:
     
q[2]:

The error message you have doesn’t make sense with the code, maybe try to run it all again?

1 Like

@sijo

damn it! What did I do wrong? I’ll find out… eventually.

Thanks Sijo

1 Like