[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comments on SRFI-1.

This page is part of the web mail archives of SRFI 1 from before July 7th, 2015. The new archives for SRFI 1 contain all messages, not just those from before July 7th, 2015.

Harvey J. Stein wrote:

> Maybe better than list-length>= would be (list-ref-with-default l n
> default-value), which returns default-vaule if (>= (length l) n).  

That doesn't mean the programmer will know what value to provide --
indeed, this increases the possibility of error.  To be safe, in the
worst case, he would have to scan the entire list to make sure the
default-value isn't in it (remember, Scheme doesn't have a generative
struct mechanism either), or tack a token onto every value already in
the list.  Clearly, neither of these is viable.

The way to avoid this sort of misery is to pass in "continuations"
(ie, procedures that are invoked in tail position).  Your procedure
would take two continuations, for success (if the list is long enough,
feed the remainder to this) and failure (the list isn't long enough;
maybe an argument saying how long it actually was?).  This scans the
list once, avoids default-values, doesn't leak computation, and is
elegant in the Schemish way: it uses two powerful things that Scheme
already has (closures and tail-calls) to work around what it doesn't
have (exceptions).


PS: Since I'm on srfi-1, please remove my name from the distribution.
    I see you and Olin are on it, too.