On Jun 4, 2009, at 8:33 PM, Mark J. Reed wrote:
I was just briefly confused, possibly due to my experience with Certain Other Languages (<cough>Perl</cough>) which have a special precedence rule that attaches parenthesis-enclosed arguments to the preceding subroutine name for parsing purposes:
Yes, Perl does have some magical properties. I am not a fan of magic in programming languages. ;-)
If any list operator (print(), etc.) or any unary operator (chdir(), etc.) is followed by a left parenthesis as the next token, the opera‐ tor and arguments within parentheses are taken to be of highest prece‐ dence, just like a normal function call.
In this case, as I mentioned, “floor” is not a unary operator, so it wouldn’t be covered by this rule if we added it to AppleScript. The issue remains that there is no means to indicate that a command is meant to be treated with some operator precedence, and there are probably reasons (other than backwards compatibility) not to assume that any one-parameter command is to be treated as such.
Also, AppleScript is more dynamic than Perl and doesn’t know whether a command is a “list operator”, either.
Adding this information about commands is an interesting idea, though it opens the door to user confusion. When the rules become more subtle and complex, it makes it harder for someone to read and understand code without first looking up the definitions of every term seen. i.e., someone would have to know the precedence of every command in a script to be sure of its meaning. Treating all commands with the same precedence may confuse some in some cases, but once explained the rules are easy to correctly remember and apply.
It Would Be Nice if integer coercion from real had some finer control; I didn't realize that floor() and friends were Satimagisms. Might turn that into an enhancement request..
1. The “round” command takes a parameter “rounding” that includes the ability to perform a floor (or other) operation:
round 1.9 rounding down -- i.e., "floor" --> 1
2. Coercion is a limited and sometimes ambiguous operation that should be used sparingly. I think it’s probably unfortunate that you can coerce a non-integral float to an integer. It’s better to provide a robust set of operations like rounding and truncating, which may be used to implement the desired semantics precisely.
-- Chris Page
The other, other AppleScript Chris
|