From: Howard Oh
Subject: How to save image in CLISP?
Date: 
Message-ID: <1164294245.821066.309080@k70g2000cwa.googlegroups.com>
Hi,

My main language is (Dolphin) Smalltalk.
I've got interested in LISP by reading PG's books. Trying to learn LISP
with a book "LISP 3rd Edition" and this group and CLISP.

I've got very used to writing procedures with "defun". It is like
Compiler>>compile: method in Smalltalk.

- How do you save current image like I do in Smalltalk?

    SmalltalkSystem current saveImage.


- How do I view the source of a procedure like I do in Smalltalk?

    (Foo>>compiledMethod: #testMethod) getSource.


Best Regards
Howard J. Oh

From: ·········@random-state.net
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <1164296988.375077.154030@l12g2000cwl.googlegroups.com>
Howard Oh wrote:

> - How do you save current image like I do in Smalltalk?
>
>     SmalltalkSystem current saveImage.

Refer to the documentation of the lisp implementation you are using.
Eg. in SBCL you would do

  (save-lisp-and-die "my.core")

> - How do I view the source of a procedure like I do in Smalltalk?
>
>     (Foo>>compiledMethod: #testMethod) getSource.

The short, literally correct, but actually wrong answer is:

  (function-lambda-expression #'your-function)

The longer, real answer:

Common Lisp is not quite as image based as Smalltalk: source code is
not typically retained in the image, and unlike in smalltalk recovering
the source from the compiled representation is not feasible.

While you typically interact with a long-living image when developing
lisp, you keep the source code in files, and let your development
environment deal with passing it on to the lisp image for compilation.

Emacs & Slime form one such environment. Some implementations come with
their own setups.  Note that even if the _editor_ happens to be running
in the same image as you are working in, the source code still lives in
files.

Cheers,

  -- Nikodemus Siivola

PS. CL is the preferred abbreviation for Common Lisp, and Clisp is the
name of one specific implementation.
From: Bill Atkins
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <m2bqmyrvkc.fsf@bertrand.local>
·········@random-state.net writes:

> PS. CL is the preferred abbreviation for Common Lisp, and Clisp is the
> name of one specific implementation.

In the context, it looks like OP is actually referring to the CLISP
implementation.
From: Howard Oh
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <1164310362.094736.272590@f16g2000cwb.googlegroups.com>
> In the context, it looks like OP is actually referring to the CLISP
> implementation.

That right! :-)

I'm writing procedures with defun for the problems & exercises in the
LISP book. I was sad not knowing how to save the procedures before quit
and not losing my homeworks. :-(
From: Howard Oh
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <1164311044.016126.40240@l39g2000cwd.googlegroups.com>
·········@random-state.net ÀÛ¼º:

> Howard Oh wrote:
>
> > - How do you save current image like I do in Smalltalk?
> >
> >     SmalltalkSystem current saveImage.
>
> Refer to the documentation of the lisp implementation you are using.
> Eg. in SBCL you would do
>
>   (save-lisp-and-die "my.core")
>
> > - How do I view the source of a procedure like I do in Smalltalk?
> >
> >     (Foo>>compiledMethod: #testMethod) getSource.
>
> The short, literally correct, but actually wrong answer is:
>
>   (function-lambda-expression #'your-function)
>
> The longer, real answer:
>
> Common Lisp is not quite as image based as Smalltalk: source code is
> not typically retained in the image, and unlike in smalltalk recovering
> the source from the compiled representation is not feasible.
>
> While you typically interact with a long-living image when developing
> lisp, you keep the source code in files, and let your development
> environment deal with passing it on to the lisp image for compilation.
>
> Emacs & Slime form one such environment. Some implementations come with
> their own setups.  Note that even if the _editor_ happens to be running
> in the same image as you are working in, the source code still lives in
> files.
>
> Cheers,
>
>   -- Nikodemus Siivola
>
> PS. CL is the preferred abbreviation for Common Lisp, and Clisp is the
> name of one specific implementation.


Somehow I got an impression that LISP shares alot of advanced feature
with Smalltalk by reading PG's introduction to LISP in his book "Hacker
& Painter".
That's why I was looking for a way to save image, or get source of a
procedure.
Thanks for guiding me not to go fasle pursuit.

Thanks!
From: Pascal Bourguignon
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <87ac2hq60v.fsf@thalassa.informatimago.com>
"Howard Oh" <········@dreamwiz.com> writes:

> Somehow I got an impression that LISP shares alot of advanced feature
> with Smalltalk by reading PG's introduction to LISP in his book "Hacker
> & Painter".
> That's why I was looking for a way to save image, or get source of a
> procedure.
> Thanks for guiding me not to go fasle pursuit.

Well, if you like to do it like this, you can use my ibcl...


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
In deep sleep hear sound,
Cat vomit hairball somewhere.
Will find in morning.
From: Pascal Bourguignon
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <87irh6qdrc.fsf@thalassa.informatimago.com>
·········@random-state.net writes:

> Howard Oh wrote:
>
>> - How do you save current image like I do in Smalltalk?
>>
>>     SmalltalkSystem current saveImage.
>
> Refer to the documentation of the lisp implementation you are using.
> Eg. in SBCL you would do
>
>   (save-lisp-and-die "my.core")
>
>> - How do I view the source of a procedure like I do in Smalltalk?
>>
>>     (Foo>>compiledMethod: #testMethod) getSource.
>
> The short, literally correct, but actually wrong answer is:
>
>   (function-lambda-expression #'your-function)
>
> The longer, real answer:
>
> Common Lisp is not quite as image based as Smalltalk: source code is
> not typically retained in the image, and unlike in smalltalk recovering
> the source from the compiled representation is not feasible.

Well, this is just a matter of writting a couple of tools to be able
to work from the image.  See for example my IBCL sketch:

   http://www.informatimago.com/develop/lisp/small-cl-pgms/ibcl/


Perhaps the only caveat is that lisp implementations don't try to
ensure any compatibility with a lisp executable and an image it hasn't
created itself.  In that sense, lisp images are more fragile: if you
lose the executable with which it was created (install a new version,
or even just recompile and override it), you lose access to your lisp
images.  Which is no problem if you fileOut often...


> While you typically interact with a long-living image when developing
> lisp, you keep the source code in files, and let your development
> environment deal with passing it on to the lisp image for compilation.
>
> Emacs & Slime form one such environment. Some implementations come with
> their own setups.  Note that even if the _editor_ happens to be running
> in the same image as you are working in, the source code still lives in
> files.
>
> Cheers,
>
>   -- Nikodemus Siivola
>
> PS. CL is the preferred abbreviation for Common Lisp, and Clisp is the
> name of one specific implementation.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Small brave carnivores
Kill pine cones and mosquitoes
Fear vacuum cleaner
From: Luke J Crook
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <F_idnbwVWOPIevjYnZ2dnUVZ_sOdnZ2d@giganews.com>
Howard Oh wrote:
> 
> - How do you save current image like I do in Smalltalk?
> 
>     SmalltalkSystem current saveImage.
> 
> 

Frank Buss shows how here: http://www.frank-buss.de/lisp/clisp.html

- Luke
From: Bill Atkins
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <m23b8atab6.fsf@bertrand.local>
"Howard Oh" <········@dreamwiz.com> writes:

> - How do you save current image like I do in Smalltalk?
>
>     SmalltalkSystem current saveImage.

It's implementation-dependent.  In LispWorks, it's hcl:save-image; in
SBCL, it's sb-ext:save-lisp-and-die; in CLISP, it's ext:save-initmem.

>
> - How do I view the source of a procedure like I do in Smalltalk?
>
>     (Foo>>compiledMethod: #testMethod) getSource.

It's environment-dependent.  Lisp doesn't handle source code the same
way Smalltalk does, so it's not necessarily the case that Lisp would
have the source code stored for functions you've defined.  But your
environment will typically be able to take you to the definition of
whatever you're looking for.

In SLIME or LispWorks, pressing M- while point is over a symbol will
take you to the definition of that symbol in the source file where it
was defined.

HTH,
Bill
From: Howard Oh
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <1164310741.985224.91670@j44g2000cwa.googlegroups.com>
Bill Atkins,

> It's environment-dependent.  Lisp doesn't handle source code the same
> way Smalltalk does, so it's not necessarily the case that Lisp would
> have the source code stored for functions you've defined.  But your
> environment will typically be able to take you to the definition of
> whatever you're looking for.

Does LISP quits less often than Smalltalk does? How do you manage all
those files? It looks like a russian-painter-algorithm.


> In SLIME or LispWorks, pressing M- while point is over a symbol will
> take you to the definition of that symbol in the source file where it
> was defined.
> 

It sounds very advanced to CLISP that I'm using.
From: Kaz Kylheku
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <1164314292.354112.125550@l12g2000cwl.googlegroups.com>
Howard Oh wrote:
> Bill Atkins,
> > In SLIME or LispWorks, pressing M- while point is over a symbol will
> > take you to the definition of that symbol in the source file where it
> > was defined.
> >
>
> It sounds very advanced to CLISP that I'm using.

The ANSI Common Lisp feature is called ED, whose behavior is
implementation-specific.

http://www.lisp.org/HyperSpec/Body/fun_ed.html

ED is implemented in CLISP. If you have some function FOO, try (ED
'FOO). It will bring up an editor, with the source. It's not your
original source, but the source code object rendered back to a printed
notation. So for instance any comments which are not captured in a
documentation string will not be there. Symbols will eb printed in
upper case. Etc. If you edit this definition, save and exit, it will be
processed by CLISP.

If FOO is a compiled function which was loaded from a compiled module,
the source won't be available and so ED will signal an error condition
that the function cannot be edited.

If you load or input a function definition as source, and then compile
it with COMPILE, in that situation you can still edit the source.

ED is not all that particularly useful except for trying some quick and
dirty experimental changes in a function without touching the original
source file.

Normally you want to fetch the source file where you defined the
function, do the edit there, and then reload that file. That's what
Bill is talking about.
From: Bill Atkins
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <m2r6vs5hxp.fsf@bertrand.local>
"Howard Oh" <········@dreamwiz.com> writes:

> Does LISP quits less often than Smalltalk does? How do you manage all
> those files? It looks like a russian-painter-algorithm.

Eh?

> It sounds very advanced to CLISP that I'm using.

It is.  There's really no reason to work at a raw REPL these days.
From: Pascal Bourguignon
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <87u00ogoa5.fsf@thalassa.informatimago.com>
Bill Atkins <······@rpi.edu> writes:

> "Howard Oh" <········@dreamwiz.com> writes:
>
>> Does LISP quits less often than Smalltalk does? How do you manage all
>> those files? It looks like a russian-painter-algorithm.
>
> Eh?
>
>> It sounds very advanced to CLISP that I'm using.
>
> It is.  There's really no reason to work at a raw REPL these days.

Who said it was raw?

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"By filing this bug report you have challenged the honor of my
family. Prepare to die!"
From: Bill Atkins
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <m2ac2g86xx.fsf@bertrand.local>
Pascal Bourguignon <···@informatimago.com> writes:

>>> It sounds very advanced to CLISP that I'm using.
>>
>> It is.  There's really no reason to work at a raw REPL these days.
>
> Who said it was raw?

No one, but I assumed "it sounds very advanced" meant that the OP
was using something that didn't support M-.
From: Troels Henriksen
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <87ejrrr4lb.fsf@sigkill.dk>
"Howard Oh" <········@dreamwiz.com> writes:

> Does LISP quits less often than Smalltalk does? How do you manage all
> those files? It looks like a russian-painter-algorithm.

Lisp development is not really image-based the same way as Smalltalk
is. Lisp is more like conventional languages, in that you put the
files in the file-system, and tell the Lisp system to load them after
it has started. Most of us use some kind of build-system, such as ASDF
(which is a bit more than just a build-system, though), to make sure
the files are loaded in the right order.

-- 
\  Troels "Athas"
/\ Henriksen
From: Kaz Kylheku
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <1164313492.735427.114980@h54g2000cwb.googlegroups.com>
Howard Oh wrote:
> Hi,
>
> My main language is (Dolphin) Smalltalk.

CLISP has a reference manual which documents its extensions to the
Common Lisp language.

  http://clisp.cons.org/impnotes.html

Search for the word "image".  It's in the table of contents:

  30.2. Saving an Image

Moreover, when you fire up CLISP and type (save[TAB], it autocompletes
to (saveinitmem. since by default you are in the "CL-USER" package
where extensions are permitted to be visible.

(By CLISP you do mean the CLISP implementation from Michael Stoll,
Bruno Hable and Sam Steingold, and not Common Lisp, right? A lot of
newbies get this wrong, believe it or not. Common Lisp is abbreivated
CL, never CLISP.)
From: Pascal Bourguignon
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <87vel6qekg.fsf@thalassa.informatimago.com>
"Howard Oh" <········@dreamwiz.com> writes:
> My main language is (Dolphin) Smalltalk.
> I've got interested in LISP by reading PG's books. Trying to learn LISP
> with a book "LISP 3rd Edition" and this group and CLISP.
>
> I've got very used to writing procedures with "defun". It is like
> Compiler>>compile: method in Smalltalk.
>
> - How do you save current image like I do in Smalltalk?
>
>     SmalltalkSystem current saveImage.
>
>
> - How do I view the source of a procedure like I do in Smalltalk?
>
>     (Foo>>compiledMethod: #testMethod) getSource.

Either:

- Read the implementation notes:  http://clisp.cons.org/impnotes/image.html

- Use google groups: http://groups.google.com/groups?as_q=save+image+clisp&num=100&scoring=r&hl=en&as_epq=&as_oq=&as_eq=&as_ugroup=comp.lang.lisp&as_usubject=&as_uauthors=&lr=&as_drrb=q&as_qdr=&as_mind=1&as_minm=1&as_miny=1981&as_maxd=23&as_maxm=11&as_maxy=2006&safe=off

- Use google: http://www.google.com/search?&num=100&hl=en&as_ugroup=comp.lang.lisp&as_usubject=&as_uauthors=&lr=&as_drrb=q&as_qdr=&as_mind=1&as_minm=1&as_miny=1981&as_maxd=23&as_maxm=11&as_maxy=2006&safe=off&sa=N&tab=gw&q=save%20image%20clisp


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"You question the worthiness of my code? I should kill you where you
stand!"
From: Mark Tarver
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <1164548199.724645.35080@j44g2000cwa.googlegroups.com>
> - How do you save current image like I do in Smalltalk?

CLISP - (SAVEINITMEM)

> - How do I view the source of a procedure like I do in Smalltalk?

(SYMBOL-FUNCTION 'foo) to view the source code for the function foo.
If its not compiled that is.

Mark
From: Pascal Bourguignon
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <87vel2e15u.fsf@thalassa.informatimago.com>
"Mark Tarver" <··········@ukonline.co.uk> writes:

>> - How do you save current image like I do in Smalltalk?
>
> CLISP - (SAVEINITMEM)

No.  It's EXT:SAVEINITMEM.


>> - How do I view the source of a procedure like I do in Smalltalk?
>
> (SYMBOL-FUNCTION 'foo) to view the source code for the function foo.
> If its not compiled that is.

Mark, the correct function is CL:FUNCTION-LAMBDA-EXPRESSION.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
        Un chat errant
se soulage
        dans le jardin d'hiver
                                        Shiki
From: Mark Tarver
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <1164556766.466535.220860@45g2000cws.googlegroups.com>
Pascal Bourguignon wrote:
> "Mark Tarver" <··········@ukonline.co.uk> writes:
>
> >> - How do you save current image like I do in Smalltalk?
> >
> > CLISP - (SAVEINITMEM)
>
> No.  It's EXT:SAVEINITMEM.
>
>
> >> - How do I view the source of a procedure like I do in Smalltalk?
> >
> > (SYMBOL-FUNCTION 'foo) to view the source code for the function foo.
> > If its not compiled that is.
>
> Mark, the correct function is CL:FUNCTION-LAMBDA-EXPRESSION.
>
>
> --
> __Pascal Bourguignon__                     http://www.informatimago.com/
>         Un chat errant
> se soulage
>         dans le jardin d'hiver
>                                         Shiki

Hum.  I open CLisp 2.39

[1]> (fboundp 'saveinitmem)
T
[2]> (fboundp 'ext:saveinitmem)
T
....................

[6]> (fboundp 'cl:function-lambda-expression)
T
[7]> (defun f (x) 0)
F
[8]> (cl:function-lambda-expression 'f)
(LAMBDA (X) (DECLARE (SYSTEM::IN-DEFUN F)) (BLOCK F 0)) ;
#(NIL NIL NIL NIL ((DECLARATION OPTIMIZE DECLARATION))) ;
F
[9]> (symbol-function 'f)
#<FUNCTION F (X) (DECLARE (SYSTEM::IN-DEFUN F)) (BLOCK F 0)>

Two ways of skinning the same cat?

Mark
From: Pascal Bourguignon
Subject: Re: How to save image in CLISP?
Date: 
Message-ID: <87odquduq7.fsf@thalassa.informatimago.com>
"Mark Tarver" <··········@ukonline.co.uk> writes:

> Pascal Bourguignon wrote:
>> "Mark Tarver" <··········@ukonline.co.uk> writes:
>>
>> >> - How do you save current image like I do in Smalltalk?
>> >
>> > CLISP - (SAVEINITMEM)
>>
>> No.  It's EXT:SAVEINITMEM.
>>
>>
>> >> - How do I view the source of a procedure like I do in Smalltalk?
>> >
>> > (SYMBOL-FUNCTION 'foo) to view the source code for the function foo.
>> > If its not compiled that is.
>>
>> Mark, the correct function is CL:FUNCTION-LAMBDA-EXPRESSION.
>
> Hum.  I open CLisp 2.39
>
> [1]> (fboundp 'saveinitmem)
> T
> [2]> (fboundp 'ext:saveinitmem)
> T
> ....................
>
> [6]> (fboundp 'cl:function-lambda-expression)
> T
> [7]> (defun f (x) 0)
> F
> [8]> (cl:function-lambda-expression 'f)
> (LAMBDA (X) (DECLARE (SYSTEM::IN-DEFUN F)) (BLOCK F 0)) ;
> #(NIL NIL NIL NIL ((DECLARATION OPTIMIZE DECLARATION))) ;
> F
> [9]> (symbol-function 'f)
> #<FUNCTION F (X) (DECLARE (SYSTEM::IN-DEFUN F)) (BLOCK F 0)>
>
> Two ways of skinning the same cat?

Yes, the wrong way and the right way:


C/USER[31]> (COM.INFORMATIMAGO.COMMON-LISP.INTERACTIVE:MKUPACK)
#<PACKAGE USER2>
C/USER2[32]> (defun f (x) x)
F
C/USER2[33]> (compile 'f)
F ;
NIL ;
NIL
C/USER2[34]> (symbol-function 'f)
#<COMPILED-FUNCTION F>
C/USER2[35]> (function-lambda-expression 'f)
(LAMBDA (X) X) ;
T ;
F
C/USER2[36]> (fboundp 'saveinitmem)
NIL
C/USER2[37]> (fboundp 'ext:saveinitmem)
T
C/USER2[38]> 



-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d? s++:++ a+ C+++ UL++++ P--- L+++ E+++ W++ N+++ o-- K- w--- 
O- M++ V PS PE++ Y++ PGP t+ 5+ X++ R !tv b+++ DI++++ D++ 
G e+++ h+ r-- z? 
------END GEEK CODE BLOCK------