Variable parameter lists and more! (was Re: wishlist: user-declared parameter labels without "given"
Variable parameter lists and more! (was Re: wishlist: user-declared parameter labels without "given"
- Subject: Variable parameter lists and more! (was Re: wishlist: user-declared parameter labels without "given"
- From: Timothy Bates <email@hidden>
- Date: Mon, 02 Apr 2001 12:08:18 +1000
>
On 4/1/01 10:08 AM, "Arthur J Knapp" <email@hidden> wrote:
>
> you can write your handlers to take a record as a parameter:
>
> getasample( { taking: 3, from_list: {1, 2, 3, 4}, replacing: false } )
I just found out two fantastic things:
1. If you write a handler to take a record as its input, it unpacks them
automagically, and doesn't care what order the items are in.
icanhandleanyorder({x:"x", z:"z", y:"y"})
on icanhandleanyorder({x:x, y:y, z:z})
display dialog "x is" & x & ", y is" & y & ", z is" & z
end icanhandleanyorder
2. And more fantastic: this allows us to have optional parameters (I just
read Paul and Arthur's mails more closely and Arthur in fact noted this
already.
so you can say
do1ofseveralthings({task:"beep", parameters:{}})
do1ofseveralthings({task:"add", parameters:{2, 2}})
on do1ofseveralthings({task:task, parameters:parameters})
if task is "beep" then
beep
else if task is "add" then
display dialog (item 1 of parameters) + (item 2 of parameters)
end if
end do1ofseveralthings
Rock on! that is so powerful.
tim