Re: Lisp's QUOTE and Mathematica's "Hold"
- From: Peter Seibel <peter@xxxxxxxxxxxxxxx>
- Date: Sun, 21 Aug 2005 03:55:31 GMT
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/
.
- Follow-Ups:
- Re: Lisp's QUOTE and Mathematica's "Hold"
- From: Jon Harrop
- 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
- Very poor Lisp performance
- Prev by Date: Re: Lisp's QUOTE and Mathematica's "Hold"
- Next by Date: Re: Lisp semantics vs. Mathematica semantics
- 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
|