Hacker News new | past | comments | ask | show | jobs | submit login

  (defun move-ball (ball distance screen-width)
    (zapf (ball-x ball)
          (mod (+ distance %) screen-width)))
In TXR Lisp:

    (defun move-ball (ball distance screen-width)
      (placelet ((it (ball-x ball)))
         (set it (mod (+ distance it) screen-width)))
Trivial exercise: zapf macro expanding to the placelet form.

TXR Lisp's anaphoric operators like ifa and conda use placelet, so that their "it" can be a place referring to the original:

   ;; decrement (ball-x ball) place if it exceeds 15:

   (ifa (> (ball-x ball) 15)
     (dec it))



By the way, placelet isn't macrolet. In the above, the (ball-x ball) place form is evaluated once to determine the place which becomes aliased by the it symbol. The two occurrences of it in the (set it ...) form do not cause multiple evaluation of (ball-x ball).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: