Page 1 of 1

List as a function argument

PostPosted: Mon Sep 04, 2017 1:26 pm
by dchelnokov
Dear All,
If we call a function with a list parameter, shall we always convert the argument into a local list variable explicitly in the function's body, like below:
if all_even_numbers(list_of_my_layers) = True {// do this...}
***
Function body: all_even_numbers(list_of_my_layers)
var list_of_elements = list_of_my_layers.toList
//do the check
//...
// return True or False


If there are options, could you please list :lol: them ?
Is that list passed to a function as a reference, or as a copy? So can a function change its list-argument, or it only works with a copy of the list?

Re: List as a function argument

PostPosted: Tue Sep 05, 2017 5:32 pm
by dchelnokov
Experimenting I found that we need to assign the list-argument to a local variable and use the ".ToList" method at the end of the argument name. If you try to do anything with the raw argument, the WD will catch it as "non list variable".

I think that the List argument is a sort of pointer and I don't see the way to manipulate it in WD.

Re: List as a function argument

PostPosted: Wed Oct 11, 2017 3:34 pm
by Janina Baltaziewicz
Hi,

That is true, you always have to convert your input parameters into the respective data type in the function (or macro) body before using it.
What you get there is a copy of the original input value, but packed in an "object" data type. That's why it isn't recognised as list or integer or whatever the original type was.

Cheers!

Janina

Re: List as a function argument

PostPosted: Tue Nov 07, 2017 4:01 pm
by dchelnokov
Thank you! :)