[r6rs-discuss] [Formal] FIND delivers an ambiguous value
Andre van Tonder
andre at het.brown.edu
Wed Nov 1 14:48:22 EST 2006
On Wed, 1 Nov 2006, Shiro Kawai wrote:
> From: Andre van Tonder <andre at het.brown.edu>
>> This is clearly the right way of doing it. But since then
>> find = memp
>> I would argue for dropping find altogether.
> In my view, 'find' is just a convenience procedure trading
> accuracy (about #f as element). Despite of the problem
> Nils pointed out, I use 'find' a lot more than 'member'-type
> procedures, because most of the time I know what I'm going
> to find is not #f. I think it captures a common use case
> and worth to have it.
But in your use case, don't you normally have to check the
return value anyway? If so, there very little
difference between writing:
(let ((x (memp p list))) ; equivalent to suggested modification
(do-something (car x))
(let ((x (find p list))) ; with existing spec
(do-something-else))) ; fragile
except that the suggested modification is more reliable in case
your data is corrupt (exactly this has been known to happen to me).
Sometimes memp can be more concise. The following is a very common use case:
(cond ((memp p list) => car) ; equivalent to suggested modification
(cond ((find p list) => (lambda (result) result)) ; existing spec
(else 'error)) ; more fragile
The memp convention is the traditional way of encoding "maybe" return values
in Scheme. Find, as currently specified, is in contradiction with this
old convention. So is the optional argument suggestion.
More information about the r6rs-discuss