4 * 3 + 2 * 3 - 1 28 What would you expect the programmer intended in the following? 4*3 + 2*3 -1
Almost everyone would say: 12 + 6 - 1 There's a way to unambiguously use whitespace to alter binding precedence such that code is clearer to read, and significantly faster to write and edit if you consider the cursor movement and shift keys necessary to add parentheses. The 2 rules are: 1. Parentheses have precedence over white space. ie. 2*(3 -1) is the same as 2* (3 -1)-: 2* 3-1. 2. Ambiguous white space (where dyad has space on left side) resolves by binding the left argument as up to the first space to the left of the series of arguments.ie. 2 *3 -1 -: 2*3 -1 -: (2*3)-1 5+ 4+2 *3 -1 -: 5 + ((4+2)*3) -1 3. Im not sure how to handle adverbs and conjunctions, but binding to everything up to whitespace seems entirely functional, so I will suggest that for now. More examples 2 *3 -1 -: (2*3) -1 (rule 2) 4* 3+ 2* 3- 1 -:(4*3+2*3-1) rule 2 (*: 2* 3-1) -: (*: 2 * 3-1) (*:2* 3-1) -: (*:2 * 3-1) -: (*:2) * 3-1 4 *3 +2 *3 -1 -: ((((4*3)+2)*3)-1) +:@-+: 3 -: (+:@[EMAIL PROTECTED]: 3) -: +:@- +: 3 NB. = _12 ... No train, but @ binds with -+: +:@(-+:) 3 NB. = _6 ... binds @ to hook +:@- 2+3 -: (+:@ -2+3) NB. normal parenthesising = _10... right hand side of conjunction doesn't normally get affected. There is another big advantage in addition to clearer code intentions from this syntax change. It would make parentheses only necessary to describe trains, and so make spotting/interpreting trains easier. I still make a lot of bugs by forgetting the postfix preference. When I first started with J, I would fix that by parenthesising everything in sight, and sometimes that would trigger trains unintentionally. This would be very sweet sugar, and hope you consider it. Let me know of any issues you find with the approach. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
