Re: Maybe macros Marc Nieper-Wißkirchen 28 Jun 2020 20:24 UTC

Am So., 28. Juni 2020 um 20:52 Uhr schrieb Wolfgang Corcoran-Mathe
<xxxxxx@sigwinch.xyz>:
>
> On 2020-06-28 19:43 +0200, Marc Nieper-Wißkirchen wrote:
> > If the values of the Maybe/Either returned by the empty `...-and' or
> > `...-or' forms are accessed to be processed further, the code is most
> > likely doing something very wrong. Zero values actually help here to
> > catch such logical errors because they will more likely raise an
> > error.
> >
> > [snip]
> >
> > If you want to leave the payload unspecified, you should also leave
> > the number of unspecified values unspecified. That certainly makes
> > sense.
>
> Agreed that the code is certainly doing something wrong.  However,
> the protocol of returning no values in case no meaningful value can be
> returned doesn't seem to be used much in Scheme, as yet.  But we might
> want to allow that to be an option, so I agree--leaving the payload
> completely unspecified is probably the right thing here.

+1

> > The best unit would be a Just/Left/Right for which it would be an
> > error to unwrap it. This could be some singleton value.
>
> I like this, although I suspect that few implementations would bother
> to signal this error; it would be necessary, I think, to add special
> "forbidden" Justs/Lefts/Rights for this purpose, and to check for them
> when unwrapping containers.  That seems a bit messy.

It is enough if the spec included three unique constant
Just/Left/Right values, for which "it is an error" to access their
payload. It is then up to the implementation whether it wants to
signal this error. For the reference/sample implementation,

(define the-just (just))

would be enough. It wouldn't signal an error, though.