Re: Idiom to fetch key and datum
taylanbayirli@xxxxxx 07 Sep 2015 19:40 UTC
John Cowan <xxxxxx@mercury.ccil.org> writes:
> (ephemeron-if <eph-expr>
> ((<key-id> <value-id>) <expr> ...)
> (else <expr> ...))
(ephemeron-if ephemeron
((key datum)
... normal code ...)
(else
... exceptional code ...))
is 5 lines of code, using a newly invented syntax form, and pushes the
exceptional code (which I guess would usually be short) to the end.
(let-values (((broken? key datum)
(ephemeron-ref ephemeron)))
(if broken?
... exceptional code ...
... normal code ...))
is also 5 lines (4 if you have 60 columns to spare), doesn't use any
unfamiliar syntax, and has the exceptional code come first like it is
also the case in e.g. 'guard'.
Syntax should generally be added sparingly. In this case I would go as
far as saying it has negative utility.
I actually considered something to the effect of
(let-ephemeron ephemeron broken? key datum
(if broken? ... ...))
but the difference is so small, it's just not worth it.
With my conservative hat on today,
Taylan