• 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: Coercion of list to record
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Coercion of list to record


  • Subject: Re: Coercion of list to record
  • From: Kurt Klamp <email@hidden>
  • Date: Thu, 7 Feb 2008 16:58:24 +0100


Am 07.02.2008 um 16:26 schrieb Skeeve:

set theList to {"is | allowed","no"}

set recordItems to {}
repeat with x from 1 to count theList by 2
set end of recordItems to "|" & item x of theList & "|:\"" & item (x + 1) of theList & "\"" as string
end repeat
set AppleScript's text item delimiters to ", "
set recordAsString to ("{" & recordItems as string) & "}"
set AppleScript's text item delimiters to ""
run script recordAsString
Yes! I know this is really pathological. But these pathological cases tend to occure. And when they occure, you will spend hours searching for the reason for the failure of your script.

More important: You also prooved Chris right, because the pain is now increasing!

Skeeve you are right !

But: the OP asked if there's a possibility to convert a list into a record.

He got some examples (and i'll add another one at the end) and some hints how this can be done.
It is, at least for me, a rather often practice to switch between both types.


And if one is aware of the conventions of naming variables and recordlabels (NB the same conventions for the coding itself), things should work.
But again, you are right, its not an granted reliable way. Who walks along this way should know what he's doing.


And to serve the OP with another solution:

(takes use of the satimage.osax)

on makerecord(thelist)
	set p to PlistNew
	set p1 to PlistNewChild  at p key "dummy"
	repeat with i from 1 to (count thelist) step 2
		PlistNewChild (item i+1 of thelist) at p1 key (item i of thelist)
	end
	set r to PlistGet p1
	PlistClose p -- to free memory
	return r
end

BE AWARE OF THE NAMING CONVENTIONS !!


-- Kurt



_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: Coercion of list to record
      • From: Kurt Klamp <email@hidden>
References: 
 >Coercion of list to record (From: "Robert R. Horning" <email@hidden>)
 >Re: Coercion of list to record (From: Christopher Nebel <email@hidden>)
 >Re: Coercion of list to record (From: Bastiaan Boertien <email@hidden>)
 >Re: Coercion of list to record (From: Skeeve <email@hidden>)
 >Re: Coercion of list to record (From: Bastiaan Boertien <email@hidden>)
 >Re: Coercion of list to record (From: Axel Luttgens <email@hidden>)
 >Re: Coercion of list to record (From: Skeeve <email@hidden>)

  • Prev by Date: Re: Coercion of list to record
  • Next by Date: Re: Coercion of list to record
  • Previous by thread: Re: Coercion of list to record
  • Next by thread: Re: Coercion of list to record
  • Index(es):
    • Date
    • Thread