clasp icon indicating copy to clipboard operation
clasp copied to clipboard

Recursive functions give compiler warning: Style warning: Undefined function

Open kpoeck opened this issue 6 years ago • 2 comments

COMMON-LISP-USER> (defun fibonacci (n)
  (cond ((< n 0) (error "Please pass a positive argument ~a~%" n))
        ((= n 0) 0)
        ((= n 1) 1)
        (t (+ (fibonacci (1- n))(fibonacci (- n 2))))))
;;; Style warning: Undefined function FIBONACCI
;;;     at -unknown-file- filepos: 0  lineno: 0 
FIBONACCI

The call itself works fine. Pretty sure this is a regression, but don't know how to prove that

kpoeck avatar Dec 15 '18 13:12 kpoeck

Specifically they give a warning in the REPL, i.e. if they are compiled. The file compiler doesn't seem to complain about it, presumably because before compiling the definition it hits the register-global-function-def in the eval-when. Not sure how to fix this. If it's a regression, it's only because we used to not signal any warnings.

Bike avatar May 10 '19 18:05 Bike

sbcl's mechanism for avoiding this appears to be sb-int:named-lambda, which not only gives a function a name, but makes that name bound to the function in its body.

Bike avatar Mar 26 '20 13:03 Bike