From: Didier Verna
Subject: Is there an eval-1 function somewhere ?
Date: 
Message-ID: <muxmzhug632.fsf@uzeb.lrde.epita.fr>
       Hi !

I'd like an eval-1 function (a bit like what macroexpand-1 is to macroexpand):
a function that takes an expression (possibly also a dynamic environment), and
performs one step of evaluation, returning the new partially evaluated
expression (and possibly a modified environment) and also indicating where in
the evaluation process it currently is (for continuation purpose). Does
anybody have this kind of thing at hand ?

Thanks.

-- 
Didier Verna, ······@lrde.epita.fr, http://www.lrde.epita.fr/~didier

EPITA / LRDE, 14-16 rue Voltaire   Tel.+33 (1) 44 08 01 85
94276 Le Kremlin-Bic�tre, France   Fax.+33 (1) 53 14 59 22   ······@xemacs.org

From: Barry Margolin
Subject: Re: Is there an eval-1 function somewhere ?
Date: 
Message-ID: <barmar-04BA89.21173517012006@comcast.dca.giganews.com>
In article <···············@uzeb.lrde.epita.fr>,
 Didier Verna <······@lrde.epita.fr> wrote:

>        Hi !
> 
> I'd like an eval-1 function (a bit like what macroexpand-1 is to macroexpand):
> a function that takes an expression (possibly also a dynamic environment), and
> performs one step of evaluation, returning the new partially evaluated
> expression (and possibly a modified environment) and also indicating where in
> the evaluation process it currently is (for continuation purpose). Does
> anybody have this kind of thing at hand ?

(step <expression>)

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Eli Gottlieb
Subject: Re: Is there an eval-1 function somewhere ?
Date: 
Message-ID: <HQhzf.86040$XJ5.44674@twister.nyroc.rr.com>
Barry Margolin wrote:
> In article <···············@uzeb.lrde.epita.fr>,
>  Didier Verna <······@lrde.epita.fr> wrote:
> 
> 
>>       Hi !
>>
>>I'd like an eval-1 function (a bit like what macroexpand-1 is to macroexpand):
>>a function that takes an expression (possibly also a dynamic environment), and
>>performs one step of evaluation, returning the new partially evaluated
>>expression (and possibly a modified environment) and also indicating where in
>>the evaluation process it currently is (for continuation purpose). Does
>>anybody have this kind of thing at hand ?
> 
> 
> (step <expression>)
> 
At least on every implementation I've used (GCL,clisp,SBCL) step would 
step through the entire evaluation, requiring human interaction at each 
and every step.  What about something that can just return the partially 
evaluated expression and be used in a program?
From: Pascal Bourguignon
Subject: Re: Is there an eval-1 function somewhere ?
Date: 
Message-ID: <87k6cyrwb3.fsf@thalassa.informatimago.com>
Eli Gottlieb <···········@gmail.com> writes:

> Barry Margolin wrote:
>> In article <···············@uzeb.lrde.epita.fr>,
>>  Didier Verna <······@lrde.epita.fr> wrote:
>> 
>>>       Hi !
>>>
>>>I'd like an eval-1 function (a bit like what macroexpand-1 is to macroexpand):
>>>a function that takes an expression (possibly also a dynamic environment), and
>>>performs one step of evaluation, returning the new partially evaluated
>>>expression (and possibly a modified environment) and also indicating where in
>>>the evaluation process it currently is (for continuation purpose). Does
>>>anybody have this kind of thing at hand ?
>> (step <expression>)
>> 
> At least on every implementation I've used (GCL,clisp,SBCL) step would
> step through the entire evaluation, requiring human interaction at
> each and every step.  What about something that can just return the
> partially evaluated expression and be used in a program?

Just take the sources of your favorite Common Lisp implementation, find
the STEP sources and edit them to make an automated step evaluator.


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

ADVISORY: There is an extremely small but nonzero chance that,
through a process known as "tunneling," this product may
spontaneously disappear from its present location and reappear at
any random place in the universe, including your neighbor's
domicile. The manufacturer will not be responsible for any damages
or inconveniences that may result.
From: Eli Gottlieb
Subject: Re: Is there an eval-1 function somewhere ?
Date: 
Message-ID: <qfuzf.88545$XJ5.67362@twister.nyroc.rr.com>
Pascal Bourguignon wrote:
> Eli Gottlieb <···········@gmail.com> writes:
> 
> 
>>Barry Margolin wrote:
>>
>>>In article <···············@uzeb.lrde.epita.fr>,
>>> Didier Verna <······@lrde.epita.fr> wrote:
>>>
>>>
>>>>      Hi !
>>>>
>>>>I'd like an eval-1 function (a bit like what macroexpand-1 is to macroexpand):
>>>>a function that takes an expression (possibly also a dynamic environment), and
>>>>performs one step of evaluation, returning the new partially evaluated
>>>>expression (and possibly a modified environment) and also indicating where in
>>>>the evaluation process it currently is (for continuation purpose). Does
>>>>anybody have this kind of thing at hand ?
>>>
>>>(step <expression>)
>>>
>>
>>At least on every implementation I've used (GCL,clisp,SBCL) step would
>>step through the entire evaluation, requiring human interaction at
>>each and every step.  What about something that can just return the
>>partially evaluated expression and be used in a program?
> 
> 
> Just take the sources of your favorite Common Lisp implementation, find
> the STEP sources and edit them to make an automated step evaluator.
> 
> 
Actually:

(defun and-list (stuff)
   (if (null stuff)
     t
     (and (car stuff) (and-list (cdr stuff)))))
(defun each-atom (stuff)
   (if (atom stuff)
     t
     (and-list (mapcar 'atom stuff))))
(defun eval-1 (expression)
   (cond
     ((each-atom expression) (eval expression))
     (t (mapcar 'eval-1 expression))))

That should evaluate the single deepest level of parens in an expression.
From: Tayssir John Gabbour
Subject: Re: Is there an eval-1 function somewhere ?
Date: 
Message-ID: <1137606174.256157.115850@g47g2000cwa.googlegroups.com>
Eli Gottlieb wrote:
> Pascal Bourguignon wrote:
> > Eli Gottlieb <···········@gmail.com> writes:
> >>At least on every implementation I've used (GCL,clisp,SBCL) step would
> >>step through the entire evaluation, requiring human interaction at
> >>each and every step.  What about something that can just return the
> >>partially evaluated expression and be used in a program?
> >
> > Just take the sources of your favorite Common Lisp implementation, find
> > the STEP sources and edit them to make an automated step evaluator.
> >
> Actually:
>
> (defun and-list (stuff)
>    (if (null stuff)
>      t
>      (and (car stuff) (and-list (cdr stuff)))))
> (defun each-atom (stuff)
>    (if (atom stuff)
>      t
>      (and-list (mapcar 'atom stuff))))
> (defun eval-1 (expression)
>    (cond
>      ((each-atom expression) (eval expression))
>      (t (mapcar 'eval-1 expression))))
>
> That should evaluate the single deepest level of parens in an expression.

Some might be interested in Dirk Gerrits's talk on code walkers...
http://wiki.alu.org/lisp-user-meeting-amsterdam-april-2004

Incidentally, the handy function EVERY looks like a literal replacement
for AND-LIST.


Tayssir
--

"Let's talk about the question of why people are wealthy. There is a
myth that it's a function of enormous personal attributes. [...] The
individual wealth which is generated in this economy is, in my
judgment, and I doubt that there is much that anyone could disagree
with about this, is a function of the innovative businesses which are
created as a result of federal research. But you understand that the
people who benefit from that research get it free. [...] So, if
somebody starts a software company or a biotechnology company, or even
if somebody owns a building in downtown Washington which you rent to
those people, it starts from the same place. It starts from this
incredible research activity which is going on with federal money."

-- Bill Gates Sr., 2003
http://www.taxpolicycenter.org/publications/template.cfm?PubID=900584
From: Eli Gottlieb
Subject: Re: Is there an eval-1 function somewhere ?
Date: 
Message-ID: <ZIvzf.120466$XC4.39736@twister.nyroc.rr.com>
Tayssir John Gabbour wrote:
> Eli Gottlieb wrote:
> 
>>Pascal Bourguignon wrote:
>>
>>>Eli Gottlieb <···········@gmail.com> writes:
>>>
>>>>At least on every implementation I've used (GCL,clisp,SBCL) step would
>>>>step through the entire evaluation, requiring human interaction at
>>>>each and every step.  What about something that can just return the
>>>>partially evaluated expression and be used in a program?
>>>
>>>Just take the sources of your favorite Common Lisp implementation, find
>>>the STEP sources and edit them to make an automated step evaluator.
>>>
>>
>>Actually:
>>
>>(defun and-list (stuff)
>>   (if (null stuff)
>>     t
>>     (and (car stuff) (and-list (cdr stuff)))))
>>(defun each-atom (stuff)
>>   (if (atom stuff)
>>     t
>>     (and-list (mapcar 'atom stuff))))
>>(defun eval-1 (expression)
>>   (cond
>>     ((each-atom expression) (eval expression))
>>     (t (mapcar 'eval-1 expression))))
>>
>>That should evaluate the single deepest level of parens in an expression.
> 
> 
> Some might be interested in Dirk Gerrits's talk on code walkers...
> http://wiki.alu.org/lisp-user-meeting-amsterdam-april-2004
> 
> Incidentally, the handy function EVERY looks like a literal replacement
> for AND-LIST.
> 
> 
> Tayssir
I eventually cut out and-list and redefined each-atom like so:
(defun each-atom (stuff)
   (if (atom stuff)
     t
     (eval `(and ,@(mapcar 'atom stuff)))))
From: Pascal Bourguignon
Subject: Re: Is there an eval-1 function somewhere ?
Date: 
Message-ID: <878xtdqn7u.fsf@thalassa.informatimago.com>
Eli Gottlieb <···········@gmail.com> writes:
> I eventually cut out and-list and redefined each-atom like so:
> (defun each-atom (stuff)
>    (if (atom stuff)
>      t
>      (eval `(and ,@(mapcar 'atom stuff)))))


(defun each-atom (stuff)
   (or (atom stuff)
       (eval `(and ,@(mapcar 'atom stuff)))))
(defun eval-1 (expression)
  (if (each-atom expression)
      (eval expression)
      (mapcar 'eval-1 expression)))


This doesn't work for:

(eval-1 '(let ((x (+ 1 2))) (print (* 2 x))))
--> *** - EVAL: variable LET has no value


You need to do code walking, and to keep an environment!

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
I need a new toy.
Tail of black dog keeps good time.
Pounce! Good dog! Good dog!
From:  (typep 'nil '(satisfies identity)) => ?
Subject: Re: Is there an eval-1 function somewhere ?
Date: 
Message-ID: <1137662759.505779.186740@z14g2000cwz.googlegroups.com>
Excellent Pascal! Thank you,

Christoph
From: Didier Verna
Subject: Re: Is there an eval-1 function somewhere ?
Date: 
Message-ID: <muxd5iivq2l.fsf@uzeb.lrde.epita.fr>
Pascal Bourguignon <····@mouse-potato.com> wrote:

> Just take the sources of your favorite Common Lisp implementation, find the
> STEP sources and edit them to make an automated step evaluator.

        Unfortunately, CMU CL's step function works only on compiled code.
BTW, I've come across a few references on Common Lisp steppers on the
internet. ZStep 95, UnicStep, froglet. Some references are 10 years old. No
source code anywhere, apart from in this message:

; From: ···@waikato.ac.nz (Armadeus)
; Newsgroups: comp.lang.lisp
; Subject: Stepper/Debugger for Common Lisp...
; Message-ID: <······················@waikato.ac.nz>
; Date: 12 Jun 94 11:12:43 +1200
; Organization: University of Waikato, Hamilton, New Zealand
; Lines: 533


which I've not looked at yet. I'm surprised there's so little work available
(or interest ?) on this matter.

-- 
Didier Verna, ······@lrde.epita.fr, http://www.lrde.epita.fr/~didier

EPITA / LRDE, 14-16 rue Voltaire   Tel.+33 (1) 44 08 01 85
94276 Le Kremlin-Bic�tre, France   Fax.+33 (1) 53 14 59 22   ······@xemacs.org
From: Kaz Kylheku
Subject: Re: Is there an eval-1 function somewhere ?
Date: 
Message-ID: <1137607714.614171.215050@g47g2000cwa.googlegroups.com>
Didier Verna wrote:
> Hi !
>
> I'd like an eval-1 function (a bit like what macroexpand-1 is to macroexpand):
> a function that takes an expression (possibly also a dynamic environment), and
> performs one step of evaluation, returning the new partially evaluated

EVAL performs only one step of evaluation. If you want repeated
evaluations, you have to nest or iterate. For instance, if you want to
evaluate an expression three times:

   (eval (eval (eval <expr>)))

Macro-expansion keeps iterating until there is nothing left to expand,
and so macroexpand-1 is needed to just do one level of expansion. There
is no such iteration within EVAL.

Also note that MACROEXPAND performs far from a complete macroexpansion.
It only deals with the main operator of the given expression. If that
isn't a macro operator, nothing happens at all; MACROEXPAND returns the
original expression and the value NIL to indicate that it's not a
macro. Macros in subexpressions are not expanded; to do that you have
to walk the code and do additional calls to MACROEXPAND.

By contrast, EVAL does the complete job of evaluating an expression,
including all necessary macro expansion.

> expression (and possibly a modified environment) and also indicating where in

What is an evaluated expression? What is a partially evaluated
expression?

Evaluation does not work by substituting the results of a subexpression
into the outer expression. It's not a source-to-source transformation.
So for instance (+ 2 2) isn't a partial evaluation of (+ (+ 1 1) (+ 1
1)).
From: Wade Humeniuk
Subject: Re: Is there an eval-1 function somewhere ?
Date: 
Message-ID: <9dyzf.88009$AP5.61830@edtnps84>
Kaz Kylheku wrote:
> 
> What is an evaluated expression? What is a partially evaluated
> expression?
> 
> Evaluation does not work by substituting the results of a subexpression
> into the outer expression. It's not a source-to-source transformation.
> So for instance (+ 2 2) isn't a partial evaluation of (+ (+ 1 1) (+ 1
> 1)).
> 

There is also the problem of

(let ((x 1))
   (+ x (setf x (+ x x))))

The binding for x has to evaluated for every step of the
partial evaluation.  This becomes even hairier if x is
special.

Wade