From: Anticomuna
Subject: question about defun
Date: 
Message-ID: <bc9ffba3-5b5c-4648-9a22-9c7a45fcd4f5@e53g2000hsa.googlegroups.com>
Hi,

I would like to understad how defun works. I have clisp installed here
and I tried to use macroexpand, but it didn't make much sense to me.

I thought because defun was a macro it could be defined in terms of
special operators and other basic functions alone. The output that I
got from the macroexpand was a lot different.

How could I set the function cell of a symbol globally? setf? Isn't it
setq the special operator for assignment?

From: Rainer Joswig
Subject: Re: question about defun
Date: 
Message-ID: <joswig-281FDA.05032816072008@news-europe.giganews.com>
In article 
<····································@e53g2000hsa.googlegroups.com>,
 Anticomuna <············@uol.com.br> wrote:

> Hi,
> 
> I would like to understad how defun works. I have clisp installed here
> and I tried to use macroexpand, but it didn't make much sense to me.

DEFUN expands to some code that informs the Lisp system
about various things (like source forms, source locations,
argument lists, ...). It also creates a function that
knows for which symbol it has been defined.
These side effects are very useful.

> 
> I thought because defun was a macro it could be defined in terms of
> special operators and other basic functions alone. The output that I
> got from the macroexpand was a lot different.
> 
> How could I set the function cell of a symbol globally? setf? Isn't it
> setq the special operator for assignment?


CL-USER 3 > (setf (symbol-function 'foo) #'list)
#<Function LIST 41100450EC>

CL-USER 4 > (foo 1 2 3)
(1 2 3)




CL-USER 8 > (setf (symbol-function 'bar) (compile nil '(lambda (a b c) (+ a (* b c)))))
#<Function 11 4060000F14>

CL-USER 9 > (bar 3 4 5)
23

-- 
http://lispm.dyndns.org/
From: Vassil Nikolov
Subject: Re: question about defun
Date: 
Message-ID: <snziqv6ld12.fsf@luna.vassil.nikolov.name>
On Wed, 16 Jul 2008 05:03:29 +0200, Rainer Joswig <······@lisp.de> said:

| In article 
| <····································@e53g2000hsa.googlegroups.com>,
|  Anticomuna <············@uol.com.br> wrote:
|| 
|| I would like to understad how defun works. I have clisp installed here
|| and I tried to use macroexpand, but it didn't make much sense to me.

| DEFUN expands to some code that informs the Lisp system
| about various things (like source forms, source locations,
| argument lists, ...). It also creates a function that
| knows for which symbol it has been defined.
| These side effects are very useful.

  Also, compare the result of

    (macroexpand '(defun foo (x) (+ x 1)))

  with the result of

    (macroexpand '(setf (symbol-function 'foo) #'(lambda (x) (block foo (+ x 1)))))

  (the latter being the essential part of the former), and see the
  last note in the HyperSpec page about DEFUN.

  ---Vassil.


-- 
Peius melius est.  ---Ricardus Gabriel.