Re: EU as text (Was: Coercion of a string to a record label?)
Re: EU as text (Was: Coercion of a string to a record label?)
- Subject: Re: EU as text (Was: Coercion of a string to a record label?)
- From: "Neal A. Crocker" <email@hidden>
- Date: Tue, 9 Oct 2001 14:23:51 -0700
You beat me to it :). I'm several days behind in reading mailing
list posts, so I just saw Harald Brandt's post. I should point out
that, in large part, this idea came from Olof Hellman, which I
stumbled upon by perusing ancient archives for this very list. His
idea was for creating records using strings to specifiy labels:
[the characters << and >> below represent chevrons (Opt-L and Shift-Opt-L).]
************ begin script *****************************
on usrf(theList)
script
{<<class usrf>>:theList}
end script
run script result
end usrf
usrf({"a", 1, "b", "2"}) -- {a:1, b:"2"}
************** end script *****************************
I play around with various modifications of the to get a way of
accessing a record property using a string to specify the label.
By the way, in List Guy's repost of my post (see below), all the
phrases bracketed by the characters "+" and ";" (at least, that's how
I see them), such as "+class form;", should be bracketed by chevrons.
Neal.
Date: Tue, 09 Oct 2001 08:35:55 -0700
Subject: EU as text
From: List Guy <email@hidden>
To: <email@hidden>
" That's easy, but I want "EU" to come from a string variable, like: set
aRegion to "EU""
I haven't seen Neal answer yet, so:
(one note: the "class form" should be enclosed in chevrons -- I'm not sure
how it will appear on the mailing list.)
[BEGIN BRILLIANT SOLUTION]
Calculating a Property Label
"Neal A. Crocker" <email@hidden>
------------------------------------------------------------------
set z to "red"
set color_record to {red:1.254, yellow:56.401, blue: 23.9}
get makereference(z,color_record)
------------------------------------------------------------------
I started playing around with the "run script" command to try and make a
function that returns a reference to a field in a record given the name of
the field as a string and the record as arguments. I eventually figured it
out and I've included it below. Please read the notes below the script.
It's tricky to compile! (By the way, the "target" argument of the
"makereference" function can be a script with a "bar" property rather than a
record with a "bar" field.)
-------------------------------------------------------------------
on makereference(propname, target)
script refscript
--{class:reference,+class form;:+constant ****usrp;, +class
want;:+class prop;, +class seld;:propname, +class from;:target}
{class:reference, +class form;:+constant ****usrp;, +class
want;:property, +class seld;:propname, from:target}
end script
run script refscript
end makereference
set blah to makereference("bar", {bar:2})
{blah, blah + 1} -- {bar of {bar:2}, 3}
-------------------------------------------------------------------
The script "refscript" inside the function "makereference" has a commented
line and an uncommented line. The uncommented line won't compile because
script editor chokes on the use of the words "from" and "property".
However, to compile the script, the uncommented line can be deleted and the
commented line can be uncommented. Then the script will compile. The
formerly commented line will be converted by script editor to look like the
uncommented which was deleted. If you plan to compile a script containing
this function more than once, it is best to make a copy of the commented
line for reuse.
[END BRILLIANT SOLUTION]
grh
--__--__--