This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: another nit.
- To: Han-Wen Nienhuys <hanwen at cs dot uu dot nl>
- Subject: Re: another nit.
- From: Dirk Herrmann <dirk at ida dot ing dot tu-bs dot de>
- Date: Thu, 6 Jul 2000 12:10:00 +0200 (MEST)
- cc: Guile Bug Mailing List <bug-guile at gnu dot org>, Guile Mailing List <guile at sourceware dot cygnus dot com>
On Thu, 6 Jul 2000, Han-Wen Nienhuys wrote:
> why do assq-ref and friends return #f when the key is not found, in
> stead of #<unspecified>? This makes it kind of hard to distinguish
> between an alist not containing KEY and (KEY . #f)
Actually, it would be best to throw an error if the key is not
found. _Any_ object, even #<unspecified> could be the value of a
(KEY . value) pair. You simply shouldn't use assq-ref if you don't know
whether the key exists. That's the reason assq is defined the way it
is: It returns either a pair or #f, no ambiguity.
If you really want to have some short way to get the value of an alist
where you don't know if the key exists, I suggest to write some function
of your own with a dedicated return value which is not eq to anything
else. For example:
(define assq-ref-not-found (cons 'tag 'assq-ref-not-found))
(define (assq-ref-sloppy alist key)
(cond ((assq key alist) => cdr)
(else assq-ref-not-found)))
What do others think? Should assq-ref be changed to throw an error if the
key is not found?
Best regards
Dirk