From: Richard Demanowski
Subject: How to get a "program listing"
Date: 
Message-ID: <923899706.033.6@news.remarQ.com>
OK, I know it sounds like a stupid question, but I can't seem to find a
way to get my lisp interpreter (GNU Common Lisp gcl-2.2.2) to give me a
"program listing".

How do I get a lisp interpreter to show me it's functions and lists?
There's gotta be a simple way to do this, but I'm not finding it in the
documentation anywhere.  

Is there a lisp equivalent of the old Applesoft BASIC "LIST" command?  It
seems to me there should be.  I mean, lisp is an interpreted language,
so I should be able to get the interpreter to show me it's current
program, but I can't seem to figure out how.

Can anybody give me a clue on this?

Thanx
RichD
--
            ········@wasatch.com (finger for PGP public key)
                    http://www.wasatch.com/~rdemanow/
-------------------------------------------------------------------------
  "I may disagree with what you have to say, but I will defend, to the
               death, your right to say it." -- Voltaire

From: Gareth McCaughan
Subject: Re: How to get a "program listing"
Date: 
Message-ID: <863e26qjao.fsf@g.pet.cam.ac.uk>
Richard Demanowski wrote:

> OK, I know it sounds like a stupid question, but I can't seem to find a
> way to get my lisp interpreter (GNU Common Lisp gcl-2.2.2) to give me a
> "program listing".
> 
> How do I get a lisp interpreter to show me it's functions and lists?
> There's gotta be a simple way to do this, but I'm not finding it in the
> documentation anywhere.  
> 
> Is there a lisp equivalent of the old Applesoft BASIC "LIST" command?  It
> seems to me there should be.  I mean, lisp is an interpreted language,
> so I should be able to get the interpreter to show me it's current
> program, but I can't seem to figure out how.
> 
> Can anybody give me a clue on this?

Clue #1: Lisp is not "an interpreted language", and in particular
the implementation you're using (GCL) works by compiling to C, handing
the C code to your native C compiler, and slurping in the resulting
object file. The original source code for a function you've defined
may have vanished completely.

Clue #2: There's no such thing as "its current program". That's often
a really bad way to think in Lisp; because Lisp systems are interactive
(note: that's not the same as "interpreted"!) it's often better to
say that you have a bunch of functions and objects and things, and
the freedom to put them together in whatever way you like. There's no
presupposition that everything of interest is in the call tree starting
at some privileged "main" function (as in C) or that what you've
written can be thought of as a bunch of lines in a particular order
(as in BASIC).

Clue #3: If you're writing anything non-trivial you would be well
advised to put your source code into a separate file; LOAD it when
it changes. (Or, if performance matters, COMPILE-FILE it and then
LOAD it.) That way, you don't need anything like a LIST command.
This is almost always a more pleasant way of working than the old
BASIC way (I know newer BASICs don't force you to do this) of
editing the program one line at a time.

Clue #4: You could record the state of every symbol in your Lisp
system when you start it up (things to look up in the HyperSpec:
DO-SYMBOLS, *PACKAGE*, BOUNDP, FBOUNDP, SYMBOL-VALUE, SYMBOL-FUNCTION)
and then, when you want to see what's changed, go through them all
similarly seeing what is different. You probably want to store the
information in a hash table rather than a list (MAKE-HASH-TABLE,
GETHASH); or even in two hash tables (one for ordinary values, one
for function values). This is likely to be pretty painful, and there's
no guarantee that it will be able to give you enough information
to be useful. On the whole, I recommend not bothering.

Clue #5: Alternatively, you could make your own version of DEFUN
that records what it's doing:

    ;; DANGER: untested code!
    (defvar *my-defs* (make-hash-table :test #'eq))
    (defmacro xdefun (&whole whole name args &body body)
      (setf (gethash name *my-defs*) whole)
      `(defun ,name ,args . ,body))

This won't do anything to record your variables, classes, methods,
structure types, etc. Anyway, to list the things you've defined with
XDEFUN you use a function along the following lines:

    (defun list-xdefs ()
      (let ((*print-readably* t))
        (loop for form being each hash-value of *my-defs* do
          (pprint form))))

If you want everything you do recorded, then rather than defining
recording versions of DEFUN, DEFSTRUCT, DEFPARAMETER, blah, blah, blah,
I suggest

    (defvar *my-defs* (make-hash-table :test #'eq))
    (defmacro xxx (&whole whole definer name &rest remainder)
      (declare (ignore remainder definer))
      (setf (gethash name *my-defs*) (cdr whole))
      (cdr whole))

and then you say e.g.

    (xxx defun foo (x) (cons x x))
    (xxx defvar *thing* (make-array '(100) :initial-element 'wombat))

-- 
Gareth McCaughan       Dept. of Pure Mathematics & Mathematical Statistics,
·····@dpmms.cam.ac.uk  Cambridge University, England.
From: David B. Lamkins
Subject: Re: How to get a "program listing"
Date: 
Message-ID: <CDoQ2.39486$A6.20149587@news1.teleport.com>
In article <···············@news.remarQ.com> , Richard Demanowski 
<········@wasatch.com>  wrote:

> OK, I know it sounds like a stupid question, but I can't seem to find a
> way to get my lisp interpreter (GNU Common Lisp gcl-2.2.2) to give me a
> "program listing".
>
> How do I get a lisp interpreter to show me it's functions and lists?
> There's gotta be a simple way to do this, but I'm not finding it in the
> documentation anywhere.
>
> Is there a lisp equivalent of the old Applesoft BASIC "LIST" command?  It
> seems to me there should be.  I mean, lisp is an interpreted language,
> so I should be able to get the interpreter to show me it's current
> program, but I can't seem to figure out how.
>
> Can anybody give me a clue on this?

You may want to pick up a couple of textbooks to help you learn about Lisp.
I recommend these to beginners:

Object-Oriented Common Lisp, Slade, 1998, Prentice-Hall, ISBN 0-13-605940-6

Slade's book is probably the best book available on actually using a Common
Lisp environment for something other than AI programming. I think it's
suitable for a beginner, but should probably be supplemented by another
title that provides better insight into the Lisp language.

Common LISPcraft, Wilensky, 1986, W.W. Norton & Co., ISBN 0-393-95544-3

When I was first learning Common Lisp, I found Wilensky's book the most
helpful at exposing some of Lisp's unique concepts, such as closures. This
book is easy to read (without being patronizing) and includes a lot of very
clear examples. There's also a brief Common Lisp reference in the appendix.
I still recommend this as a first book for beginners.

You'll find other recommendations at:
<http://www.teleport.com/~dlamkins/computer-books.html>
<http://www.elwoodcorp.com/alu/table/learn.html>

--
David B. Lamkins <http://www.teleport.com/~dlamkins/>

Recently undead Isabelle to the archangel Gabriel in "The Prophecy II":
"So, you're keeping me alive because you don't know DOS?"
From: David B. Lamkins
Subject: Re: How to get a "program listing"
Date: 
Message-ID: <mJoQ2.39492$A6.20152570@news1.teleport.com>
In article <·······················@news1.teleport.com> , "David B. Lamkins"
<········@teleport.com> wrote:

[snip]

> You'll find other recommendations at:
> <http://www.teleport.com/~dlamkins/computer-books.html>
> <http://www.elwoodcorp.com/alu/table/learn.html>

I really need to learn to copy and paste <g>.  The last URL should be
<http://www.elwoodcorp.com/alu/table/learn.htm>

--
David B. Lamkins <http://www.teleport.com/~dlamkins/>

There are many ways to abbreviate something, but only one way not to.
From: Sunil Mishra
Subject: Re: How to get a "program listing"
Date: 
Message-ID: <efy4smk1l4s.fsf@euler.cc.gatech.edu>
Richard Demanowski <········@wasatch.com> writes:

> OK, I know it sounds like a stupid question, but I can't seem to find a
> way to get my lisp interpreter (GNU Common Lisp gcl-2.2.2) to give me a
> "program listing".
> 
> How do I get a lisp interpreter to show me it's functions and lists?
> There's gotta be a simple way to do this, but I'm not finding it in the
> documentation anywhere.  
> 
> Is there a lisp equivalent of the old Applesoft BASIC "LIST" command?  It
> seems to me there should be.  I mean, lisp is an interpreted language,
> so I should be able to get the interpreter to show me it's current
> program, but I can't seem to figure out how.
> 
> Can anybody give me a clue on this?

Lisp is not necessarily interpreted, but it is interactive. MCL for
instance necessarily compiles code before executing it. (It can optionally
pre-compile a file and load that, rather than compiling at load time.) You
have basically made a bad assumption as to how lisp works.

Some Lisps record source code as debug information when you load your
source. Some don't. Most of them record some information about where the
code came from. All this is implementation dependent. In general, don't
rely on being able to get the exact read-time source from your lisp
environment.

As for what functions are defined (lisp does not work on lines, so an
analog to basic's LIST would be impossible anyway) there is an apropos
facility. I don't remember if the behavior of apropos is defined by the
standard or the implementation, but I'd be willing to bet it was the
latter.

Sunil