[anaphora-devel] when-bind if-bind (and friends?)

Nikodemus Siivola nikodemus at random-state.net
Sun Oct 15 10:48:17 UTC 2006


"Attila Lendvai" <attila.lendvai at gmail.com> writes:

> you can have two kind of if-bind, the one in arnesi and the one that covers most of the use-cases is a single var version:
>
> (if-bind var expression
>   then
>   else)
>  
> but one can have an:
>
> (if-let ((var1 expr1)
>           (var2 expr2))
>   then
>   else)
>
> which should expand to nested let's with an if's to keep the semantics of 'and.
>
> but imho this if-let idiom is not needed that often to justify the extra syntax for the single var case and the extra semantic complexity (non-obviousness).

I see your point, but I'd also note that

 (if-let (var expr)
    then
    else)

does not have any risk of confusion while remaining quite short: the
(let (x y z) ..) shorthand does not make sense for if/when-let, and
still allows binding multiple variables.

>From my POV binding macros without the surrounding parens are magical
looking, and something to be regarded with suspicion. Extra sematic
complexity to me means special-cases in comparison to rest of the
language, while clarity and ease of remembering are facilited by
following common patterns: to me it is easier to see (and guess) what

 (if-let (x (gethash y z))
    (frob x))

means, then

 (if-bind x (gethash y z)
    (frob x))

The parens provide a grouping that is visually similar to normal
binding forms, and LET is a dead giveaway. (And I maintain that for
ease of reading (if-let ((x (gethash y z))) ...) is even better:
then you _know_ that X cannot be a function call.)

Whereas in the -bind form there are two "floating forms", and i must
wonder if the form is mis-indented, and the real expansion is maybe
something like

 (if x
     (let ((y (magic)))
       (gethash z y))
     (frob x))

or

 (let ((x (magic)))
   (if x
       (gethash z y)
       (frob x)))

!

Finally, the form with extra parens is even more convenient for
editing, provided one uses paredit or something similar!

(...but IF-BIND will not kill me should everyone else really prefer it)

Cheers,

  -- Nikodemus              Schemer: "Buddha is small, clean, and serious."
                   Lispnik: "Buddha is big, has hairy armpits, and laughs."



More information about the anaphora-devel mailing list