• 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: Creating list references in handlers. Bad code or bug?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating list references in handlers. Bad code or bug?


  • Subject: Re: Creating list references in handlers. Bad code or bug?
  • From: "Bob.Kalbaugh" <email@hidden>
  • Date: Sun, 16 Sep 2001 21:29:00 -0500

on 9/16/01 3:19 PM, Victor Yee at email@hidden wrote:

> Hmmm, is this a bug?
>
> set x to {1, 2}
> set end of x's contents to 3
> x
> --> {1, 2}
>
> Victor

I'm not sure if this clarifies what you're trying to point out, but what
confuses me, and I'll put it in question form...

Why does changing a reference to (object x) change x ?

And why does setting (end of x's contents) work when using an object
reference, but not on the object itself?

--
set x to {1, 2, 3}

set y to a reference to contents of x
set z to a reference to x

log x
log y
log z

set end of y's contents to 4
set end of z's contents to 4

log x
log y
log z

set end of x's contents to 5

log x
log y
log z


-- event window results --

(*1, 2, 3*)
(*1, 2, 3*)
(*1, 2, 3*)

(*1, 2, 3, 4*) -- interesting!
(*1, 2, 3, 4*) -- interesting!
(*1, 2, 3, 4*) -- interesting!

(*1, 2, 3, 4*) -- hmmm?
(*1, 2, 3, 4*)
(*1, 2, 3, 4*)

--

And what's even more interesting are the results obtained from breaking the
above example down line-by-line. Note when I get to the line with the ???'s.
It argues with the result in the event log (unless I just DON'T understand
references! - which is probably the case.)


set x to {1, 2, 3}
set y to a reference to contents of x
y

-- result window --> contents of {1, 2, 3}


set x to {1, 2, 3}
set y to a reference to contents of x
set z to a reference to x
z

-- result window --> x of +script;


set x to {1, 2, 3}
set y to a reference to contents of x
set z to a reference to x
set end of y's contents to 4
y

-- result window --> contents of {1, 2, 3} -- ???


set x to {1, 2, 3}
set y to a reference to contents of x
set z to a reference to x
set end of y's contents to 4
set end of z's contents to 4
z

-- result window --> x of +script;


set x to {1, 2, 3}
set y to a reference to contents of x
set z to a reference to x
set end of y's contents to 4
set end of z's contents to 4
set end of x's contents to 5
x

-- result window --> {1, 2, 3, 4}


set x to {1, 2, 3}
set y to a reference to contents of x
set z to a reference to x
set end of y's contents to 4
set end of z's contents to 4
set end of x's contents to 5
{x, y, z}

-- result window --> {{1, 2, 3, 4}, contents of {1, 2, 3, 4}, x of +script;}


--bob.kalbaugh


References: 
 >Re: Creating list references in handlers. Bad code or bug? (From: Victor Yee <email@hidden>)

  • Prev by Date: file name mutations
  • Next by Date: Chooser problem
  • Previous by thread: Re: Creating list references in handlers. Bad code or bug?
  • Next by thread: Re: Creating list references in handlers. Bad code or bug?
  • Index(es):
    • Date
    • Thread