jrincayc / ucblogo-code

Berkeley Logo interpreter
https://people.eecs.berkeley.edu/~bh/logo.html
GNU General Public License v3.0
187 stars 34 forks source link

wrong operator precedence in Ucblogo 6.2.2-2 #173

Closed cazzullo closed 1 year ago

cazzullo commented 1 year ago

Hello and thanks for Ucblogo. I have found a wrong formula parsing in ucblogo 6.2.2-2 that it is also present in the 5.6 version, the operation: log10(8)/log10(2) gives 1.4244.. (with more digits) as a result when it should result 3. Seems that the parser is interpreting the formula as: log10(8/log10(2))

brianharvey commented 1 year ago

This isn't an error; it's the intended behavior.

Using prefix and infix in the same expression results in parsing ambiguities, and people are often surprised by how Logo resolves them. We treat infix operators as tighter binding than prefix functions.

Also, Logo does not have the F(X) syntax for function calls; it's just F X. If you need to use parentheses to resolve a parsing ambiguity, the notation is (F X), as in Lisp. What goes inside the parentheses must be one complete expression. So in your example, you could say

(log10 8)/log10 2