When does lisp use binary vs. base-10?
Posted: Sat May 11, 2013 10:03 am
Hi all-
I'm on a mission to learn about computers (beyond just using gui programs), and I've decided to tackle LISP.
Working my way through the examples in the book Land of Lisp (by Dr. Barski, written to cover ANSI Common Lisp), I don't understand when lisp evaluates a number as base 10 versus binary.
For example:
(ash 11 -1) yields 5. Why isn't that yielding 1? (ie: 11 binary = 3 base 10. left shift 11 and you get 2^0 , or 1). Instead it wants to convert 11 to binary first (1011) then left shift it to (101) to get 5. Does that strike anyone else as being weird, or is it just me? It seems that if one of the "operands" (sorry if this is the wrong word) is a binary shift, the other "operand" should be binary too, right?
The remainder of the examples in the book seem to use base-10 numbering without converting to binary, so I'm a little confused.
Is there a "rule of thumb" for when lisp evaluates a number's binary representation first versus using base 10?
Thanks!
D
I'm on a mission to learn about computers (beyond just using gui programs), and I've decided to tackle LISP.
Working my way through the examples in the book Land of Lisp (by Dr. Barski, written to cover ANSI Common Lisp), I don't understand when lisp evaluates a number as base 10 versus binary.
For example:
(ash 11 -1) yields 5. Why isn't that yielding 1? (ie: 11 binary = 3 base 10. left shift 11 and you get 2^0 , or 1). Instead it wants to convert 11 to binary first (1011) then left shift it to (101) to get 5. Does that strike anyone else as being weird, or is it just me? It seems that if one of the "operands" (sorry if this is the wrong word) is a binary shift, the other "operand" should be binary too, right?
The remainder of the examples in the book seem to use base-10 numbering without converting to binary, so I'm a little confused.
Is there a "rule of thumb" for when lisp evaluates a number's binary representation first versus using base 10?
Thanks!
D