Re: symbol-function vs defun question
Albus M Piroglu <[email protected]>
| Newsgroups | gmane.lisp.steel-bank.general |
|---|---|
| Message-ID | <[email protected]> |
I think the solution is to make the form that calls the macro run both
of your calls at whatever 'time' it is acting on.
Your let form, when compiled, favors transforming the defun form before
others, hence the warning. If you put the whole let form in a quoted
form, such as a macro form would be designed with, e.g. a backquote,
then the caller evaluation time can intern the symbol at setf, then
defun afterwards, no?
On Sun, 2024-03-24 at 06:53 -0400, Jeff Cunningham wrote:
> Greetings.
>
> I have been puzzling over a difference between using SYMBOL-FUNCTION
> and DEFUN within a let binding. Here's a contrived example that
> illustrates:
>
> (let ((table1 (make-hash-table)) (table2 '(1 2 3)))
> (setf (symbol-function (intern "DESCRIBE-SOME-TABLES"))
> (lambda () (print (list :table1 table1 :table2 table2))))
> (defun a-function () (describe-some-tables)))
>
> When this is compiled the first time, the compiler issues the
> warning:
>
> ; Undefined function:
> ; DESCRIBE-SOME-TABLES
> ; caught 1 STYLE-WARNING condition
>
> Yet the function works:
>
> (a-function)
> ;; => (:TABLE1 #<HASH-TABLE :TEST EQL :COUNT 0 {1003B80DA3}> :TABLE2
> (1 2 3))
>
> Compiled subsequent times the warning is gone - presumably as the
> package namespace now knows about the function. But unbind it:
>
> (fmakunbound 'describe-some-tables)
>
> and recompile and the warning is back the first time.
>
> Yet if I use DEFUN there is no such warning:
>
> (let ((table1 (make-hash-table)) (table2 '(1 2 3)))
> (defun describe-some-tables ()
> (print (list :table1 table1 :table2 table2)))
> (defun a-function () (describe-some-tables)))
>
> Why is this? And is there a way to get around it so I can define the
> function using symbol-function? The reason for doing this is to be
> able to define functions within macros whose names are composed from
> its arguments.
>
> Thanks.
>
> -- Jeff
>
>
> _______________________________________________
> Sbcl-help mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sbcl-help
_______________________________________________
Sbcl-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sbcl-help