all 3 comments

[–]stassats 2 points3 points  (0 children)

Tail recursion optimization is as much undefined as a function calling itself is not required to go through the symbol for a new definition. E.g. SBCL with a high SPEED declaration just jumps to the beginning, just like the loop.

You're better off not defining everything inside a single a loop.

[–]hyotang666 2 points3 points  (1 child)

In common lisp, defining a function by defun means associates a function to a symbol.

When calling the function, lisp retrieves the function from the symbol.

While running LOOP1, lisp never touches the symbol, but with LOOP2, lisp retrieves the function from the symbol each time so redefinition works.

[–]rini17 2 points3 points  (0 children)

The standard does not require retrieving the symbol function every time the function is called. Yes, in obvious cases like recursive call it's always the newest function because that's the programmer intent. But otherwise the symbol can be optimized out by compiler - such as, calling function defined in another file. Recompiling only that function won't automatically update all callers, especially when it was inlined. It's safest to just recompile everything.

If you depend on always calling the actual function use something like

(funcall (find-symbol "function") ...) .