www.delorie.com/gnu/docs/guile/guile_248.html   search  
 
Buy GNU books!


Guile Reference Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.

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

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

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


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003