This function is a CLisp function, this is part of a homework problem, but which is supposed to be written in this different format (the second function).
(defun range (m M) (cond
((> m M) '() )
((= m M) '() )
((< m M) (cons m (range (+ m 1) M ) ) )
)
)
(define (range m M) (cond
((> m M) '() )
((= m M) '() )
((< m M) (cons m (range (+ m 1) M ) ) )
)
)
These should both take a min value (m) and a max value (M) and return the list of integers from min to max (exluding the max value / M-1)
I have traced this over and over and I can't see why it is just returning NIL it must be a very dumb logic mistake.
(range 1 4) => result (1 2 3)
m=1 | M=4 ==> return (cons 1 (2 3) )
m=2 | M=4 ==> return (cons 2 (3) )
m=3 | M=4 ==> return (cons 3 () )
m=4 | M=4 ==> return ()
v ^
---------/
I'm going crazy trying to figure out WHY this is not performing like I trace it.
Again, when I execute the function it results in NIL.