Re: does property exists in a record
Re: does property exists in a record
- Subject: Re: does property exists in a record
- From: Bryan <email@hidden>
- Date: Sun, 12 Aug 2001 04:56:42 -0400
- Organization: Apex Radiology
So call me simple...
The following uses Akua Sweets, Sigma's Coercions
and Acme Script Widgets:
-------------------------------------------------------------------
on makereference(prpty, recrd)
set rcdlst to (recrd as user list)
if prpty is in rcdlst then
return (offset in list rcdlst of prpty with returning next item)
else
return "no property"
end if
end makereference
makereference("bar", {bar:2})
-------------------------------------------------------------------
Bryan Kaufman
"Neal A. Crocker" wrote:
>
play with the script I've included at the end of this message. you
>
ought to be able modify it to produce a script that generates
>
references to record fields from strings containing field names.
>
Such references can be created even for fields that don't exist.
>
Trying to get the contents of a non-existant record field using a
>
reference to it will, of course, generate an error. You can use a
>
try block, much as you've done in the "propertyExists" handler in
>
you original post, to catch that error and do whatever is necessary
>
for a non-existant record field.
>
>
When playing with the script I've included, be sure to read the
>
comments in the script. It's tricky to compile. Also, the <<
>
and >> characters represent chevrons.
>
>
Neal.
>
>
>Date: Sat, 11 Aug 2001 00:33:51 +1000
>
>Subject: Re: does property exists in a record
>
>From: Adam Hinshaw <email@hidden>
>
>To: <email@hidden>
>
>
>
>on 11/08/01 12:14 AM, Paul Skinner at email@hidden wrote:
>
>
>
> > I would just look for it. If it's not there then add it.
>
> >
>
> > --begin script
>
> > set x to {hello:"world", goodbye:"cruel world"}
>
> > try
>
> > hello of x
>
> > on error
>
> > set x to x & {hello:"world"}
>
> > end try
>
> > --end script
>
>
>
>problem is the property names i will be searching for are not constant.
>
>They come from strings and will vary.
>
>
>
>is there a way then to coerce a string to a record property ??
>
>
>
>doesn't look like it at the moment.
>
>
>
>adam.
>
>
The script below uses << and >> to represent left and right (or is it
>
right and left) chevrons (Option-\ and Shift-Option-\). Watch for
>
line wrapping.
>
______SCRIPT_______________
>
>
on makereference(propname, target)
>
script refscript
>
--{class:reference,<<class form>>:<<constant
>
****usrp>>, <<class want>>:<<class prop>>, <<class seld>>:propname,
>
<<class from>>:target} -- precompiled version of line below
>
{class:reference, <<class form>>:<<constant
>
****usrp>>, <<class want>>:property, <<class seld>>:propname,
>
from:target} -- this line will not compile. must uncoment line above
>
and remove this line. save copy of commentented line above for
>
future recompilation.
>
end script
>
run script refscript
>
end makereference
>
>
set blah to makereference("bar", {bar:2})
>
{blah, blah + 1} -- {bar of {bar:2}, 3}
>
_______________________________________________
>
applescript-users mailing list
>
email@hidden
>
http://www.lists.apple.com/mailman/listinfo/applescript-users