• 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: Adding items to a record in a list.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding items to a record in a list.


  • Subject: Re: Adding items to a record in a list.
  • From: Paul Berkowitz <email@hidden>
  • Date: Fri, 01 Apr 2005 12:57:50 -0800

On 4/1/05 12:29 PM, "Robert Smith" <email@hidden> wrote:

> I have a list of records, say:
>
> set r1 to {name:"B", junk:"ab "}
> set r2 to {name:"A"}
> set lr to {r1, r2}
>
> I want to add a "c" to the end of every 'junk:' item in the list. But
> those records with no junk: need to get one with just a "c" in it. I do
> not want to copy the list, only modify it in place. Here is one try:
>
> on addc(j)
> try
> set junk of j to junk of j & "c"
> on error number errnum
> set j to j & {junk:"c"}  -- < -- What to put here??
> end try
> end addc
>
> repeat with i in lr
> addc(i)
> end repeat
>   get lr
> --> {{name:"B", junk:"ab c"}, {name:"A"}}
>
> The first one gets modified, but the second one doesn't. Any ideas?

Actually, the first record got changed to a simple string "ab c" and was no
longer a record of a name and a junk. That's even worse.

Somewhere, you have to _set_ lr's items to the new records. All you're doing
is playing with varuables - you never changed the list items to include the
new variable values.

repeat with i from 1 to (count lr)
    set ii to item i of lr
    set item i of lr to addc(ii)
end repeat
get lr
--> {{name:"B", junk:"ab c"}, {name:"A", junk:"c"}}


on addc(j)
    try
        set junk of j to junk of j & "c"
    on error number errnum
        set j to j & {junk:"c"}
    end try
    return j
end addc


--
Paul Berkowitz


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Adding items to a record in a list. (From: Robert Smith <email@hidden>)

  • Prev by Date: Adding items to a record in a list.
  • Next by Date: Re: folder order
  • Previous by thread: Adding items to a record in a list.
  • Next by thread: Re: Adding items to a record in a list.
  • Index(es):
    • Date
    • Thread