Node:Sloppy Alist Functions, Next:, Previous:Removing Alist Entries, Up:Association Lists



22.7.2.5 Sloppy Alist Functions

sloppy-assq, sloppy-assv and sloppy-assoc behave like the corresponding non-sloppy- procedures, except that they return #f when the specified association list is not well-formed, where the non-sloppy- versions would signal an error.

Specifically, there are two conditions for which the non-sloppy- procedures signal an error, which the sloppy- procedures handle instead by returning #f. Firstly, if the specified alist as a whole is not a proper list:

(assoc "mary" '((1 . 2) ("key" . "door") . "open sesame"))
=>
ERROR: In procedure assoc in expression (assoc "mary" (quote #)):
ERROR: Wrong type argument in position 2 (expecting NULLP): "open sesame"
ABORT: (wrong-type-arg)

(sloppy-assoc "mary" '((1 . 2) ("key" . "door") . "open sesame"))
=>
#f

Secondly, if one of the entries in the specified alist is not a pair:

(assoc 2 '((1 . 1) 2 (3 . 9)))
=>
ERROR: In procedure assoc in expression (assoc 2 (quote #)):
ERROR: Wrong type argument in position 2 (expecting CONSP): 2
ABORT: (wrong-type-arg)

(sloppy-assoc 2 '((1 . 1) 2 (3 . 9)))
=>
#f

Unless you are explicitly working with badly formed association lists, it is much safer to use the non-sloppy- procedures, because they help to highlight coding and data errors that the sloppy- versions would silently cover up.

sloppy-assq key alist Scheme Procedure
scm_sloppy_assq (key, alist) C Function
Behaves like assq but does not do any error checking. Recommended only for use in Guile internals.

sloppy-assv key alist Scheme Procedure
scm_sloppy_assv (key, alist) C Function
Behaves like assv but does not do any error checking. Recommended only for use in Guile internals.

sloppy-assoc key alist Scheme Procedure
scm_sloppy_assoc (key, alist) C Function
Behaves like assoc but does not do any error checking. Recommended only for use in Guile internals.