Re: Coercing strings to symbols
Re: Coercing strings to symbols
- Subject: Re: Coercing strings to symbols
- From: has <email@hidden>
- Date: Fri, 15 Feb 2008 20:18:18 +0000
On 15 Feb 2008, at 19:21, Houston, Brad wrote:
I'm creating a method to produce paragraph styles in an InDesign CS2
file
based on parameters listed in an Excel table. My problem is that
many of the
parameters employ what I'll call "Symbols" (not sure what the
official term
is).
I assume you mean 'constants', to use AppleScript's somewhat confusing
parlance. (Other languages use the proper terms 'enumerators' and
'enumerations'/'enumerated types'.)
That is, a preset series of characters which are a value but not a
string. (Example: A value for "Alignment" might be center, not the
string
"center"). Anyone know of a method to coerce the string coming in
from Excel
into such an entity?
There was a discussion of these sorts of limitations just the other
day in the 'Setting parameters in Address Book' thread. Short answer:
no. Longer answer: this sort of thing is trivial in other, more
capable languages such as Python, Ruby and ObjC, e.g.:
#!/usr/bin/env ruby
string = "center"
symbol = string.intern
p symbol
# :center
but is a complete PITA in AppleScript, which isn't designed for this
sort of usage. You can hack around it if you absolutely have to (see:
code generation, evils of) but if there's a simple, reliable, non-
hackish way of doing it in AppleScript then you should stick with
that, or else switch to one of the other aforementioned languages.
Currently, in each such case I'm using the string values as a test,
that
when true then substitutes the hard-coded symbol, but the
inefficiency is
annoying.
That's the best way to do it in AppleScript. As for 'inefficiency'
concerns; while the code itself may be a bit verbose (stick it in a
separate library if the clutter bothers you), it's unlikely to have a
significant impact on performance unless your code is badly written.
has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
_______________________________________________
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