MACSCRPT Archives

May 2009

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Deivy Petrescu <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Thu, 21 May 2009 13:04:29 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (82 lines)
On 21/05/2009, at 11:16 , Bill Steele wrote:

>>
>> On Thu, May 21, 2009 at 9:39 AM, Bill Steele <[log in to unmask]>  
>> wrote:
>>>
>>> set recordList to {}
>>> set oneRecord to {foo:1, bar:"hello"}
>>> set end of recordList to oneRecord
>>> set twoRecord to {foo:2, bar:"Goodbye"}
>>> set end of recordList to twoRecord
>>> repeat with aRecord in recordList
>>> if foo of aRecord is 1
>>> set stuffIneeded to aRecord
>>> end if
>>> end repeat
>>> --> returns the entire list.
>>
>> Not OMM.  It does, however, return a reference to the first item of
>> the list ("item 1") rather than the actual record.
>>
>>
>>> set stuffIneeded to CONTENTS of aRecord
>>
>> yup.
>>
>>> Fairly easy to figure out (I managed), but not the way ordinary  
>>> lists
>>> behave.
>>
>> No, it's exactly the way ordinary lists of *references* behave,
>> whether the referenced items are records or application objects - or
>> other lists.  This exhibits the same behavior.
>>
>> repeat with aList in { { 1, 2, 3 }, { 4, 5, 6 } }
>>    if item 1 of aList is 1 then
>>       set stuffIneeded to aList
>>    end if
>> end repeat
>> stuffIneeded
>
> This is getting interesting.  I've done a lot of stuff with hunting  
> through ordinary lists and would have disagreed with you, but I  
> experimented a bit:
>
> set aList to {1, 2, 3}
> repeat with oneNumber in aList
> display dialog oneNumber --> works, 1, 2., 3
> 	if oneNumber is 2 then
> 		display dialog oneNumber --> zilch
> 	end if
> end repeat
>
> but
>
> set aList to {1, 2, 3}
> repeat with i from 1 to 3
> 	set oneNumber to item i of aList
> 	if oneNumber is 2 then
> 		display dialog oneNumber --> 2
> 	end if
> end repeat
>
> the "in list" syntax doesn't do comparisons, but "item of" does.  
> Does that qualify as problematical?
> -- 
>
> Bill Steele
> [log in to unmask]

Bill,
it is not that in list does not do comparisons it is that in list does  
not deal with the elements but with a reference to the element.
so in your first script, the line "if oneNumber is 2 then" gets  
translated to "if a reference to item 1 of aList is 2 then"
A reference is that a pointer not a value. The pointer is not 2, it  
points to 2.


Deivy Petrescu
[log in to unmask]

ATOM RSS1 RSS2