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



Peter Seibel wrote:
> Jon Harrop <usenet@xxxxxxxxxxxxxx> writes:
>> You can see Hold in Mathematica but not QUOTE in Lisp but isn't that more
>> a function of the pretty printer rather than the evaluation?
>
> No. At least in Lisp case, the QUOTE form was evaluated and it
> evaluated to the quoted expression. The pretty printer has no way of
> knowing whether a form came from a QUOTE expression or was constructed
> in some other way:
>
> '(+ 1 2) ==> (+ 1 2)

Right, but Hold[1+2] is Mathematica's equivalent of the quoted expression,
i.e. an expression held in unevaluated form.

> where ==> means "evaluates to". But so does:
>
> (list '+ 1 2) ==> (+ 1 2)
>
> and also:
>
> (cons '+ (cons 1 (cons 2 nil))) ==> (+ 1 2)

In Mathematica:

In[20]:= Hold[{1, 2}] /. {List -> Plus}

Out[20]= Hold[1 + 2]

The latter "quoted" expression is indistinguishable from the
directly-created one, just like the Lisp.

> Given any of those (+ 1 2) lists, you can't tell how it was
> produced. And if you then evaluate the list you get 3:
>
> (eval '(+ 1 2)) ==> 3
> (eval (list '+ 1 2)) ==> 3
> (eval (cons '+ (cons 1 (cons 2 nil)))) ==> 3

Yes, this is also the same:

In[21]:= Release[Hold[1 + 2]]

Out[21]= 3

In[22]:= Release[Hold[{1, 2}] /. {List -> Plus}]

Out[22]= 3

As Nathan Baum just explained, you can tell between different instantiations
of the same quoted expression in Lisp, whereas you cannot in Mathematica.

> By contrast (at least according to what others have said in this
> thread), in Mathematica Hold "evaluates" to something that carries
> it's "heldness" with it until someone explicitly Releases it. Thus you
> have:
>
> Hold[whatever] ==> Hold[whatever]
>
> and assuming for the sake of argument there is an EVAL that does the
> same thing as implied by the ==> above:
>
> EVAL[Hold[whatever]] ==> Hold[whatever]

Yes, I think its "Evaluate" rather than EVAL. In Mathematica,
Hold[Evaluate[expr]] evaluates expr and then holds it, IIRC.

> while
>
> Release[Hold[whatever]] ==> whatever
>
> but Release (again, as I understand it) is not a general purpose
> evaluator--all it does is strip off a level of heldness (or maybe all
> levels of heldness?)

Exactly (the former). This is where the similarity begins to breakdown.
However, despite the difference in method of evaluation, the results are
the same.

> Of course I could be all wrong about Mathematica
> having never used it; I'm just going by the other descriptions in this
> thread.

I think you've got the right idea. Mathematica then repeatedly evaluates the
resulting expression until it stops changing. This might seem like a
massive departure from other languages, including Lisp, but actually it is
virtually the same thing.

In Mathematica, if the resulting expression is an integer then it won't
change so evaluation stops.

If the resulting expression is a call to a recursive function then that
function will be invoked and the repeated evaluation by Mathematica simply
corresponds to the recursive function calls in most other languages.

So, term-level interpreters for Mathematica and Lisp are very similar.

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



Relevant Pages

  • Re: Lisps QUOTE and Mathematicas "Hold"
    ... So all Mathematica equivalents must be quoted at least ... So cannot be a Lisp equivalent of anything in Mathematica, ... >> not trying to say that the subsequent evaluation of the enclosing ... to implement Mathematica's capabilities in Lisp, i.e. using s-exprs. ...
    (comp.lang.lisp)
  • Fundamentals of the Mathematica Programming Language note set by Richard J. Gaylord available
    ... to give you a flavor of what i am trying to emphasize in the note set, ... Mathematica Programming Fundamentals: ... When the lhs of a rewrite ... Evaluation then proceeds by searching for further matching ...
    (sci.math.symbolic)
  • Re: Lisps QUOTE and Mathematicas "Hold"
    ... anyone writing lisp programs on any topic. ... structure" is legitimate, that is not how list structure needs to be created. ... All of JH's maunderings about macros and how that is what mathematica does, and therefore that is how lisp does something, is basically wrong. ... (quote (+ a b c)) ...
    (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)