• 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
Handlers in a variable
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Handlers in a variable


  • Subject: Handlers in a variable
  • From: "Mark J. Reed" <email@hidden>
  • Date: Fri, 15 Jan 2016 22:19:42 -0500

I find it odd that this works:

    to double(aNumber) 
       return aNumber * 2
    end double

    set someHandler to double

    someHandler(4)  --=> 8

But this doesn't:

    to call(aHandler, aValue)
       aHandler(aValue)
    end

    call(double, 4)

    error "«script» doesn’t understand the “aHandler” message." number -1708 from «script»

What is different about the parameter of a handler compared to a local variable that explains this inconsistency?

I know that AS doesn't really do higher-order functions, and the way to fake it is with script objects, kind of like pre-closure Java.  But I noticed that variables could hold handlers and thought maybe that had been rectified...

--
Mark J. Reed <email@hidden>
 _______________________________________________
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

  • Follow-Ups:
    • Re: Handlers in a variable
      • From: Chris Page <email@hidden>
  • Prev by Date: Re: Grammar Police in OS X 10.11
  • Next by Date: [ASOC] returning by reference, and converting script objects to descriptors?
  • Previous by thread: Re: Why Doesn't This Script.app Quit?
  • Next by thread: Re: Handlers in a variable
  • Index(es):
    • Date
    • Thread