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

Re: list question


  • Subject: Re: list question
  • From: Andrew Oliver <email@hidden>
  • Date: Wed, 04 Jun 2003 12:42:49 -0700

At its simplest level:

> set a to 2
> set b to a
> set c to a + b
> c
> --> 4

This makes sense as (I hope) we all agree :).

Where you're getting confused is:

> set a to a + 1

Sets the variable name 'a' to a new object that has the value of a's
original value plus 1

At this point, a and b no longer point to the same object. b still points to
the original object with a value of 2, a points to a new object with a value
of 3.

You cannot mutate 'a' (which points to an integer object) to a new value,
you can only set it to a new object distinct from the original.

Andrew
:)

On 6/4/03 10:09 AM, "Doug McNutt" <email@hidden> wrote:

> At 21:11 -0700 6/3/03, Chris Page wrote, and I snipped:
>> - variables are names for objects
>> - objects can have multiple names
>
>> set a to "A" -- a is bound to the immutable string "A"
>> set b to a -- b is bound to the same immutable string "A"
>> set c to a & "B" -- c is bound to a new immutable string "AB", constructed
>> by copying the contents of "A" and "B"
>> set a to c -- a is bound to the immutable string "AB"
>
>
> set a to 2
> set b to a
> set c to a + b
> c
> --> 4
> set a to a + 1
> set c to a + b
> c
> --> 5
>
> Can you explain just how "b" here refers to the same object as "a". Why
> doesn't the second calculation return 6? (I'd really be upset if it did!)
>
> Did not "set a to a + 1" mutate the object to which a refers? Is there an
> immutable value 2 that still exists after I add the 1? I should hope the
> memory would be reused.
>
> Does "set" in AppleScript mean the same as "Let" in original BASIC? Or does it
> work like "set" in M$ VBA where it assigns a local name to, say, a range of
> cells in an Excel workbook? Both BASIC and VBA use a simple = sign to store a
> value in memory identified by named variable. A := construct is used
> elsewhere. AppleScript doesn't allow either but does it replace the (:)= with
> "set"? Or does it have two separate meanings for "set"?
>
> How, in this brave new world of objects does one take a derivative of a
> variable that is a function of time? Perhaps it is read from a voltmeter with
> direct memory access. The immutable object mutates by itself.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: list question (From: Doug McNutt <email@hidden>)

  • Prev by Date: Re: Default Path on OSX
  • Next by Date: can't 'tell correct ver
  • Previous by thread: Re: list question
  • Next by thread: Re: list question
  • Index(es):
    • Date
    • Thread