Re: Non Compulsory Parameters & a Null Constant ?
Re: Non Compulsory Parameters & a Null Constant ?
- Subject: Re: Non Compulsory Parameters & a Null Constant ?
- From: Adam Hinshaw <email@hidden>
- Date: Thu, 13 Feb 2003 11:48:41 +1100
thanks to all,
the record as parameter seems the way to go, as i can handle using {} as a
minimal param.
makes code a little less self documenting but i guess thats the trade off.
i must say this way of dealing with defaults is very cool.
>
on doSomething(paramRec)
>
set {foo:foo, bar:bar} to paramRec & {foo:0, bar:false}
>
log foo
>
log bar
>
end
Now next question how do i dynamically add/remove from records? :) Only
joking. i know thats all cludgey as well..
adam.
on 13/2/03 5:05 AM, has at email@hidden wrote:
>
Adam Hinshaw wrote:
>
>
> is there a way to specify parameters in a handler that are not compulsory in
>
> a call to that handler.
>
>
Handler parameters are non-optional (annoying, but that's how it is).
>
You can work around this when you have to:
>
>
on doSomething(paramRec)
>
set {foo:foo, bar:bar} to paramRec & {foo:0, bar:false}
>
log foo
>
log bar
>
end
>
>
doSomething({})
>
doSomething({foo:4})
>
doSomething({foo:19, bar:true})
>
>
It's kinda ugly, but may be the lesser evil when writing handlers
>
that must have this level of flexibility and self-sufficiency (e.g.
>
reusable libraries). Rest of the time, it's simpler just to be
>
explicit:
>
>
on doSomething(foo, bar)
>
...
>
end
>
>
If it'll make your code easier to read/maintain, you can always
>
define your default values up front as 'constants':
>
>
-- constants/default values
>
property dcFoo : 0
>
property dcBar : false
>
>
...
>
>
doSomething(dcFoo, dcBar)
>
doSomething(dcFoo, true)
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.