On 10/25/04 9:01 AM, "Bryan Harris" <[EMAIL PROTECTED]> wrote:

> I must admit that I've become much more fond of perl in the last couple
> years and grown more annoyed with AS, for this very reason!  I did try to
> build this script, but I couldn't get what I wanted from it in a reasonable
> amount of time.  Why is "&" able to return lists *and* strings?

Why not? The concatenation operator's behavior is spelled out very clearly
in the AppleScript Language Guide, and Matt Neuburg's "AppleScript: The
Definitive Guide" (O'Reilly) is even better. There are two separate issues
here:

1) Concatenation ( & ) operates on two items of _the same class_. Strings
with strings, lists with lists, records with records, and returns a result
of the same class.

2) IF you attempt to concatenate two items of different classes, the left
side rules. AppleScript will _attempt_ to coerce the right-side item to the
class of the left-side item. If the left item is a string, and the right
item is an integer, a real, a date, a list - the coercion will work, and
you'll get a string. But if you try to concatenate items where the right
item can't be coerced to the same class as the left, OR WHERE  CONCATENATION
DOESN'T OTHERWISE WORK ON THE LEFT SIDE CLASS, the result is a list: you're
"collecting" the various items together.

Integers can't concatenate to another integer in the first place (10 & 3
means nothing) so beginning a concatenation with an integer will always
result in a list.

> Where is it
> documented that you can request the month of a date as an integer?

In the AppleScript Release Notes for AppleScript 1.9.2 (Panther OS 10.3).
The AppleScript Release Notes can be found, as you might expect, at
<http:www.apple.com/applescript/releasenotes/> (linked also from the main
AppleScript page at apple.com).

    " The month constants can now be coerced to numbers. [2396328] "

Since the ASLG has not been revised since 1999 (1.3.7), it's a good idea to
check the Release Notes regularly. All documentation for OS X AppleScript is
there (and OS 9 too). Also  "AppleScript: The Definitive Guide" has
everything up to Panther (AS 1.9.2).

> The
> month of the current date is "October", how does AS coerce that into an
> integer?  

month of current date is NOT "October". It's October - a constant. That
constant can be coerced 'as string' to "October" or 'as integer' (now)  to
10. You cannot coerce the string "October" to 10.

> More generally, unreliable globals, properties that don't always
> stick, and English-like syntax that usually isn't, make AS pretty difficult
> when perl is available.  Of course none of this is your fault -- just a
> source of frustration for me.

Globals are not unreliable when you know how to use them and their scope -
The Definitive Guide is superb on this. Properties stick - you must be
thinking of an issue where Entourage has not implemented the latest script
menu APIs for Panther since Entourage has also to work in Jaguar. That's not
AppleScript's fault. Use the system's script menu instead of Entourage's and
you won't have any problem with Script Editor's saved properties. (Or make
the scripts in Script Debugger or a version of Smile preceding 2.6). The
"English-like" aspect of AppleScript depends largely on the application
developers who implement their own dictionaries.

Perl can't script applications - except via accessing osascript which just
puts you back into AppleScript. You might be interested in a project
undertaken by "has" (Hamish Sanderson) to access application scripting in
Python - it's quite far on its way.

> Thanks again.


Sure. You just need to learn the rules to use AppleScript nicely. Yes, there
are problems with it, but not in this script. The problem was of your own
making, because you did not realize that 'month' is a constant and thought
it was a string already. Because you did not coerce it to either a string or
an integer, you ended up with a list (which you did not realize because you
hadn't studied the concatenation operator). And that in turn ran afoul of
ids that had not previously been reset. Since you did not even know you were
coercing a list to string you would not have even considered tids, of
course.

So it's good you made the first error: otherwise you would not have tripped
on the other two.

The mistake is probably in thinking that AppleScript is "easy". It's
certainly easy to read (you could never get me into Perl), but to _write_
it, you must know its syntax rules as well as for any language. If you give
the ASLG and release notes the same attention you give Perl, you won't go
wrong.

-- 
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

PLEASE always state which version of Microsoft Office you are using -
**2004**, X  or 2001. It's often impossible to answer your questions
otherwise.


-- 
To unsubscribe:                     
<mailto:[EMAIL PROTECTED]>
archives:       
<http://www.mail-archive.com/entourage-talk%40lists.letterrip.com/>
old-archive:       
<http://www.mail-archive.com/entourage-talk%40lists.boingo.com/>

Reply via email to