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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com