• 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: copy & set statements
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: copy & set statements


  • Subject: Re: copy & set statements
  • From: Timothy Bates <email@hidden>
  • Date: Wed, 24 Oct 2001 11:10:16 +1000

On 24/10/01 9:11 AM, "email@hidden" <email@hidden> wrote:
> Actually, everything is passed [to a handler] as a pointer, but because
> AppleScript coerces almost everything invisibly, the pointerness of simple
> values isn't apparent. Also, only lists and records have ways of doing things
> to the actual object (like "set end of myList to 42" or "set p of r to 12").
> With simple values, like numbers or strings, you don't have the ability to
> reach in and change part of them; its either all or nothing, and if you change
> all of the value, you can't tell whether you have a new value or if you've
> just changed the old one.


This is getting weird:

set theCat to {"woody", "hungry"}
myHandler(theCat)
theCat --> {woody,hungry}

on myHandler(myList)
set myList to myList & "a" -- make a change within the list
end myHandler

BUT


set theCat to {"woody", "hungry"}
myHandler(theCat)
theCat -->{"woody", "hungry", "a"}

on myHandler(myList)
set end of myList to "a" -- make a change within the list
end myHandler

So, this "feature" only bites when you don't cause AS to dereference (and
copy) the pointer to the passed in parameter, hence Nigel's admonition to
explicity copy it if you can't afford external effects, but not to rely on
the external effect (calling a global instead to insure this) because it
only happens if you don't accidentally cause AS to transparently coerce the
parameter.

No wonder my scripts had worked in the past - sheer dumb luck ;-)

tim


References: 
 >Re: copy & set statements (From: email@hidden)

  • Prev by Date: Re: Eudora: sending to more than 50 recipients
  • Next by Date: Re: copy & set statements
  • Previous by thread: Re: copy & set statements
  • Next by thread: Re: copy & set statements
  • Index(es):
    • Date
    • Thread