• 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: functions as sort of first class objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: functions as sort of first class objects


  • Subject: Re: functions as sort of first class objects
  • From: Deivy Petrescu <email@hidden>
  • Date: Tue, 24 May 2016 12:18:48 -0400

> On May 24, 2016, at 10:44 , Axel Luttgens <email@hidden> wrote:
>
> repeat with g in {a, b}
> 		set h to contents of g
> 		h()
> 	end repeat

Ha! This is really interesting.
The first thing I thought was exactly that, h is only a reference to an item in the list.
Thus, as I am used to do, I used the following:

repeat with h in whatever
set h to contents of h
do the rest
end repeat

It turns out that in this case this fails, so if you don’t do the loop with another variable it fails.
in other words,

to a()
	display alert "A"
end a

to b()
	display alert "B"
end b

repeat with h in {a, b}
	set h to contents of h
	h()
end repeat
—> error "«script» doesn’t understand the “h” message." number -1708 from «script»

but

to a()
	display alert "A"
end a

to b()
	display alert "B"
end b

repeat with h in {a, b}
	set g to contents of h
	g()
end repeat

Unless there is something I am not fundamentally understanding, this is a bug.



Deivy Petrescu
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


References: 
 >functions as sort of first class objects (From: Mitchell L Model <email@hidden>)
 >Re: functions as sort of first class objects (From: Axel Luttgens <email@hidden>)

  • Prev by Date: Re: Library Use Statement Question
  • Next by Date: Re: functions as sort of first class objects
  • Previous by thread: Re: functions as sort of first class objects
  • Next by thread: functions as sort of first class objects
  • Index(es):
    • Date
    • Thread