Am So., 14. Juni 2020 um 20:53 Uhr schrieb John Cowan <>:

On Sun, Jun 14, 2020 at 12:08 PM Marc Nieper-Wißkirchen <> wrote:

This is really a completely different protocol.  I have called it the "multitruth" protocol, but a better name is needed. 

What about `maybe->list*' instead?

It's really "list-or-false" protocol, but that is just too long.

In particular because it is probably the more useful protocol than `maybe->list'. (And no one would come up with a name like `string->number-or-false'.

What do you think of the names

`just->list' and `right->list' instead? If given a Nothing or a Left, they will return #f as a special case. It is an error to call them on any other value.


The `assume' is only for clarity; you can remove it without changing
the semantics. The point is that `stop?' has to be called n + 1 times
according to the `unfold' protocol when you generate something of
length n.

That makes sense only if `successor` is being called for its side effects only.

Indeed. The same goes for `stop?'. If you want to implement the `unfold' protocol, you have to include this as well.  Otherwise, we better drop the unfold altogether.

We do make the initial call on stop?, which is the first thing the unfold protocol does, so stop? must be present; it determines whether we get a Just/Right if stop? returns #t or a Nothing/Left if stop? returns #f.

Successor is used to go from the current seeds to the seeds for the next iteration, but as there never can be another iteration, there is no need to call it.

In the unfold protocol, `successor' is called exactly N times when a list-like object of length N is constructed.  While this does not matter for Haskell, it does matter for Scheme, which is not a pure language.

If you don't call `successor' when a Maybe is constructed, you don't follow the protocol.

And there is no reason to include `maybe-unfold' if you don't want to follow the protocol.

Consider the following:

(generator-unfold GEN UNFOLD)

This should exhaust GEN and return a stream-like object (constructed by UNFOLD) of the same length.  Note that the `successor' argument to UNFOLD has a side effect.

With the correct specification and implementation of `maybe-unfold' according to the protocol, a Scheme implementation can raise an error if

(generator-unfold GEN maybe-unfold)

is called on a generator of length 2 or more.

This is just another case where coherence and regularity matter even in the details.