chickadee » callable-data-structures » make-callable-alist

make-callable-alist #!optional (alist '()) #!key (test eqv?)procedure

Return a callable alist object. The initial alist is optional if the test keyword parameter is not given.

The test keyword parameter specifies the key comparison procedure (default: eqv?).

Besides the alist key, the callable alist object accepts the default keyword parameter, which specifies the default value for when the given key doesn't exist (default: #f).

Examples:

#;1> (use callable-alists)
#;2> (define symbols (make-callable-alist))
#;3> symbols
#<procedure callable-alist>
#;4> (symbols)
()
#;5> (set! (symbols 'foo) 42)
#;6> (symbols 'foo)
42
#;7> (symbols)
((foo . 42))
#;8> (define strings (make-callable-alist '() test: equal?))
#;9> strings
#<procedure callable-alist>
#;10> (strings)
()
#;11> (set! (strings "foo") 42)
#;12> (strings "foo")
42
#;13> (strings)
(("foo" . 42))