Reference Function Name Via Variable?

Kay C Lan lan.kc.macmail at gmail.com
Fri Jan 16 01:22:00 EST 2009


On Fri, Jan 16, 2009 at 1:13 PM, Scott Rossi <scott at tactilemedia.com> wrote:

> Thanks to list folks for all the suggestions about calling functions using
> variable names -- lots of good ideas out there.
>
> Well I said merge wasn't necessary and someone else would come up with a
one liner, looks like I was wrong on both accounts:

ON mouseUp
    put "hello" into pData1
    put "world" into pData2
    put "shout" into test

    answer value(merge("[[test]](pData1,pData2)"))
END mouseUp

FUNCTION shout pData1,pData2
    return pData1 && pData2
END shout

I had a feeling merge could help but originally I had it all backwards:-(

Anyway, with this method, something like this is very flexible:

value(merge("[[custFunc]]([[pParamList]])"))

be careful to include the () around [[pParamList]]

Although no advantage in your example:

ON mouseUp
    put "hello" into pData1
    put "world" into pData2
    put "pData1,pData2" into pParamList
    put "shout" into custFunc

    answer value(merge("[[custFunc]]([[pParamList]])"))
END mouseUp

FUNCTION shout pData1,pData2
    return pData1 && pData2
END shout

clearly it would be easy to take a field/customProp/variable that contained
multiple lines with each line containing a varying number of items and use a
repeat loop to create and fill pData1, pData2,... pDataN

HTH



More information about the use-livecode mailing list