• 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: POSIX and lists question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: POSIX and lists question


  • Subject: Re: POSIX and lists question
  • From: has <email@hidden>
  • Date: Thu, 11 Aug 2005 20:27:38 +0100

Mark J Reed wrote:

>Unfortunately there isn't. Also note that AppleScript doesn't support closures
>
>Funny, 'cause Mr. Neuberg says it does in the book  ("AppleScript ... can generate closures", page 102, last pp), and they seem to work. :)

AppleScript handler objects contain no binding to their lexical environment, a key aspect of closures. For example, consider:

on newObj(x)
	script o
		on foo()
			return x
		end foo
	end script
	set x to x + 1
	return o
end newObj

set y to newObj(3)
y's foo() --> 4


Handler foo looks like it's behaving as a closure, but is it really? Take it out of its enclosing script object and see what happens:

on newObj(x)
	script o
		on foo()
			return x
		end foo
	end script
	set x to x + 1
	return o
end newObj

set y to newObj(3)
set fn to y's foo
fn() --> «handler newObj» -- NOT the value of x!!!


Here's a clearer demonstration of what's going wrong:

script a
	property x : 2

	on foo()
		return x
	end foo
end script

script b
	property z : 0

	property foo : a's foo
end script

b's foo() --> 0


AppleScript handlers look up lexically bound properties in their _current_ context, not the context in which they were originally declared. Compile-time optimisations reduce name bindings to by-index lookups of the script object's slots, which explains the bizarre return values above.


>Not sure what "undocumented" means

"Not in the ASLG."


>But it does neglect to mention any harmful side effects  What sort of screwups are we talking about?

See above.


>>AppleScript's a pretty basic language and doesn't really rise to that level of sophistication.
>
>Based on what I've seen so far, I think you're underestimating the sophistication of AppleScript.

It's more advanced than the old-school unix scripting languages and does have some nice features (script objects, built-in persistency, OSA support), but it's no Lisp or Smalltalk despite the influences and modern OSS scripting languages mostly leave it in the dust.


>but I do happen to enjoy pushing software to its limits.

Not something I recommend doing with AS; it doesn't cope well with stress. Works best when you don't push it too hard and stick to what it's good at, i.e. application scripting and attachability.


>I'm sorry if you feel that I'm using either AppleScript or this forum inappropriately.

Not at all. Just passing on the same knowledge that one of the old-time AS gurus once gave me.

HTH

has
--
http://freespace.virgin.net/hamish.sanderson/
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: POSIX and lists question
      • From: "Gary (Lists)" <email@hidden>
References: 
 >Re: POSIX and lists question (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: Test for existence of a variable?
  • Next by Date: Re: Walter hates framed sites (in another list)
  • Previous by thread: Re: POSIX and lists question
  • Next by thread: Re: POSIX and lists question
  • Index(es):
    • Date
    • Thread