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:
"Stockly, Ed" <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Tue, 19 May 2009 14:14:28 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (84 lines)
> When you concatenate it coerces what ever you are adding into either a
string or a list.  Since records can be coerced into lists it makes it a list
rather than a list containing a record.

I believe that explains part of the behavior, but not all.  I can't
definitively explain it at all, but I can show you why I think it's more
complex and how AppleScript may be confused by what's happening between the
lists and records.

Run this:

set recordList to {}
set oneRecord to {foo:1, bar:"hello"}
set recordList to recordList & oneRecord
set twoRecord to {xx:2, yy:"Goodbye"}
set recordList to recordList & twoRecord

-->{foo:1, bar:"hello", xx:2, yy:"Goodbye"}

Not the result we wanted, but it shows that when AppleScript tries to
concatentate records it will work if the the record items are unique. If
they are the same it fails silently. (Not good)

Also, when it concatenates records it does not create a list of records but
simply more records.

Run this:

set recordList to {}
set oneRecord to {foo:1, bar:"hello"}
set recordList to recordList & oneRecord

set recordList to {recordList}

set twoRecord to {foo:2, bar:"Goodbye"}
set recordList to recordList & twoRecord

-->{{foo:1, bar:"hello"}, 2, "Goodbye"}

Still not the result we're looking for but note that the record did coerce
into integer and text.

It turned a list of one item, a record, into a list of three items and
extracted the value from the added records.

Run this:

set recordList to {}
set oneRecord to {foo:1, bar:"hello"}
set recordList to recordList & oneRecord

set recordList to {recordList}

set twoRecord to {foo:2, bar:"Goodbye"}

set twoRecord to {twoRecord}

set recordList to recordList & twoRecord

-->{{foo:1, bar:"hello"}, {foo:2, bar:"Goodbye"}}

An now we have exactly what the OP wanted.

But if you omit this line:

  set recordList to {recordList}

Or this line:

  set twoRecord to {twoRecord}

It still doesn't work.

So I think the solution is to use {} to change your record into a list
containing a record and then concatenate or simply use the

Set the end of x to y

Contstruct, which probably does the same thing in the background.

HTH

ES

ATOM RSS1 RSS2