Re: Lisp's QUOTE and Mathematica's "Hold"
- From: Jon Harrop <usenet@xxxxxxxxxxxxxx>
- Date: Sun, 21 Aug 2005 12:17:22 +0100
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
.
- Follow-Ups:
- Re: Lisp's QUOTE and Mathematica's "Hold"
- From: Nathan Baum
- Re: Lisp's QUOTE and Mathematica's "Hold"
- References:
- Very poor Lisp performance
- From: Jon Harrop
- Re: Very poor Lisp performance
- From: Jon Harrop
- Re: Very poor Lisp performance
- From: Ulrich Hobelmann
- Re: Very poor Lisp performance
- From: Jon Harrop
- Re: Very poor Lisp performance
- From: Brian Downing
- Re: Lisp's QUOTE and Mathematica's "Hold"
- From: Jon Harrop
- Re: Lisp's QUOTE and Mathematica's "Hold"
- From: Nathan Baum
- Re: Lisp's QUOTE and Mathematica's "Hold"
- From: Jon Harrop
- Re: Lisp's QUOTE and Mathematica's "Hold"
- From: Nathan Baum
- Re: Lisp's QUOTE and Mathematica's "Hold"
- From: Jon Harrop
- Re: Lisp's QUOTE and Mathematica's "Hold"
- From: Nathan Baum
- Re: Lisp's QUOTE and Mathematica's "Hold"
- From: Jon Harrop
- Re: Lisp's QUOTE and Mathematica's "Hold"
- From: Nathan Baum
- Very poor Lisp performance
- Prev by Date: Re: Very poor Lisp performance
- Next by Date: Re: ADA and my own business
- Previous by thread: Re: Lisp's QUOTE and Mathematica's "Hold"
- Next by thread: Re: Lisp's QUOTE and Mathematica's "Hold"
- Index(es):
Relevant Pages
|