• 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: Variable Ponderance
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Variable Ponderance


  • Subject: Re: Variable Ponderance
  • From: has <email@hidden>
  • Date: Fri, 1 Oct 2004 19:55:07 +0100

Michael Sullivan wrote:

set x to {1, 2, 3}
doSomething(x)

You're not passing a variable (x). You're passing the object that's stored in it.


on doSomething(y)
	set item 1 of y to 2
end doSomething

And here you're not modifying the variable (y), you're modifying the content of the object that's stored in it. Which is the _same object_ as is stored in variable x.


Ech, this one bites everybody sooner or later. (Not helped by the ASLG's lame attempt to explain it - some vague rubbish about "data sharing" buried somewhere in the middle). Short answer: follow the objects, not the variables.

The way I like to say this (I think it's equivalent) is that some objects (anything other than a number IIRC) are never stored in variables -- only a reference (pointer if you prefer, but reference is more general) is stored in the variable binding.

With a high-level language like AppleScript, you really want to avoid discussing low-level stuff like pointers - what matters is the high-level concepts that users are directly exposed to, not low-level implementation details that the language deliberately goes to quite considerable lengths to hide from them. [1]


If you really don't like the 'variable = container' metaphor (which is a bit of an over-simplification, after all) a more accurate explanation is to say that a variable is a name bound to an object, subsequently enabling you to refer to that object by name. A single object can have any number of names bound to it, and names may be bound, unbound or rebound at any time. It's a much more abstract description, however, so for most discussions, the 'user-friendly' container metaphor is 'good enough' and easier for the non-experts to understand.

Cheers,

has

[1] It's even less safe to talk in terms of implementation details (pointers, stacks, heaps, malloc, etc, etc, etc.) when you're not actually privy to them yourself - which is the case with a closed-source language like AS. (This is another reason why wandering C programmers, like missionaries, should always be shot upon first sight, before all their 'heap allocation' and 'pass by reference' babblings infects the rest of the population with singularly pointless, productivity zapping, rampantly idle speculation...;p)
--
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: Variable Ponderance
      • From: Bill Briggs <email@hidden>
    • Re: Variable Ponderance
      • From: Courtney Schwartz <email@hidden>
  • Prev by Date: Re: Volume status (Modified by Adam K. Wuellner)
  • Next by Date: re. footnotes [was Re: Variable Ponderance]
  • Previous by thread: Re: Variable Ponderance
  • Next by thread: Re: Variable Ponderance
  • Index(es):
    • Date
    • Thread