I'm now readin SICP.Its not a bad book at all.
Its notation however sucks:
(+ (* 3 (+ (* 2 4) (+ 3 5))) (+ (- 10 7) 6))
There is no way i could see which empty)( places contain which operators without reading entire string piece by piece.
This wouldn't work with larger strings.
Name:
Anonymous2008-12-23 14:34
I'm now readin SICP.Its not a bad book at all.
Its notation however sucks:
3*(2*4 + 3 + 5) + 10 - 7 + 6
There is no way i could see which empty)( places contain which operators without reading entire string piece by piece.
This wouldn't work with larger strings.
Name:
Anonymous2008-12-23 14:37
>>2
Why they don't use this format? Its far easier to read.
Name:
Anonymous2008-12-23 14:40
>>3
In what way? It requires mentally running through some arbitrary order of operations to find out what it does, and it also duplicates operators.
Name:
Anonymous2008-12-23 14:43
compare readibility:
(define (abs x)
(cond ((> x 0) x)
((= x 0) 0)
((< x 0) (- x))))
function abs(x){
if(x>0){return x}
if(x=0){return 0}
if(x<0){return -x}
}
Name:
Anonymous2008-12-23 14:46
MORE OPTIMIZED:
function abs(x){if(x<0){return -x}; return x}
Name:
Anonymous2008-12-23 14:49
>>4
It shows the operators.
Your version hides the operators.
When i debug code i want to see operators NOW.
I don't want to evaluate the ()(()()()( aids.
>>13
for extra speed use this version:
function absvalue(x,sign){
if(sign=='-'){x='-'+x}
if(sign=='+'){x='+'+x}
x=parseInt(x);
if(x>0){var result="Positive"}
if(x=0){var result="Zero"}
if(x<0){var result="Negative"}
switch(result){
case "Positive":
return x;break;
case "Zero":
return x;break;
case "Negative";
return negative(x);break;
}
OP has a valid point. There should be some way to "pretty print" the expression automatically so the tree structure is obvious. How can I do that in DrScheme (or any other scheme that doesn't suck)?
no one outside of computer science uses prefix notation. everyone uses infix or postfix notation in the real world.
Name:
Anonymous2008-12-24 4:10
Educationally, RPN calculators have the advantage that the user must understand the expression being calculated: it is not possible to simply copy the expression from paper into the machine and read off the answer without understanding. One must calculate from the middle of the expression, which makes life easier but only if the user understands what they are doing.
Name:
Anonymous2008-12-24 4:31
Educationally, prefix notation calculators have the advantage that the user must understand the expression being calculated: it is not possible to simply copy the expression from paper into the machine and read off the answer without understanding. One must start in the middle of the expression, reverse half of it, interleave the backwards into the forward half, and add parentheses in all the right places.
Name:
Anonymous2008-12-24 4:42
parsing prefix and infix notation requires slow as fuck recursive algorithms due to their complicated syntax. postfix notation is superior.
Name:
Anonymous2008-12-24 4:50
I want to see LISPfags using prefix calculators IRL and talking about how natural and efficient it is.