Arc Forumnew | comments | leaders | submitlogin
A question about the tutorial
1 point by comatose_kid 6176 days ago | 1 comment
This may be obvious to experienced Lispers, but the tutorial states that the = operator's "...first argument isn't evaluated".

However, later on in the tutorial I see that the result of (= (car x) 'z) sets x to (z b) (initially, x was (a b). Was the first argument to = evaluated here?



1 point by cje 6176 days ago | link

Not exactly, no. The first argument isn't evaluated, but "=" looks at it to let you do convenient things like that.

In fact, "=" is actually a fancy macro, which transforms (= (car x) 'z) into (scar x 'z), where "scar" is the set-car function.

For example:

  arc> (= x '(a b c))
  (a b c)
  arc> (= (car x) 'new)
  new
  arc> x
  (new b c)
The fancy bit here is that only the "outermost" form of the first argument is specially processed:

  arc> (= (car (cdr x)) 'second)
  second
  arc> x
  (new second c)
  arc> (= (car (cdr (cdr x))) 'third)
  third
  arc> x
  (new second third)
These last two examples would expand to

  (scar (cdr x) 'second)
and

  (scar (cdr (cdr x)) 'third))
Common Lisp does essentially the same thing with "setf".

-----