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

NSExpression is incorrect?


  • Subject: NSExpression is incorrect?
  • From: Dave DeLong <email@hidden>
  • Date: Sat, 20 Nov 2010 19:25:13 -0800

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

  • Follow-Ups:
    • Re: NSExpression is incorrect?
      • From: Roland King <email@hidden>
  • Prev by Date: Re: Custom NSCell and target/action
  • Next by Date: help with bindings
  • Previous by thread: Re: Little suggestion for many many images app, best approach.
  • Next by thread: Re: NSExpression is incorrect?
  • Index(es):
    • Date
    • Thread