Q:

list of digits of a number

I am trying to write a function which takes a number and returns a list of the number's digits. For example:
(list-num 648)
;=> (6 4 8)

I have written some code, but it returns (8 4 6), and I can't use reverse.  MY code so far:
(define (list-num n)
  (if (not (equal? (quotient n 10) 0))
      (cons (modulo n 10) (list-num(quotient n 10)))
      (cons (modulo n 10) '())))

A:

You can use your function as the inner function and wrap an outer function that does the reverse:
(define (list-num n)
  ; inner function - your initial function      
  (define (sub n)
    (if (not (equal? (quotient n 10) 0))
        (cons (modulo n 10) (sub (quotient n 10)))
        (cons (modulo n 10) '())))
  ; call inner function
  (reverse (sub n)))

then
> (list-num 648)
'(6 4 8)

You could also use a named let and an accumulator:
(define (list-num n)
  (let loop ((n n) (acc '())) ; named let, acc=accumulator
    (let ((q (quotient n 10)) (r (remainder n 10)))
      (if (= q 0)
          (cons r acc)
          (loop q (cons r acc))))))

