• 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 19:21:02 -0700

On Jun 4, 2009, at 5:22 PM, Mark J. Reed wrote:

floor(1.5001) as integer ==> 2.0

I don't know how that can parse as "floor(1.5001 as integer)" with the parens where they are.

“floor” is a command, not a function. The parenthesis don’t indicate a function call in this case, they indicate that “1.5001” should be evaluated apart from anything outside the parenthesis (which ultimately makes no difference, because the entire _expression_ is the literal “1.5001”). A clue to this is that when you compile the above code, it appears as

floor (1.5001) as integer

There’s a space between “floor” and the parenthesized argument _expression_. If you run this script, the event log reveals:

tell application "Script Editor"
floor 2
--> 2.0
end tell

AppleScript coerced 1.5001 to an integer and then sent it the floor message (which is, of course, what you’re complaining about). If you want to perform the “floor” command before “as”, then you must place it inside the parenthesis

(floor 1.5001) as integer

to produce

tell application "Script Editor"
floor 1.5001
--> 1.0
end tell

If you look at the precedence chart in the ASLG, you’ll see that “as” is an operator, and all the operators have precedence over commands. That way, command argument expressions are fully evaluated before passing them to the command:

Table 9-2  Operator precedence

The real issue here is that you expect “floor” to have the precedence of some operator, but AppleScript doesn’t know that it behaves as an operator, nor what its precedence would be if it were. If you’d like a means for commands to specify their precedence, please file an enhancement request at <http:bugreport.apple.com>.

-- 
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>)

  • Prev by Date: Re: Same code gives different answers in 2 different scripts
  • Next by Date: Re: Operator vs. Command precedence
  • Previous by thread: Re: Same code gives different answers in 2 different scripts
  • Next by thread: Re: Operator vs. Command precedence
  • Index(es):
    • Date
    • Thread