• 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: More about Records
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More about Records


  • Subject: Re: More about Records
  • From: Richard 23 <email@hidden>
  • Date: Tue, 2 Jan 2001 16:47:39 -0800

Paul hit us with another ponderable. I still remember the
last one a couple of months ago. Here we go again I thought...

>Would someone like to explain what's going on here?
>
>set r1 to {a:1, b:2, c:3}
>set r2 to {a:1, b:2, c:75}
>
>r1's {a, b}
> -- {1, 2}
>r2's {a, b}
> -- {1, 2}
>r1's {a, b} = r2's {a, b}
> -- false
>{r1's a, r1's b} = {r2's a, r2's b}
> -- false
>r1's a = r2's a and r1's b = r2's b
> -- true

You, my friend, have discovered the double-edged sword of value
by reference. Two referenced values (or objects) can appear to
be the same but if they don't reference the same object, they
are not said to be equal.

Perhaps there should be an equivalent keyword or symbol.

This is why all of your tests fail but the last one in which
you are no longer passing a value by reference. You're
comparing two integers which are not passed by reference and
are, in fact, equal.

Fortunately we do have contains. Contains is also useful when
comparing a value to a repeat loop's iterator variable.

I'll add to your suite of tests:

log r1's {a, b} = {1, 2}
-- false
log r1's {a, b} contains r2's {a, b}
-- true
log {r1's a, r1's b} contains {r2's a, r2's b}
-- true

Then to demonstrate the necessity of contains when iterating
a list (not necessary when a range of numbers is specified):

repeat with theItem in r1
if theItem = 2 then say "equal"
if theItem contains 2 then say "contains"
end repeat

Even if you do have text to speech you will not hear your mac say
"equals".

R23


  • Follow-Ups:
    • Re: More about Records
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: records, a reference to, and the top level scope!
  • Next by Date: Droplet and Aliases...how?
  • Previous by thread: Re: More about Records
  • Next by thread: Re: More about Records
  • Index(es):
    • Date
    • Thread