Field content as parametres in a function

Alex Tweedly alex at tweedly.net
Tue Nov 29 06:08:17 EST 2022


Yes, your description is correct (except for saying the behavior is 
"puzzling" :-)

The first case you are passing a single parameter (which happens to have 
commas in its current content). You could have said " .... paramcount() 
returns 1 as expected".

The second case you pass 5 values.

And the third case, as you say, expands the value first, so it becomes a 
call with 5 parameters.

Alex.

On 29/11/2022 08:03, Tore Nilsen via use-livecode wrote:
> I have come across a puzzling behavior when trying to use the content of a field as parametres in a function, and I am trying to understand why.
>
> I put the following in a field called «test»: 1,2,3,4,5
>
> When I then call the function like this:
> 		answer testFunction(field «test»), the paramCount() returns 1
>
> If I use the values directly in the script:
> 		answer testFunction(1,2,3,4,5), the paramCount() returns 5 as expected
>
> I will also get the expected result if a do the following:
>
> 		put "answer testFunction(" & field «test»  & ")" into tScript
> 		do tScript
>
> I guess the reason for this is that in the last example, LiveCode compiles the content of the variable tScript before execution, and that this turns what is first treated as a single block of text into a list of parametres.
>
> The reason why I want to understand what is happening is that I am about to teach my students how to write reusable code that will behave correctly for any number of parametres.
>
> So my question is if I am on the right track?
>
> Best regards
> Tore Nilsen
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode



More information about the use-livecode mailing list