Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

They are basically the same macros, but without the use of bindings (more brevity).

So if-let and when-let are not really anaphoric.

In Common Lisp, I use b-when and b-if that Kenny Tilton wrote:

  (defmacro b-when (bindvar boundform &body body)
    `(let ((,bindvar ,boundform))
       (when ,bindvar
         ,@body)))

  (defmacro b-if (bindvar boundform yup &optional nope)
    `(let ((,bindvar ,boundform))
       (if ,bindvar
           ,yup
         ,nope)))

Usage:

  (b-when foo (plusp 1)
	(frob foo))


I find your lack of parentheses disturbing. I'd personally prefer:

  (b-when foo (plusp 1)
    (frob foo))
These implementations also don't handle declarations correctly ;P A surprisingly tricky topic.


Hmm, did you mean...

  (bwhen (foo (plusp 1))
      (frob foo))
bwhen is actually the first version of the macro, heh. It does seem a bit more idiomatic with parens, but I've gotten used to the other.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

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

Search: