Defining functions Scheme-style in Common Lisp, without defun

811 views Asked by At

In Scheme, you define functions like

(define f (lambda (x) ...))

In particular, you can do something like this

(define f (g))

where g is some function returning a function. Is it possible to do the same in Common Lisp, i.e. to associate a function symbol with a given anonymous function?

1

There are 1 answers

3
BlenderBender On BEST ANSWER

Nevermind, I just found the answer in Paul Graham's book ANSI Common Lisp (after looking the second time; p. 99):

(setf (symbol-function 'f) (lambda (x) (* x x)))

achieves (for most intents and purposes) the same as

(defun f (x) (* x x))