From: Tomer Altman
Subject: Loading new definitions into running program images?
Date: 
Message-ID: <4pk1xwnfy2u.fsf@sahara.lbl.gov>
Lisp Wizards,

I've often heard/read of the ability of the Lisp family of languages
being able to load new definitions into a running program image. This
in my mind seems to be an amazing feat, and is often touted as a
superior feature of the language (Paul Graham?) . Yet in all my introductory
exposure to Scheme/Lisp, I cannot seem to find a good, clear example
of this ability in action. Could someone help me see the light?

Many thanks,

~Tomer Altman

From: Joe Marshall
Subject: Re: Loading new definitions into running program images?
Date: 
Message-ID: <brvrhc52.fsf@ccs.neu.edu>
Tomer Altman <·······@lbl.gov> writes:

> Lisp Wizards,
> 
> I've often heard/read of the ability of the Lisp family of languages
> being able to load new definitions into a running program image. This
> in my mind seems to be an amazing feat, and is often touted as a
> superior feature of the language (Paul Graham?) . Yet in all my introductory
> exposure to Scheme/Lisp, I cannot seem to find a good, clear example
> of this ability in action. Could someone help me see the light?

You never once typed a definition into a lisp listener?
From: Will Hartung
Subject: Re: Loading new definitions into running program images?
Date: 
Message-ID: <bf9ie3$cn6pk$1@ID-197644.news.uni-berlin.de>
"Joe Marshall" <···@ccs.neu.edu> wrote in message
·················@ccs.neu.edu...
> Tomer Altman <·······@lbl.gov> writes:
>
> > Lisp Wizards,
> >
> > I've often heard/read of the ability of the Lisp family of languages
> > being able to load new definitions into a running program image. This
> > in my mind seems to be an amazing feat, and is often touted as a
> > superior feature of the language (Paul Graham?) . Yet in all my
introductory
> > exposure to Scheme/Lisp, I cannot seem to find a good, clear example
> > of this ability in action. Could someone help me see the light?
>
> You never once typed a definition into a lisp listener?

It seems silly, but this is pretty much the crux of the matter. It's just
not realized because it's not "your code", it's the "Lisp Environments
Code".

But, Lisp images do this all day long. If you've ever made a change, said
"oops" and had to restart, then you understand some of the difficulties of
loading bad code into a running image :-).

But probably one of the best ways to do this with "your code" is to play
with one of the web server-esque applications floating around, that way you
can start up the server, check it with a browser, make changes, and do it
again.

Regards,

Will Hartung
(·····@msoft.com)
From: Barry Margolin
Subject: Re: Loading new definitions into running program images?
Date: 
Message-ID: <VKXRa.276$0z4.6@news.level3.com>
In article <···············@sahara.lbl.gov>,
Tomer Altman  <·······@lbl.gov> wrote:
>I've often heard/read of the ability of the Lisp family of languages
>being able to load new definitions into a running program image. This
>in my mind seems to be an amazing feat, and is often touted as a
>superior feature of the language (Paul Graham?) . Yet in all my introductory
>exposure to Scheme/Lisp, I cannot seem to find a good, clear example
>of this ability in action. Could someone help me see the light?

The most obvious example is in fixing bugs.  Symbolics used to distribute
system patches to their customers every few months.  You just loaded the
patch files into a running system, and they were updated -- you didn't need
to reboot as you do after patching almost any other operating system.

-- 
Barry Margolin, ··············@level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Fred Gilham
Subject: Re: Loading new definitions into running program images?
Date: 
Message-ID: <u765lwwr42.fsf@snapdragon.csl.sri.com>
Tomer Altman <·······@lbl.gov> writes:

> Lisp Wizards,
> 
> I've often heard/read of the ability of the Lisp family of languages
> being able to load new definitions into a running program image. This
> in my mind seems to be an amazing feat, and is often touted as a
> superior feature of the language (Paul Graham?) . Yet in all my introductory
> exposure to Scheme/Lisp, I cannot seem to find a good, clear example
> of this ability in action. Could someone help me see the light?

Using Emacs/Ilisp:

Do "find file" (usually C-x C-f) on foo.lisp.  Make sure there isn't
already a foo.lisp for this to be clearest.

Type M-x cmulisp (or whatever you have to do to start your lisp).



Type in the following:


(defun foo ()
  (bar)
  (sleep 1))


(defun bar ()
  (format t "This is an erroneous piece of code.~%"))


After typing in each definition, type "C-c c" (or whatever
"compile-defun" is for your Ilisp installation) in the foo.lisp
buffer.

In the lisp listener buffer, type (foo)

You'll see

* (foo)
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.



Without stopping the running program, go to the text buffer, and edit
the bar function:


(defun bar ()
  (format t "This is good code.~%"))

Type "C-c c" in the text buffer again.

Without you doing anything in the lisp buffer, the following will
happen:

This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
This is an erroneous piece of code.
;;;Compiling defun bar
; Converted BAR.
; Compiling LAMBDA NIL: 
; Compiling Top-Level Form: 
BAR
0] This is good code.
This is good code.
This is good code.
This is good code.
This is good code.


My first experience doing this was while running a program that
printed its output in a GUI.  I looked at the GUI, saw that the
program was doing something wrong, edited the offending function, hit
C-c c, and the program just started doing the right thing.

Persistent use of this kind of thing will have an obvious effect on
the development process.

-- 
Fred Gilham                                        ······@csl.sri.com
An ABC camera crew interviewed Hillary Clinton in the Bahamas, where
she was sunning herself on a flat rock to keep her body temperature
up. "Cookies," she said, eyeing the cameras. "Children." -- Fred Reed
From: Simon Katz
Subject: Re: Loading new definitions into running program images?
Date: 
Message-ID: <bfgauo$ebi5f$1@ID-131024.news.uni-berlin.de>
"Fred Gilham" <······@snapdragon.csl.sri.com> wrote in message
···················@snapdragon.csl.sri.com...
>
> Type in the following:
>
>
> (defun foo ()
>   (bar)
>   (sleep 1))


Of course, there should be a loop here, e.g.

(defun foo ()
    (loop do (bar)
          do (sleep 1)))
From: Simon Katz
Subject: Re: Loading new definitions into running program images?
Date: 
Message-ID: <bfgb02$edlbk$1@ID-131024.news.uni-berlin.de>
"Fred Gilham" <······@snapdragon.csl.sri.com> wrote:
> Type in the following:
>
>
> (defun foo ()
>   (bar)
>   (sleep 1))


Of course, there should be a loop here, e.g.

(defun foo ()
    (loop do (bar)
          do (sleep 1)))
From: Kalle Olavi Niemitalo
Subject: Re: Loading new definitions into running program images?
Date: 
Message-ID: <87llus429n.fsf@Astalo.kon.iki.fi>
"Simon Katz" <·····@nomistech.com> writes:

> (defun foo ()
>     (loop do (bar)
>           do (sleep 1)))

The loop keyword DO can be followed by more than one compound
form, so you can drop the second DO.

As you didn't use any other loop keywords or LOOP-FINISH, you can
even drop the first DO as well, turning the extended loop form
into a simple loop form.

I guess you knew this already.
From: Peng HaiJie
Subject: Re: Loading new definitions into running program images?
Date: 
Message-ID: <503139c2.0307211905.6aefcb9f@posting.google.com>
but how to do this in hemlock of cmucl?
From: Janis Dzerins
Subject: Re: Loading new definitions into running program images?
Date: 
Message-ID: <twkd6g3ufor.fsf@gulbis.latnet.lv>
···@tepus.com (Peng HaiJie) writes:

> but how to do this in hemlock of cmucl?

Easy!  You just need a CMUCL image with Hemlock.  This can be done by
this way:

···@fishbone$ lisp
; Loading #p"/home/jdz/.cmucl-init.lisp".
CMU Common Lisp CVS release-18e-branch + minimal debian patches, running on fishbone
With core: /usr/lib/cmucl/lisp.core
Dumped on: Wed, 2003-07-16 21:45:53+03:00 on fishbone
For support see http://www.cons.org/cmucl/support.html Send bug reports to the debian BTS.
or to ········@debian.org
type (help) for help, (quit) to exit, and (demo) to see the demos

Loaded subsystems:
    Python 1.1, target Intel x86
    CLOS 18e (based on PCL September 16 92 PCL (f))
* (require 'cmucl-hemlock)
;...
;Lots of files being loaded
;...
T
* (ext:save-lisp "my-hemlock.core" :purify t)
[Doing purification: Done.]
[Undoing binding stack... done]
[Saving current lisp image into my-hemlock.core:
Writing 26949144 bytes from the Read-Only space at 0x10000000.
Writing 4554056 bytes from the Static space at 0x28000000.
Writing 4096 bytes from the Dynamic space at 0x48000000.
done.]
···@fishbone$ 

Then you're back in the prompt with a my-hemlock.core image.  Now
you're ready to start hemlock:

···@fishbone$ lisp -core my-hemlock.core 
; Loading #p"/home/jdz/.cmucl-init.lisp".
CMU Common Lisp CVS release-18e-branch + minimal debian patches, running on fishbone
With core: /home/jdz/my-hemlock.core
Dumped on: Tue, 2003-07-22 11:03:35+03:00 on fishbone
For support see http://www.cons.org/cmucl/support.html Send bug reports to the debian BTS.
or to ········@debian.org
type (help) for help, (quit) to exit, and (demo) to see the demos

Loaded subsystems:
    Python 1.1, target Intel x86
    CLOS 18e (based on PCL September 16 92 PCL (f))
    Gray Streams Protocol Support
    CLX X Library MIT R5.02
    Hemlock 3.5
* (ed)

; Loading #p"/home/jdz/.hemlock-init.lisp".
T

(The Hemlock windows pop up.)


To do lisp developing, you'll want to start slave processes.  You do
this using #k"C-M-c".  But slave process must have Hemlock in it.  So
you might need to tell Hemlock to start lisp with different image if
it is not in the default one.  In your Hemlock editor window edit a
file /home/yourname/.hemlock-init.lisp (using "Find File" command,
bound to #k"C-x C-f" normally).  Put this in there:

;;; -*- Mode:Lisp, Editor; Package:HEMLOCK -*-

(in-package :hemlock)

;;; Tell Hemlock how to invoke slave processes
;;; Replace "/path/to/image-with-hemlock" to a real path to image with
;;; Hemlock (this may be the my-hemlock.core made above).
;;;
(setv slave-utility-switches '("-core" "/path/to/image-with-hemlock"))

Now save the file (#k"C-x C-s").  If you want to start the slave
process immediately, just evaluate the abave expression (#k"C-x C-e"),
and then do #k"C-M-c".  Hemlock should prompt you for slave name,
which you may leave with default value and just press enter (return
:).  The slave process should be up and running.

Then you go and edit your lisp programs.  Read user manual for key
bindings.  I can tell you that #k"C-x C-e" evaluates an expression,
#k"C-x C-c" compiles one.  You can switch to the slave buffer any time
using #k"C-M-c", and to the slave background output buffer with
#k"C-M-C".

I have put my current .hemlock-init.lisp with things like mouse wheel
support, customized fonts, some facts for myself to remember and other
things here: http://www.ltn.lv/~jonis/.hemlock-init.lisp.

One more thing: if you want a REPL for your Hemlock image, invoke
command "Select Eval Buffer".  And read the manual :)

Final note: I hope I did not mess up anything above.  I even tried to
copy/paste stuff instead of typing random parts of it by hand.

-- 
Janis Dzerins

  If million people say a stupid thing, it's still a stupid thing.