Subject: Re: Extracting Function Names
From: rpw3@rpw3.org (Rob Warnock)
Date: Sun, 23 Sep 2007 04:14:08 -0500
Newsgroups: comp.lang.lisp
Message-ID: <P_Kdnezm7739s2vbnZ2dnUVZ_gydnZ2d@speakeasy.net>
Chris Russell  <christopher.m.russell@gmail.com> wrote:
+---------------
| On 22 Sep, 09:14, qikink <qik...@gmail.com> wrote:
| > Is there a way to extract a plaintext function name from
| > the sharp-quoted version?
+---------------

Certainly not portably, and perhaps not even consistently
within a single implementation.

+---------------
| For example:
| ((lambda(x)(subseq x 11 (1- (length x)))) (format nil "~a" #'list))
| 
| happens to return "LIST" in my version of sbcl. It may break
| in the other cases and I expect on other implementations of CL.
+---------------

Even in SBCL it will definitely break in other cases.
Consider these examples from CMUCL [which is probably
still close enough to SBCL for the results to be similar]:

    > (format nil "~a" #'list)

    "#<Function LIST {100C9A01}>"
    > (flet ((list (foo) (+ 3 foo)))
	(format nil "~a" #'list))
    "#<Interpreted Function (FLET LIST
			     )
      {48947A29}>"
    > (let ((list (lambda (foo) (+ 3 foo))))
	(format nil "~a" list))

    "#<Interpreted Function (LAMBDA (FOO) (+ 3 FOO)) {48995A49}>"
    > (let* ((*compile-print* nil)
             (*compile-verbose* nil)
	     (list (compile nil (lambda (foo) (+ 3 foo)))))
	(format nil "~a" list))

    "#<Function \"LAMBDA (FOO)\" {489CEC69}>"
    > 


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607