Re: Lisp's QUOTE and Mathematica's "Hold"



Nathan Baum wrote:
> Jon Harrop wrote:
>> I think this is an important point: all Mathematica values are equivalent
>> to Lisp s-exprs. So all Mathematica equivalents must be quoted at least
>> once. So (X) cannot be a Lisp equivalent of anything in Mathematica,
>> AFAIK.
>
> Not all. Literals are, by definition, self-evaluating. ``3'' is the same
> thing in Lisp and Mathematica, and 3 and '3 will evaluate to the same
> thing. 3 and ''3 won't, however.
>
> Are 3 and Hold[3] the same thing.

Given that "a" and "Hold[a]" are not the same thing then I'd say "expr" and
"Hold[expr]" were not the same thing in general, so no.

>> I'm just comparing the effect of eval on QUOTE and Release on Hold. I'm
>> not trying to say that the subsequent evaluation of the enclosing
>> expression works in the same way.
>
> Perhaps in terms of the relationship between EVAL and ReleaseHold they
> are similar.

Yes, that's all I meant.

> The two do, of course, do quite different things, and it is only when
> used with QUOTE in this limited way that EVAL/QUOTE behaves like
> ReleaseHold/Hold.

Yes. It caught my eye because it seems like a remarkably straightforward way
to implement Mathematica's capabilities in Lisp, i.e. using s-exprs.

> EVAL evaluates its argument, whilst ReleaseHold simply makes its
> argument available for evaluation and then Mathematica's normal
> evaluator causes it to be evaluated.

Yes. From the point of view of the user, there isn't much difference.

> If Lisp had Mathematica's evaluation semantics, EVAL/QUOTE would be
> quite unlike ReleaseHold/Hold: it would be like Peter Seibel's
> implementation of RELEASE and HOLD.

Ok.

> In my view, it is flawed to say that EVAL and ReleaseHold serve similar
> purposes just because the semantics of the language mean that they can
> appear in similar expressions which evaluate to the same thing.
>
> Yes,
>
> ReleaseHold[Hold[3 + 3]] ==> 3, and
> (EVAL (QUOTE (+ 3 3)) ==> 3
>
> but
>
> ReleaseHold[Hold[A + B]] ==> A + B, whilst
> (EVAL (QUOTE (+ A B)) ==> Error
>
> and also
>
> Hold[3] ==> Hold[3], whilst
> (QUOTE 3) ==> 3
>
> and of course
>
> ReleaseHold[X] ==> X, whilst
> (EVAL X) ==> Error
>
> additionally,
>
> ReleaseHold[{2, Hold[1 + 1]}] ==> {2, 2}, whilst
> (EVAL (VECTOR 2 (QUOTE (+ 1 1)))) ==> #(2 (+ 1 1))

But these examples are again missing one level of quotation in Lisp. You're
trying to replace Mathematica's evaluator with Lisp's evaluator. Try
keeping everything quoted instead, and forget about the subsequent
evaluation not working.

The second example should be:

Release[Hold[a+b]] ==> a+b
eval ''(+ a b) ==> (+ a b)

So the first example should be:

Release[Hold[3+3]] ==> 3+3 ( ==> 6)
eval ''(+ 3 3) ==> (+ 3 3)

As Mathematica's built-in rules are not the same as Lisp's, we should not
let the Lisp evaluator evaluate anything for us. You are quite right that
Lisp's evaluator works for (+ 3 3) but it should also work for '(+ 3 a 3),
to give '(+ 6 a), for example.

With the equivalence that I'm proposing you would then have:

3 ==> 3
'3 ==> 3

Hold[3] ==> Hold[3]
''3 ==> '3

Release[Hold[X]] ==> X
(eval ''x) ==> X

Release[Hold[{2, Hold[1+1]}]] ==> {2, Hold[1+1]}
(eval '`,(list 2 '(+ 1 1))) ==> (2 (+ 1 1))

However, the following doesn't work because eval applies to the root of the
s-expr whereas Release recursively searches for the equivalent of a second
level of quotation that can be removed:

Release[2 + Hold[3 + 4]] ==> 2 + 3 + 4 ( ==> 9)
(eval '(+ 2 '(+ 3 4))) ==> Argument Y is not a NUMBER: (+ 3 4).

So a better equivalent to Release would remove the second level of quotation
leaving the first intact. Perhaps we should be mapping eval over the given
s-expr, rather than applying it directly...

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com
.



Relevant Pages

  • Re: Lisps QUOTE and Mathematicas "Hold"
    ... >> You can see Hold in Mathematica but not QUOTE in Lisp but isn't that more ... At least in Lisp case, the QUOTE form was evaluated and it ... However, despite the difference in method of evaluation, the results are ...
    (comp.lang.lisp)
  • Re: Lisp and Scheme with fewer parentheses / Mathematica??
    ... Try to get out of lisp mindset, and view things from general humanity. ... whether, is it reasonable, to say that programing in mathematica is ... Lisp has a 'simpler' and more straight forward model evaluation model. ... is more to be a straight-forward implementation language ...
    (comp.lang.lisp)
  • Re: Lisps QUOTE and Mathematicas "Hold"
    ... If Lisp was virtually the same as Mathematica, programs could only be written to use ... and would therefore be evaluated to produce, which is not a self-evaluating form and would therefore be evaluated to produce 3, which is a self-evaluating form and would therefore not be evaluated because further evaluation would have no effect. ... Presumably, a Lisp which used Mathematica-style evaluation would want to be a Lisp-1, so this kind of problem could not occur. ...
    (comp.lang.lisp)
  • Re: Lisp syntax vs. Mathematica syntax
    ... That is, in an ordinary lisp, ... If you want to quote x in Mathematica, ... of quote, evaluation, etc. because there are many items ... macro that reduces expressions like "3+10". ...
    (comp.lang.lisp)
  • Re: why do you choose LISP?
    ... i like lisp primarily bceause it is a functional lang. ... It is also during the early 1990s, i started to learn programing on my ... during these years i bought Mathematica (because i heard it's the ... I do not have any concrete idea what IS a language specification ...
    (comp.lang.lisp)