From: jazzbox
Subject: 2 simple questions....
Date: 
Message-ID: <3b69f24e.40436985@news.w-link.net>
I've been working with Franz Lisp, just in the Listener, and I can't
figure out how to

1) delete a variable
2) pprint a defun 'd form

I did RTFM, can't get it!

From: Geoffrey Summerhayes
Subject: Re: 2 simple questions....
Date: 
Message-ID: <c2qa7.58142$uH4.4059253@news20.bellglobal.com>
<jazzbox> wrote in message ······················@news.w-link.net...
> I've been working with Franz Lisp, just in the Listener, and I can't
> figure out how to
>
> 1) delete a variable

(makunbound 'variable-name) ;; If I understand your intent

> 2) pprint a defun 'd form
>

Got me, I don't understand why this would be an issue.
Is the defun compiled?

--------
Geoff

To heck with the standard disclaimer: This is strictly someone else's
opinion, I will deny all knowledge of this conversation unless you're
willing to send me a decent amount of money to rat on them.
From: jazzbox
Subject: Re: 2 simple questions....
Date: 
Message-ID: <3b6adb75.13375643@news.w-link.net>
On Fri, 3 Aug 2001 00:43:25 -0400, "Geoffrey Summerhayes"
<·············@hNoOtSmPAaMil.com> wrote:

>
><jazzbox> wrote in message ······················@news.w-link.net...
>> I've been working with Franz Lisp, just in the Listener, and I can't
>> figure out how to
>>
>> 1) delete a variable
>
>(makunbound 'variable-name) ;; If I understand your intent
>

Thank you.  I think that I didn't really understand the difference
between a symbol and a variable.  From what I gather, a variable is
nothing more than a symbol with the value attached to it, the value
being something other than the symbol name.  This idea causes me a bit
of confusion.  It seems that when you use the setf form, you bring a
symbol into existence.  However I don't see how you remove the symbol
from existence.... I suspect that declaring a symbol is equivalent to
defining a global variable in a conventional program.  I need to learn
more about the laws of scope as I suspect nested symbols are garbage
collected.

Mike

>> 2) pprint a defun 'd form
>>
>
>Got me, I don't understand why this would be an issue.
>Is the defun compiled?
>

No, not compiled... In Prolog there is a "listing" predicate which
gives you everything in memory.  I am accustomed to that so I was
looking for the same type of thing.  

Thanks again.
>--------
>Geoff
>
>To heck with the standard disclaimer: This is strictly someone else's
>opinion, I will deny all knowledge of this conversation unless you're
>willing to send me a decent amount of money to rat on them.
>
>
>
From: Kent M Pitman
Subject: Re: 2 simple questions....
Date: 
Message-ID: <sfwwv4kap47.fsf@world.std.com>
(jazzbox) writes:

> On Fri, 3 Aug 2001 00:43:25 -0400, "Geoffrey Summerhayes"
> <·············@hNoOtSmPAaMil.com> wrote:
> 
> >
> ><jazzbox> wrote in message ······················@news.w-link.net...
> >> I've been working with Franz Lisp, just in the Listener, and I can't
> >> figure out how to
> >>
> >> 1) delete a variable
> >
> >(makunbound 'variable-name) ;; If I understand your intent
> >
> 
> Thank you.  I think that I didn't really understand the difference
> between a symbol and a variable.  From what I gather, a variable is
> nothing more than a symbol with the value attached to it, the value
> being something other than the symbol name.  This idea causes me a bit
> of confusion.  It seems that when you use the setf form, you bring a
> symbol into existence.

No.  When you type the variable's name at all.  (The underlying function
that does the demand-creation is called INTERN.) For example:

'a

causes the symbol A to exist.

(eq 'a 'a)

will verify that you're always getting the symbol A.

A symbol is, generally, potentially a [dynamic a.k.al special] variable
however, a variable is not generally stored in a symbol; certainly a lexical
variable is not.  This takes some getting used to.  Special variables are
really different critters than lexical variables, though they can be written
the same.  

All variables *are* named by symbols, but normally the location of a variable,
certainly a lexical variable, is temporary to the execution of the program
and is not a program-accessible thing.  A special variable is something that
is stored where you can get at it, as a reference to 
(symbol-value 'special-variable-name) will reveal.

> However I don't see how you remove the symbol
> from existence.... 


MAKUNBOUND removes the value that is associated with the symbol (i.e.,
with the special (a.k.a dynamic) variable).  It does not remove te symbol.

In general, you should not worry about the removal of symbols.  They will
be removed by the garbage collector if they really need to be.

UNINTERN can be used to remove a symbol's indexing from a package so that
a fresh reference to it (e.g., typing its name or calling INTERN) will
demand-create a new symbol.  However, it's a *very bad* idea to call INTERN
casually.  You certainly should not do this just because you are done
with a symbol.  Use it only in the most extreme cases when you are a lot
more familiar with the system than it sounds like you are.  UNINTERN will
almost always confuse you and is rarely actually needed in practice.

> I suspect that declaring a symbol

Symbols don't get declared. They just are.  They are like truth and justice
and exist ready to serve you whether you've ever called on them before or not.

> is equivalent to
> defining a global variable in a conventional program.

Lisp's meaning of global variable is either a special variable or a 
constant variable.   The former can be dynamically bound or assigned; the
latter cannot have its value changed.  For the former, see DEFPARAMETER
and DEFVAR; for the latter, see DEFCONSTANT.

> I need to learn
> more about the laws of scope as I suspect nested symbols are garbage
> collected.

No, symbols that are not "pointed to" or "referred to" are garbage collected.
This is not an issue of scope, except in the trivial sense that the GC will
not collect anything that is in *anyone*'s scope.

> Mike
> 
> >> 2) pprint a defun 'd form
> >>
> >
> >Got me, I don't understand why this would be an issue.
> >Is the defun compiled?
> >
> 
> No, not compiled... In Prolog there is a "listing" predicate which
> gives you everything in memory.  I am accustomed to that so I was
> looking for the same type of thing.  

You're supposed to keep your definitions in a file and load them in,
not in memory to be dumped.  Some Lisps do retain some information that
allows you to do it the other way around, but it is rarely complete and
relying on it as a development paradigm is a bad idea.  There have
been other dialects of Lisp that did do it the way you describe (InterLisp,
for example), but not Common Lisp.
From: Tim Moore
Subject: Re: 2 simple questions....
Date: 
Message-ID: <9kf1b5$3o3$0@216.39.145.192>
On Fri, 3 Aug 2001, Kent M Pitman wrote:

> (jazzbox) writes:
> 
> You're supposed to keep your definitions in a file and load them in,
> not in memory to be dumped.  Some Lisps do retain some information that
> allows you to do it the other way around, but it is rarely complete and
> relying on it as a development paradigm is a bad idea.  There have
> been other dialects of Lisp that did do it the way you describe (InterLisp,
> for example), but not Common Lisp.

Do you mean it "is a bad idea" because it's not portable and Common Lisps
just don't do it that way, or it "is a bad idea" because it's not a good
paradigm for a Common Lisp development environment?

Tim
From: Kent M Pitman
Subject: Re: 2 simple questions....
Date: 
Message-ID: <sfwhevoyi2r.fsf@world.std.com>
Tim Moore <·····@herschel.bricoworks.com> writes:

> On Fri, 3 Aug 2001, Kent M Pitman wrote:
> 
> > (jazzbox) writes:
> > 
> > You're supposed to keep your definitions in a file and load them in,
> > not in memory to be dumped.  Some Lisps do retain some information that
> > allows you to do it the other way around, but it is rarely complete and
> > relying on it as a development paradigm is a bad idea.  There have
> > been other dialects of Lisp that did do it the way you describe (InterLisp,
> > for example), but not Common Lisp.
> 
> Do you mean it "is a bad idea" because it's not portable and Common Lisps
> just don't do it that way, or it "is a bad idea" because it's not a good
> paradigm for a Common Lisp development environment?

I think it's also a bad paradigm because PRINT isn't reliable for 
externalizing all the kinds of data you can type in.  Some objects
aren't printable and some lose the intentional information about where
they came from (e.g., #. or package-prefixes in the face of shared packages).

InterLisp was designed around it, but CL is not.
From: jazzbox
Subject: Re: 2 simple questions....
Date: 
Message-ID: <3b6b1edd.30631245@news.w-link.net>
Kent, Thanks for all the info.  I'm going to reread it again a bit
later.  One quick question if you don't mind:

How do you clear everything out of memory to start afresh?  For
instance, if I want to load in a different or partially different set
of forms?  

I seem to be missing some of these basic concepts in the books/manuals
I have.  I have the Winston LISP book (which by the way he says "a
variable is a symbol thought of as a name for a place to store a
value."), and also the documentation that comes with the Franz Common
Lisp product,  but for some reason some of the basic concepts are
escaping me.  I have a pretty good command of CLIPS and Prolog, but
want to add LISP.  I took  a course in college, but that was many
years ago.

Thanks again -- Mike

On Fri, 3 Aug 2001 21:00:44 GMT, Kent M Pitman <······@world.std.com>
wrote:

>Tim Moore <·····@herschel.bricoworks.com> writes:
>
>> On Fri, 3 Aug 2001, Kent M Pitman wrote:
>> 
>> > (jazzbox) writes:
>> > 
>> > You're supposed to keep your definitions in a file and load them in,
>> > not in memory to be dumped.  Some Lisps do retain some information that
>> > allows you to do it the other way around, but it is rarely complete and
>> > relying on it as a development paradigm is a bad idea.  There have
>> > been other dialects of Lisp that did do it the way you describe (InterLisp,
>> > for example), but not Common Lisp.
>> 
>> Do you mean it "is a bad idea" because it's not portable and Common Lisps
>> just don't do it that way, or it "is a bad idea" because it's not a good
>> paradigm for a Common Lisp development environment?
>
>I think it's also a bad paradigm because PRINT isn't reliable for 
>externalizing all the kinds of data you can type in.  Some objects
>aren't printable and some lose the intentional information about where
>they came from (e.g., #. or package-prefixes in the face of shared packages).
>
>InterLisp was designed around it, but CL is not.
From: Kent M Pitman
Subject: Re: 2 simple questions....
Date: 
Message-ID: <sfw8zh0vlcq.fsf@world.std.com>
(jazzbox) writes:

> Kent, Thanks for all the info.  I'm going to reread it again a bit
> later.  One quick question if you don't mind:
> 
> How do you clear everything out of memory to start afresh?  For
> instance, if I want to load in a different or partially different set
> of forms?  

By far easiest and most reliable is to exit the program and start a
new one.  The Lisp environment is very maleable to redefinition, but it
is not intended to be "cleared".

You *could* make a new package to work with.  Whether you get rid of the
old definitions is an orthogonal question; things like DELETE-PACKAGE can
be used to drop pointers to the whole package *from the package system*,
but that doesn't mean the things aren't pointed to from elsewhere.

But in the normal course of the normal development cycle, I'd say just start
a fresh Lisp.
From: Marco Antoniotti
Subject: Re: 2 simple questions....
Date: 
Message-ID: <y6cn15g6apm.fsf@octagon.mrl.nyu.edu>
A friend who uses Matlab a lot tried CL and asked: how do I see all
the variables I defined?

I came up with the following little routines.  Not much, but they made
him happy.  Of course, you can add a CLEAR (and CLEAR-VARIABLES and
CLEAR-FUNCTIONS) function along the same lines.

Yet, KMP suggestion is better.

==============================================================================

(defun show (&optional (what :variables) (package *package*))
  (ecase what
    (:variables (show-variables package))
    (:functions (show-functions package))))

(defun show-variables (package)
  (do-symbols (s package)
    (multiple-value-bind (sym status)
	(find-symbol (symbol-name s) package)
      (when (and (or (eq status :external)
		     (eq status :internal))
		 (boundp sym))
	(format t "~&Symbol ~S~T -> ~S~%"
		sym
		(symbol-value sym))))))

(defun show-functions (package)
  (do-symbols (s package)
    (multiple-value-bind (sym status)
	(find-symbol (symbol-name s) package)
      (when (and (or (eq status :external)
		     (eq status :internal))
		 (fboundp sym))
	(format t "~&Function ~S~T -> ~S~%"
		sym
		(symbol-function sym))))))

==============================================================================

Cheers

Marco
-- 
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA                 http://bioinformatics.cat.nyu.edu
                    "Hello New York! We'll do what we can!"
                           Bill Murray in `Ghostbusters'.
From: jazzbox
Subject: Re: 2 simple questions....
Date: 
Message-ID: <3b6b2e2a.34548548@news.w-link.net>
On 03 Aug 2001 18:27:17 -0400, Marco Antoniotti <·······@cs.nyu.edu>
wrote:

>
>A friend who uses Matlab a lot tried CL and asked: how do I see all
>the variables I defined?
>
>I came up with the following little routines.  Not much, but they made
>him happy.  Of course, you can add a CLEAR (and CLEAR-VARIABLES and
>CLEAR-FUNCTIONS) function along the same lines.
>
>Yet, KMP suggestion is better.
>
>==============================================================================
>
>(defun show (&optional (what :variables) (package *package*))
>  (ecase what
>    (:variables (show-variables package))
>    (:functions (show-functions package))))
>
>(defun show-variables (package)
>  (do-symbols (s package)
>    (multiple-value-bind (sym status)
>	(find-symbol (symbol-name s) package)
>      (when (and (or (eq status :external)
>		     (eq status :internal))
>		 (boundp sym))
>	(format t "~&Symbol ~S~T -> ~S~%"
>		sym
>		(symbol-value sym))))))
>
>(defun show-functions (package)
>  (do-symbols (s package)
>    (multiple-value-bind (sym status)
>	(find-symbol (symbol-name s) package)
>      (when (and (or (eq status :external)
>		     (eq status :internal))
>		 (fboundp sym))
>	(format t "~&Function ~S~T -> ~S~%"
>		sym
>		(symbol-function sym))))))
>
>==============================================================================
>
>Cheers
>

 thanks, I tried this and it looks like it works fine.


>Marco
>-- 
>Marco Antoniotti ========================================================
>NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
>719 Broadway 12th Floor                 fax  +1 - 212 - 995 4122
>New York, NY 10003, USA                 http://bioinformatics.cat.nyu.edu
>                    "Hello New York! We'll do what we can!"
>                           Bill Murray in `Ghostbusters'.
From: Thomas F. Burdick
Subject: Re: 2 simple questions....
Date: 
Message-ID: <xcv8zh1tv9f.fsf@conquest.OCF.Berkeley.EDU>
(jazzbox) writes:

> I've been working with Franz Lisp, just in the Listener, and I can't
> figure out how to
> 
 [ ... ]
> 2) pprint a defun 'd form
> 
> I did RTFM, can't get it!

This is from CMUCL, but it should work in any implementation.
   * (defun foo (x y z)
       (let ((2x (* x 2)))
         (with-output-to-string (stream)
           (loop for num from y to z
                 do (format stream "~S~%" (* 2x num))))))
   FOO
   * (pprint (function-lambda-expression #'foo))
   (LAMBDA (X Y Z)
     (BLOCK FOO
       (LET ((|2X| (* X 2)))
         (WITH-OUTPUT-TO-STRING (STREAM)
           (LOOP FOR NUM FROM Y TO Z DO (FORMAT STREAM "~S~%" (* |2X| NUM)))))))
From: jazzbox
Subject: Re: 2 simple questions....
Date: 
Message-ID: <3b6ae0a9.14707448@news.w-link.net>
On 03 Aug 2001 01:14:52 -0700, ···@conquest.OCF.Berkeley.EDU (Thomas
F. Burdick) wrote:

>(jazzbox) writes:
>
>> I've been working with Franz Lisp, just in the Listener, and I can't
>> figure out how to
>> 
> [ ... ]
>> 2) pprint a defun 'd form
>> 
>> I did RTFM, can't get it!
>
>This is from CMUCL, but it should work in any implementation.
>   * (defun foo (x y z)
>       (let ((2x (* x 2)))
>         (with-output-to-string (stream)
>           (loop for num from y to z
>                 do (format stream "~S~%" (* 2x num))))))
>   FOO
>   * (pprint (function-lambda-expression #'foo))
>   (LAMBDA (X Y Z)
>     (BLOCK FOO
>       (LET ((|2X| (* X 2)))
>         (WITH-OUTPUT-TO-STRING (STREAM)
>           (LOOP FOR NUM FROM Y TO Z DO (FORMAT STREAM "~S~%" (* |2X| NUM)))))))

Right!  Thanks.  I see now.  

Thanks for your help guys.

Mike
From: Kent M Pitman
Subject: Re: 2 simple questions....
Date: 
Message-ID: <sfwvgk4ap2f.fsf@world.std.com>
(jazzbox) writes:

> 
> On 03 Aug 2001 01:14:52 -0700, ···@conquest.OCF.Berkeley.EDU (Thomas
> F. Burdick) wrote:
> 
> >This is from CMUCL, but it should work in any implementation.
> >   * (defun foo (x y z)
> >       (let ((2x (* x 2)))
> >         (with-output-to-string (stream)
> >           (loop for num from y to z
> >                 do (format stream "~S~%" (* 2x num))))))
> >   FOO
> >   * (pprint (function-lambda-expression #'foo))
> >   (LAMBDA (X Y Z)
> >     (BLOCK FOO
> >       (LET ((|2X| (* X 2)))
> >         (WITH-OUTPUT-TO-STRING (STREAM)
> >           (LOOP FOR NUM FROM Y TO Z DO (FORMAT STREAM "~S~%" (* |2X| NUM)))))))
> 
> Right!  Thanks.  I see now.  
> 
> Thanks for your help guys.

But note that implementations are not required to retain this info,
and can flush it if they want at any time.
From: Eugene Zaikonnikov
Subject: Re: 2 simple questions....
Date: 
Message-ID: <680a835d.0108030159.44ea0c2d@posting.google.com>
Hi,

(jazzbox) wrote in message news:<·················@news.w-link.net>...
> I've been working with Franz Lisp,

Surely Allegro Common Lisp by Franz, Inc.? Franz Lisp is a very
different beast.

> just in the Listener, and I can't figure out how to
[...]
> 2) pprint a defun 'd form

See description of FUNCTION-LAMBDA-EXPRESSION. Note that it can legitimately
return NIL if the lambda expression not available anymore (e.g. was wiped out
during compilation).

--
  Eugene.
From: jazzbox
Subject: Re: 2 simple questions....
Date: 
Message-ID: <3b6adcc6.13712427@news.w-link.net>
On 3 Aug 2001 02:59:51 -0700, ······@funcall.org (Eugene Zaikonnikov)
wrote:

>Hi,
>
>(jazzbox) wrote in message news:<·················@news.w-link.net>...
>> I've been working with Franz Lisp,
>
>Surely Allegro Common Lisp by Franz, Inc.? Franz Lisp is a very
>different beast.
>

Thanks for the reply.  Right, Allegro Common Lisp by Franz.
I haven't been using the GUI, just the Listener so far.  I'm trying to
put together some forms to manipulate a semantic net.  I'm working my
way through the Winston AI book.

>> just in the Listener, and I can't figure out how to
>[...]
>> 2) pprint a defun 'd form
>
>See description of FUNCTION-LAMBDA-EXPRESSION. Note that it can legitimately
>return NIL if the lambda expression not available anymore (e.g. was wiped out
>during compilation).
>

I tried it... I need to look into it some more.  Thanks.
>--
>  Eugene.