Re: Maybe macros Wolfgang Corcoran-Mathe 27 Jun 2020 14:09 UTC

I also suggest the addition of the follow Either macros, with
semantics analogous to those of the Maybe macros:

* (either-and either-expr ...)
* (either-or either-expr ...)
* (either-let* (claw ...) body)

It might be objected that the either-and/-or forms make less sense
than their Maybe counterparts, since the latter are, in a sense,
translations of Scheme and/or to the "Maybe protocol".  These macros
are not merely logical operations, though; they have a control role
similar to that of SRFI 165's computation-each (and Haskell's >>
or sequence_).

This SRFI lacks maybe-/either-each and -each-in-list procedures
analogous to those of SRFI 165, and the reason for this seems clear
to me; as Scheme *procedures*, they aren't very useful.  Following
165, the expression

    (maybe-each-in-list maybes)

would simply return Nothing if one occurred among the maybes, and
the value of the last element of maybes otherwise.  This is just
list-searching,[*] and is roughly equivalent to

    (truth->maybe (every just? maybes)).

While this isn't very useful, I believe there are many cases in
which we would like to sequentially evaluate Maybe/Either-valued
*expressions* until we hit Nothing/a Left.  The Schemely solution
is to provide the -and, -or, and -let* macros for both Maybe and
Either.

Regards,

Wolfgang

[*] Incidentally, either-each seems more useful; no similar one-liner
comes to mind for getting the first Left and otherwise the last
Right of a list of Eithers.

--
Wolfgang Corcoran-Mathe  <xxxxxx@sigwinch.xyz>

"If one is searching for a needle in a haystack, look in the part
of the haystack that contains more needles." --Bird & Wadler