Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBCL forward declaration: possible?

I'm writing some code in SBCL, and the ordering of my functions keeps causing warnings of the following type to appear when I load files into the REPL:

;caught STYLE-WARNING:
    undefined function: FOO

Where FOO is the symbol for the function. This is purely due to how they are ordered in my file, as the function FOO is defined, just not before the part of the code that throws that warning.

Now, in Clojure, which is the Lisp I'm familiar with, I have the declare form, which lets me make forward declarations to avoid this kind of issue. Is there something similar for SBCL/Common Lisp in general?

like image 699
Koz Ross Avatar asked May 13 '14 06:05

Koz Ross


1 Answers

We can use the '(declaim (ftype ...))' for that:

(declaim (ftype (function (integer list) t) ith))

(defun foo (xs)
  (ith 0 xs))

(defun ith (n xs)
  (nth n xs))

Both the function 'foo' and 'ith' works fine and there is not any style warning about that.

http://www.lispworks.com/documentation/HyperSpec/Body/d_ftype.htm

like image 129
xiepan Avatar answered Sep 20 '22 00:09

xiepan