From: K�roly Ladv�nszky
Subject: Question: Dynamic program modification
Date: 
Message-ID: <3bd86a37_5@corp-goliath.newsgroups.com>
Hi,


I've been experimenting with Lisp for just a short period of time.
I wonder if its possible to 'read-in' Lisp code while the program is
running.
Things like updating a function with a new version etc..

Thanks for any comment,

K�roly



______________________________________________________________________________
Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net

From: Barry Margolin
Subject: Re: Question: Dynamic program modification
Date: 
Message-ID: <ym_B7.28$o03.1351@burlma1-snr2>
In article <··········@corp-goliath.newsgroups.com>,
K�roly Ladv�nszky <··@bb.cc> wrote:
>I've been experimenting with Lisp for just a short period of time.
>I wonder if its possible to 'read-in' Lisp code while the program is
>running.
>Things like updating a function with a new version etc..

Yes.  The program can call LOAD, it can use EVAL to execute DEFUN forms
that it puts together itself, it can use (setf (symbol-function
'some-function) ...) to replace the definition of a function, and so on.

-- 
Barry Margolin, ······@genuity.net
Genuity, 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: Kent M Pitman
Subject: Re: Question: Dynamic program modification
Date: 
Message-ID: <sfwu1wnsbvu.fsf@world.std.com>
"K�roly Ladv�nszky" <··@bb.cc> writes:

> I've been experimenting with Lisp for just a short period of time.
> I wonder if its possible to 'read-in' Lisp code while the program is
> running.
> Things like updating a function with a new version etc..

Sure.

Executing a DEFUN will immediately redefine the function.  Lisp's data
storage (which includes its function base) is object-oriented.
Redefining a globally defined function is just snapping the pointer in
a symbol's function cell and making it point to something else.  All
calls to globally named functions go indirect through that cell, so
they see the update immediately (unless inlining has been specifically
requested, but that's rare, and can in some cases be "fixed" with a 
NOTINLINE declaration).

Suppose the definition of a function add3 is:

 (defun add3 (x) (+ x 3))

but it lives in a file add3.lisp.  For example:

 (defun add3 (x)
   (let ((me #'add3))
     (load "add3.lisp")
     (when (eq me #'add3) 
       (error "add3.lisp has no definition of add3."))
     (add3 x)))

Of course, it's possible to make a macro that packages this up better, but
I didn't do that because I didn't want you to get lost in the macrology
and not see the expanded code that was relevant to your question.

Btw, I wouldn't characterize what you asked for as "dynamic progrma
modification"; i'd call it just "dynamic program (re)definition".
Modifying a function is another matter--there are no operations on
code vectors that will side-effect them as if they were data.
From: K�roly Ladv�nszky
Subject: Re: Question: Dynamic program modification
Date: 
Message-ID: <3bd87ffb_4@corp-goliath.newsgroups.com>
Thanks Kent for your answer. It has been very helpful, 'load' works great,
even with fsl files. Let me ask
you something about the 'other way round'. Is it possible to save/load Lisp
program objects
into a file (aka serialize)?

Cheers,

K�roly

"Kent M Pitman" <······@world.std.com> az al�bbiakat �rta a k�vetkez�
�zenetben: ····················@world.std.com...
> "K�roly Ladv�nszky" <··@bb.cc> writes:
>
> > I've been experimenting with Lisp for just a short period of time.
> > I wonder if its possible to 'read-in' Lisp code while the program is
> > running.
> > Things like updating a function with a new version etc..
>
> Sure.
>
> Executing a DEFUN will immediately redefine the function.  Lisp's data
> storage (which includes its function base) is object-oriented.
> Redefining a globally defined function is just snapping the pointer in
> a symbol's function cell and making it point to something else.  All
> calls to globally named functions go indirect through that cell, so
> they see the update immediately (unless inlining has been specifically
> requested, but that's rare, and can in some cases be "fixed" with a
> NOTINLINE declaration).
>
> Suppose the definition of a function add3 is:
>
>  (defun add3 (x) (+ x 3))
>
> but it lives in a file add3.lisp.  For example:
>
>  (defun add3 (x)
>    (let ((me #'add3))
>      (load "add3.lisp")
>      (when (eq me #'add3)
>        (error "add3.lisp has no definition of add3."))
>      (add3 x)))
>
> Of course, it's possible to make a macro that packages this up better, but
> I didn't do that because I didn't want you to get lost in the macrology
> and not see the expanded code that was relevant to your question.
>
> Btw, I wouldn't characterize what you asked for as "dynamic progrma
> modification"; i'd call it just "dynamic program (re)definition".
> Modifying a function is another matter--there are no operations on
> code vectors that will side-effect them as if they were data.


______________________________________________________________________________
Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net