Variable parameter synonym functions

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Variable parameter synonym functions

mikey-2
Has anybody come up with an easy way to write functions or handlers that are synonyms for other functions/handlers where both take a variable number of parameters?

If I want to have a handler "a" and synonym "aardvark", I would normally write

on a name
   aardvark name
end a

on aardvark name
   answer "I'm an aardvark named"&&name
end aardvark


Now imagine doing that while supporting a variable number of parameters.

Sent from my iPhone
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Variable parameter synonym functions

xtalkprogrammer
Hi Mikey,

Here's a way:

on mouseUp
      put fun1("a","b")
end mouseUp

function fun1
      repeat with x = 1 to the paramcount
           put param(x) & comma after myList
      end repeat
      put "fun2(" & char 1 to -2 of myList & ")" into myFun
      return value(myFun)
end fun1

function fun2
      return the paramcount
end fun2

--
Best regards,

Mark Schonewille

Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
KvK: 50277553

Installer Maker for LiveCode:
http://qery.us/468

Buy my new book "Programming LiveCode for the Real Beginner"
http://qery.us/3fi

LiveCode on Facebook:
https://www.facebook.com/groups/runrev/

On 10/23/2014 13:51, Mikey wrote:

> Has anybody come up with an easy way to write functions or handlers that are synonyms for other functions/handlers where both take a variable number of parameters?
>
> If I want to have a handler "a" and synonym "aardvark", I would normally write
>
> on a name
>     aardvark name
> end a
>
> on aardvark name
>     answer "I'm an aardvark named"&&name
> end aardvark
>
>
> Now imagine doing that while supporting a variable number of parameters.
>
> Sent from my iPhone
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Kind regards,

Drs. Mark Schonewille

Economy-x-Talk Consultancy and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
Facebook: http://facebook.com/LiveCode.Beginner
KvK: 50277553
Reply | Threaded
Open this post in threaded view
|

Re: Variable parameter synonym functions

Mike Kerner
Yes, I understand how to do it, I'm just wondering if there's a more
elegant way.

On Thu, Oct 23, 2014 at 8:29 AM, Mark Schonewille <
[hidden email]> wrote:

> Hi Mikey,
>
> Here's a way:
>
> on mouseUp
>      put fun1("a","b")
> end mouseUp
>
> function fun1
>      repeat with x = 1 to the paramcount
>           put param(x) & comma after myList
>      end repeat
>      put "fun2(" & char 1 to -2 of myList & ")" into myFun
>      return value(myFun)
> end fun1
>
> function fun2
>      return the paramcount
> end fun2
>
> --
> Best regards,
>
> Mark Schonewille
>
> Economy-x-Talk Consulting and Software Engineering
> Homepage: http://economy-x-talk.com
> Twitter: http://twitter.com/xtalkprogrammer
> KvK: 50277553
>
> Installer Maker for LiveCode:
> http://qery.us/468
>
> Buy my new book "Programming LiveCode for the Real Beginner"
> http://qery.us/3fi
>
> LiveCode on Facebook:
> https://www.facebook.com/groups/runrev/
>
>
> On 10/23/2014 13:51, Mikey wrote:
>
>> Has anybody come up with an easy way to write functions or handlers that
>> are synonyms for other functions/handlers where both take a variable number
>> of parameters?
>>
>> If I want to have a handler "a" and synonym "aardvark", I would normally
>> write
>>
>> on a name
>>     aardvark name
>> end a
>>
>> on aardvark name
>>     answer "I'm an aardvark named"&&name
>> end aardvark
>>
>>
>> Now imagine doing that while supporting a variable number of parameters.
>>
>> Sent from my iPhone
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



--
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
   and did a little diving.
And God said, "This is good."
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Variable parameter synonym functions

Ken Ray
In reply to this post by mikey-2
How about:

on a
   send ("aardvark" && (word 2 to -1 of the params)) to me
end a

on aardvark
  put the params
end aardvark


on mouseUp
   a "one","two","three"
end mouseUp

—> aardvark "one","two","three"

??

Ken Ray
Sons of Thunder Software, Inc.
Email: [hidden email] <applewebdata://472067EC-3153-497D-B547-581563CF4971/[hidden email]>
Web Site: http://www.sonsothunder.com/         <http://www.sonsothunder.com/>



> On Oct 23, 2014, at 6:51 AM, Mikey <[hidden email]> wrote:
>
> Has anybody come up with an easy way to write functions or handlers that are synonyms for other functions/handlers where both take a variable number of parameters?
>
> If I want to have a handler "a" and synonym "aardvark", I would normally write
>
> on a name
>   aardvark name
> end a
>
> on aardvark name
>   answer "I'm an aardvark named"&&name
> end aardvark
>
>
> Now imagine doing that while supporting a variable number of parameters.
>
> Sent from my iPhone
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode