Re: Month as Integer (or he's ranting again)
Re: Month as Integer (or he's ranting again)
- Subject: Re: Month as Integer (or he's ranting again)
- From: Richard 23 <email@hidden>
- Date: Fri, 1 Dec 2000 01:25:21 -0800
Sun Real said:
>
The months names are constants, not variables. I haven't played with
>
this but I (a) don't think it could be made to work and (b) wouldn't
>
recommend trying to use constants as record labels in any case. The
>
fastest of these methods was posted by Michelle Steiner yesterday.
Oh, come on! Thinking outside the box is fun!
1. There's no such thing as a constant in AppleScript, although there
are read only properties, of which the months are neither.
2. If a word has already been defined by AppleScript it seems to me
to be the only strings of characters that are pretty much
guaranteed to taken away by an osax in which an author is
allowed to be as reckless as they want, stealing names from
the global namespace.
3. The fastest? Do I smell a challenge? Did you benchmark the
posted methods? Them's fightin' werds! 8)
Look out. I'm about to sermonize about self-determinization again....
Maybe it would be convenient to change all the occurrences of the
constant "tab" to four spaces. If I uses the word "tab" rather than
a literal (eg, ASCII Character 9, "\t", etc). I can do this very
easily.
----------
set tab to " " -- four spaces. Now whereever my script uses
tab, it uses the four spaces instead.
-- don't forget to change it back. it will persist in the current
-- application until it quits which can lead to unexpected results
-- if it happens to be a script editor several hours later!
----------
Or maybe I'd like to return a record from a script which finds a
file. the file information class is just a plain old record with
nifty application terminology for its labels. It would almost feel
like a "real" command handler result if I made up my own record
using similar labels. File information's a little stuffy for an
example so I'll switch to silly mode for the following example:
----------
on GetState(theName)
return {class: vector, name: theName, ==>
level: "very", kind: "cross"}
end GetState
set theObj to GetState("mr. flibbles")
tell theObj to set theMsg to name & " is " & its level & " " & kind
display dialog theMsg buttons "Ok" default button 1 with icon note
--> "mr flibbles is very cross"
get theObj's class
--> vector
----------
What's neat about using the terminology is that I can be more
expressive about my data and flesh it out in such a way that
referencing it and querying its properties makes more sense
to my irrational mind.... And using the predefined labels
doesn't require me to say "its" every time. In the silly
example, I had to refer to the level of mr flibble's state of
mind with "its" because its a user defined label, which seems
to act more like a variable than a property.
and of course AppleScript allows me to modify or even completely
replace the default behavior of command handlers. This can be
very useful. I find the log statement for instance very limiting
and have requested that instead of wiping out the result variable
as a consequence of calling log, it would be much more useful to
leave the result value alone allowing this sort of thing:
----------
get 2 ^ 8
log result
set theValue to result
----------
If it worked that way, the log statement would be more useful
because inserting a temporary log statement wouldn't affect the
script's outcome. Debugging is not very useful if the very act
of doing so affects the way a script works. But I don't have
to wait for Chris and the rest of the wacky laff-a-minute team
of engineers to implement my suggestion. I can do it now.
---------
get 2 ^ 8
log result
set theValue to result
--> 256
log {word: "hey", adj: "neat"}
set {theWord, theAdj} to result
--> {"hey", "neat"}
return theWord
--> "wow"
on log theMsg
continue log theMsg
theMsg as list as item -- this allows me to label values
-- for log messages, and strip the label before returning
end log
---------
Here's what the log for that comes out like:
(*result:256.0*)
(*word:hey, adj:neat*)
At a glance I know what values I was logging. Now that's useful!
AppleScript is wonderful dynamic language that lets you do a lot of
cool things provided you don't let yourself get hemmed in by what
people who don't know what they're talking about tell you what you
can and can't do. (Like me for instance!)
I don't advocate that you do this. I'm saying you can do this.
R23, huffing and puffing and blowing your house down