technoblogy / ulisp-arm

A version of the Lisp programming language for ARM-based boards.
http://www.ulisp.com/
MIT License
106 stars 30 forks source link

Sometimes a return statement never returns #15

Closed technoblogy closed 5 years ago

technoblogy commented 5 years ago

If the expression in a return statement calls a function that itself uses a return statement, the first return statement never returns. For example:

(defun tst (x)
  (loop
   (return (fun x))))

(defun fun (y)
  (loop
   (return (car y))))

then calling:

(tst '(a b))

should return a, but instead hangs up.

A workaround is to assign the result to a temporary variable, and then return that:

(defun tst (x)
  (loop
   (let ((val (fun x)))
     (return val))))

(defun fun (y)
  (loop
   (return (car y))))

So now, as expected:

> (tst '(a b))
a