Re: Usecase: chaining operations after "optionals"
Arne Babenhauserheide 10 Jun 2020 10:27 UTC
Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> writes:
> Am Mi., 10. Juni 2020 um 11:16 Uhr schrieb Arne Babenhauserheide <
> xxxxxx@web.de>:
>
>>
>> Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> writes:
>> > Yes, you are right in case `#f' is a valid value in your association
>> list.
>> > If this is the case, you can code it in a data-driven style with SRFI
>> 189:
>> >
>> > (define (assoc-ref key alist)
>> > (maybe-bind (list->maybe (assoc key alist)) cdr))
>> >
>> > It returns either a Nothing or Just the associated value.
>>
>> Can Nothing be part of an alist?
>>
>
> Yes; otherwise we would be in the same situation as with #f to indicate
> failure.
>
> The point is that the `assoc-ref' from above returns a positive result
> wrapped in a Just, which is never a Nothing, but which can, of course, wrap
> a Nothing.
Ah, that’s the list->maybe?
Best wishes,
Arne
--
Unpolitisch sein
heißt politisch sein
ohne es zu merken