Re: Porting Ruby snippet to Lisp



Brian Adkins <lojicdotcomNOSPAM@xxxxxxxxx> writes:

19 (when (setf logged-in-user ???)
20 (setf (gethash :user-id (session x)) (id logged-in-user))
21 (redirect-to-original))))))

In this situation some people like anaphoric macros:

(defmacro awhen (test-form &body body)
`(let ((it ,test-form))
(when it ,@body)))

.. . .
19 (awhen <something that computes a logged-in-user>
20 (setf (gethash :user-id (session x)) (id it))
21 (redirect-to-original x))))))
.



Relevant Pages

  • Re: loop ... until ... and then return this
    ... Another good idea is to use anaphoric macros, as described in "On Lisp" by ... (defmacro awhen (test-form &body body) ... The trick of this macro is the variable capturing. ... As Bulent wrote, loop provides something similar with "thereis", but the ...
    (comp.lang.lisp)
  • Re: More questions about exported symbols and general style.
    ... up bindings to captured variables (like IT in anaphoric macros) in ... packages that I'll be using. ... Do I want to just export IT and friends, ... (defmacro foo (list-form &body body) ...
    (comp.lang.lisp)