[r6rs-discuss] [Formal] FIND delivers an ambiguous value
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
(if x
(do-something (car x))
(do-something-else)))
and
(let ((x (find p list))) ; with existing spec
(if x
(do-something x)
(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
(else 'error))
(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.
Andre
Received on Wed Nov 01 2006 - 14:48:22 UTC
This archive was generated by hypermail 2.3.0
: Wed Oct 23 2024 - 09:15:00 UTC