I'm kinda new to Lisp in general so please forgive my ignorance here. I'm having a few problems with one function I'm writing, I can get it working by using append, and in theory i know what append does but i cant replicate this using (cons).
Somewhat annoying since it means i dont understand as much as i thought ;).
Code: Select all
(define positive-binary
  (lambda (number)
  "This function simply returns a list containing the binary
  representation of number."
    (cons
      (if (= (remainder number 2) 0)
        0
        1)
      (if (= number 1) ()
        (positive-binary
            (truncate (/ number 2)))))))when putting 10 into the function the result should be 1010 but right now I'm getting 0101. Its not a reversal problem :) am just putting things onto the wrong end of the list it seems.
Thank in advance guys,
Mark.