From: Brian Slesinsky
Subject: Re: reflection
Date: 
Message-ID: <bd751532.0208101538.6e837268@posting.google.com>
Saverio Perugini <········@csgrad.cs.vt.edu> wrote in message news:<········································@csgrad.cs.vt.edu>...
> Hello,
> 
> What is the `hello world' of reflection in lisp
> or common lisp?

I don't know what you mean by "reflection", and I'm not a Lisp expert,
but I was curious and found out a few things.

I'll interpret "reflection" the way it's normally done for Java or
Python - that is, using code to browse the runtime system and find out
what types and objects are available.  For example this could be used
in a GUI browser and/or for command-line completion.

At top level there's (list-all-packages).  The do-symbols macro can be
used to loop over the symbols in a package, so that gives us all the
symbols.
(Alternately, apropos-list could be used to search for symbols using a
substring.)

Not all symbols are bound, so they don't actually represent objects in
the system (other than symbols).

To find out if there is a global variable binding for a symbol:

  (boundp 'foo)

To find out if there is a global function binding for a symbol:

  (fboundp 'foo)

To check that it's actually a function:

  (and (functionp #'foo)
       (not (macro-function-p #'foo))
       (not (special-operator-p #'foo)))

If documentation is available, this will get it:
   (documentation 'foo 'function)

It looks like there's no standard way to find out the arguments to a
function, but according to the FAQ there are vendor-specific
extensions.

Some implementations allow you to get the source code using
function-lambda-expression, but it's valid for this function to always
return nil.

There is also the describe function, but its output is
implementation-specific text.

The other thing that would be useful is something like a class
browser.  Ideally we could start at the top with the 't' type and find
out its subtypes, and so on recursively.  Then, for each type, find
out the functions that take arguments of that type.  That doesn't
appear possible for regular types and functions, since types aren't
declared.  I don't understand CLOS well enough to know what's possible
for generic functions..
From: Brian Slesinsky
Subject: Re: reflection
Date: 
Message-ID: <bd751532.0208102235.4692b131@posting.google.com>
Correction: here's the code to test whether a symbol is bound to a
function, copied from the FAQ this time:

(defun fbound-to-function-p (symbol)
     (and (fboundp symbol)
          (not (macro-function symbol))
          (not (special-operator-p symbol))))