codebox: pass an array as an argument to a function?

tyler mazaika's icon

tyler mazaika

12月 13 2023 | 8:18 午後

Is it possible to pass an Array as an argument to a function somehow? Is there some magic syntax which can be used to do this?

(Same question would apply to passing a list type)

Alex Norman's icon

Alex Norman

12月 19 2023 | 2:30 午後

Sorry for the huge delay Tyler,
List is easy, I'm not sure if array is supported yet though:

function foo(v: list, m: number): number {
    return v[2] * m;
}

out1 = foo([1,2,3], in1);
tyler mazaika's icon

tyler mazaika

12月 19 2023 | 2:42 午後

All good Alex, thanks. FWIW I think I was hoping to be able to pass 2 or 3 dimensional arrays into a function for some processing. I may be able to get by with passing multiple lists in parallel with the syntax you shared.

Dan McAnulty's icon

Dan McAnulty

6月 27 2024 | 12:35 午前

Thanks for this! I was looking for the syntax for declaring variable types like that in function declarations, does anybody know where I would find it in the documentation?

I couldn't seem to find it, but am grateful to have found the answer here in the forum.


*** EDIT ***

Oh, I found it!

under 'Types'

I hadn't realized how long and full of helpful details that codebox landing page is.