Re: Handlers in a variable
Re: Handlers in a variable
- Subject: Re: Handlers in a variable
- From: Axel Luttgens <email@hidden>
- Date: Sun, 17 Jan 2016 17:11:34 +0100
> Le 17 janv. 2016 à 16:25, Chris Page a écrit :
>
> […]
>
> Here's an example closure in AppleScript:
>
> to incrementBy(n)
> set x to 0
> script
> to next()
> set x to x + n
> end next
> end script
> end incrementBy
>
> set closure1 to incrementBy(1)
> set closure2 to incrementBy(5)
>
> {closure1's next(), closure2's next(), closure1's next(), closure2's next()} --> {1, 5, 2, 10}
>
> The “incrementBy” handler constructs a script with a “next” handler that closes over both the argument “n” and the local variable “x”. Although the current language requires the intermediate “script”, the handler doesn’t close over any of the script's properties.
Hello Chris,
As a general rule, wouldn’t it be safer to explicitly declare the local variables as such? As with a "local x" statement in the above code?
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden