[alexandria-devel] [PATCH] PROG1-LET

Nikodemus Siivola nikodemus at random-state.net
Tue Apr 10 07:13:33 UTC 2012


On 9 April 2012 00:05, Benjamin Saunders <ralith at gmail.com> wrote:

>> and it adds quite some complexity when reading the code.
>
> This is indeed subjective. I find it to be clearer to read than the
> alternatives, but perhaps that's just me? Anaphora would seem to be

WHEN-LET and IF-LET have a fairly common use-case:

  (when-let ((x (gethash key table)))
    (bar x))

compared to

  (let ((x (gethash key table)))
    (when x
      (bar x)))

where in a typical case the /relative/ reduction in lines of code is a
substantial 33% -- and they are also "classic": been around forever,
re-invented independently by several people. For the single-binding
case there is also little chance of "guessing wrong" what it actually
does.

In case of PROG1-LET, I actually assumed

  (prog1-let ((x (foo)))
      (bar x)
     (quux x))

would have been equivalent to

  (let ((x (foo)))
    (prog1
        (bar x)
      (quux x)))

and the possibility it might mean

  (let ((x (foo)))
    (prog1
        x
      (bar)
      (quux)))

didn't even register -- in particular because I would write that as
just a LET, without using PROG1 at all:

  (let ((x (foo)))
    (bar x)
    (quux x)
    x)

-- or better yet, when possible make QUUX return X so the return value
would be implicit:

  (let ((x (foo)))
    (bar x)
    (quux-and-return x))

at which point we're back at the same line count as PROG1-LET, and
have easier to read code.

A "bind values, do stuff, return the bindings" -macro similar
PROG1-LET would IMO fit fine in Alexandria, but PROG1-LET is not a
good name for it. I also suspect it only gains true utility if it
returns multiple values, but then we're back at looking for
use-cases...

Cheers,

 -- Nikodemus




More information about the alexandria-devel mailing list