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



Jon Harrop <usenet@xxxxxxxxxxxxxx> writes:

> Brian Downing wrote:
>> In article <43062cf8$0$22943$ed2619ec@xxxxxxxxxxxxxxxxxxxxxxxxxx>,
>> Jon Harrop <usenet@xxxxxxxxxxxxxx> wrote:
>>> Right. I think that's exactly the same as "Hold" in Mathematica.
>>
>> Not really.
>
> Both QUOTE and Hold retain subexpressions in unevaluated form. Perhaps the
> similarity ends there...
>
>> (defparameter *test* (quote (+ 2 2))) ==> *TEST* contains (+ 2 2).
>>
>> test = Hold[2 + 2] ==> test contains Hold[2 + 2]
>>
>> i.e., Hold "sticks" with the expression, whereas QUOTE is just a signal
>> to the evaluator to pass its contents through unevaluated. You can't
>> build something as simple as QUOTE in Mathematica because the evaluator
>> will keep evaluating until it stops changing - the CL QUOTE would be a
>> noop in the Mathematica evaluator.
>
> 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)

where ==> means "evaluates to". But so does:

(list '+ 1 2) ==> (+ 1 2)

and also:

(cons '+ (cons 1 (cons 2 nil))) ==> (+ 1 2)

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

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]

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?) Of course I could be all wrong about Mathematica
having never used it; I'm just going by the other descriptions in this
thread.

-Peter

--
Peter Seibel * peter@xxxxxxxxxxxxxxx
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp * http://www.gigamonkeys.com/book/
.



Relevant Pages

  • Re: Very poor Lisp performance
    ... I think that's exactly the same as "Hold" in Mathematica. ... i.e., Hold "sticks" with the expression, whereas QUOTE is just a signal ... to the evaluator to pass its contents through unevaluated. ... Prev by Date: ...
    (comp.lang.lisp)
  • Re: Lisps QUOTE and Mathematicas "Hold"
    ... > Both QUOTE and Hold retain subexpressions in unevaluated form. ... >> to the evaluator to pass its contents through unevaluated. ... >> noop in the Mathematica evaluator. ...
    (comp.lang.lisp)
  • Re: Lisp Beginner question
    ... >> because QUOTE works on lists as well as atoms. ... Using ' as an abbreviation for QUOTE ... A question I kept asking myself for the first few dozen hours of my lisp ... experience was "How does the evaluator know when to stop evaluating?" ...
    (comp.lang.lisp)
  • Re: Lisps QUOTE and Mathematicas "Hold"
    ... Both QUOTE and Hold retain subexpressions in unevaluated form. ... > to the evaluator to pass its contents through unevaluated. ... > noop in the Mathematica evaluator. ...
    (comp.lang.lisp)
  • Re: Lisps QUOTE and Mathematicas "Hold"
    ... Jon Harrop wrote: to the evaluator to pass its contents through unevaluated. ... You can't build something as simple as QUOTE in Mathematica because the evaluator will keep evaluating until it stops changing - the CL QUOTE would be a noop in the Mathematica evaluator. ...
    (comp.lang.lisp)