• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Operator vs. Command precedence
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Operator vs. Command precedence


  • Subject: Re: Operator vs. Command precedence
  • From: Chris Page <email@hidden>
  • Date: Thu, 04 Jun 2009 21:29:40 -0700

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

 _______________________________________________
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

  • Follow-Ups:
    • Re: Operator vs. Command precedence
      • From: "Mark J. Reed" <email@hidden>
References: 
 >Re: Same code gives different answers in 2 different scripts (From: Shane Stanley <email@hidden>)
 >Re: Same code gives different answers in 2 different scripts (From: "Mark J. Reed" <email@hidden>)
 >Re: Operator vs. Command precedence (From: Chris Page <email@hidden>)
 >Re: Operator vs. Command precedence (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: “round” command rounding algorithms
  • Next by Date: Re: Operator vs. Command precedence
  • Previous by thread: Re: Operator vs. Command precedence
  • Next by thread: Re: Operator vs. Command precedence
  • Index(es):
    • Date
    • Thread