schemecommon-lispansi-common-lisp

Defining functions Scheme-style in Common Lisp, without defun


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?


Solution

  • 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))