• 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: NSExpression is incorrect?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSExpression is incorrect?


  • Subject: Re: NSExpression is incorrect?
  • From: Roland King <email@hidden>
  • Date: Sun, 21 Nov 2010 14:07:15 +0800

I agree with you that exponentiation is usually defined as right-associative.

How about a compatibility switch in your code which you can flip to make it work either way.

On 21-Nov-2010, at 11:25 AM, Dave DeLong wrote:

> Hi everyone,
>
> Let's say I have the string @"2 ** 3 ** 2".  I can run this through NSPredicate to parse it into an NSExpression tree for me, like so:
>
> NSExpression * e = [(NSComparisonPredicate *)[NSPredicate predicateWithFormat:@"2 ** 3 ** 2 == 0"] leftExpression];
>
> When I log/evaluate this predicate, it gives me "(2 ** 3) ** 2", which evaluates to 64.  In other words, NSExpression (or NSPredicate or whomever) has assumed that the power operator is a left-associative operator.
>
> According to Wikipedia (the source of all truth and knowledge), when no parentheses are present in the expression, "the order is usually understood to be top-down, not bottom-up."  [1]  In other words, "a ** b ** c" is understood to be "a ** (b ** c)", not "(a ** b) ** c".  Put more formally, the power operator is supposed to be right associative.  (rdar://problem/8692313)
>
> I'm currently working on some code that mimics much of the behavior of NSExpression.  However, I'm now faced with a choice:  do I make my code technically correct by making the power operator right associative, or do I maintain parity with NSExpression and make it left associative?
>
> Any suggestions you have would be welcome.
>
> Thanks,
>
> Dave DeLong
>
> [1]: http://en.wikipedia.org/wiki/Exponentiation#Identities_and_properties
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSExpression is incorrect?
      • From: Ben Haller <email@hidden>
References: 
 >NSExpression is incorrect? (From: Dave DeLong <email@hidden>)

  • Prev by Date: help with bindings
  • Next by Date: Re: Help with Basics (Was: help with bindings)
  • Previous by thread: NSExpression is incorrect?
  • Next by thread: Re: NSExpression is incorrect?
  • Index(es):
    • Date
    • Thread