• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Handlers in a variable
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Handlers in a variable (From: "Mark J. Reed" <email@hidden>)
 >Re: Handlers in a variable (From: Chris Page <email@hidden>)

  • Prev by Date: Re: Grammar Police in OS X 10.11
  • Next by Date: Re: [ASOC] returning by reference and converting script objects to descriptors?
  • Previous by thread: Re: Handlers in a variable
  • Next by thread: Re: Handlers in a variable
  • Index(es):
    • Date
    • Thread