Re: Variable parameter lists and more! (was Re: wishlist:
Re: Variable parameter lists and more! (was Re: wishlist:
- Subject: Re: Variable parameter lists and more! (was Re: wishlist:
- From: "Arthur J Knapp" <email@hidden>
- Date: Mon, 02 Apr 2001 11:16:19 -0400
>
Date: Mon, 02 Apr 2001 12:08:18 +1000
>
Subject: Variable parameter lists and more! (was Re: wishlist:
>
user-declared parameter labels without "given"
>
From: Timothy Bates <email@hidden>
>
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})
>
2. And more fantastic: this allows us to have optional parameters
>
do1ofseveralthings({task:"beep", parameters:{}})
>
do1ofseveralthings({task:"add", parameters:{2, 2}})
One thing that would be nice to have is a way to test an AppleScript
record for the existence of a label. Many people use try statements
to trap for the error that is caused when asking for a label that does
not exist:
set reco to {a:1, b:2, c:3}
try
z of reco --> error "Can't get z of {a:1, b:2, c:3}."
on error number -1728
set z to missing value
end try
Another way to go is once again to turn to record concatentation:
set reco to {a:1, b:2, c:3}
set a to a of (reco & {a:missing value})
set b to b of (reco & {b:missing value})
set c to c of (reco & {c:missing value})
set z to z of (reco & {z:missing value})
{a, b, c, z}
--> {1, 2, 3, missing value}
Which is the same as writing:
set UserRecord to {a: 1, b: 2, c: 3}
set DefaultRecord to {a: missing value, b: missing value, c: missing
value, z: missing value}
set FullRecord to UserRecord & DefaultRecord
--> {a: 1, b: 2, c: 3, z: missing value}
if ( z of FullRecord = missing value ) then -- no error
-- whatever
>
Rock on! that is so powerful.
Party on Wayne, party on Garth...
Arthur J. Knapp
http://www.stellarvisions.com
mailto:email@hidden
Hey, check out:
http://MacScripter.net/