1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
<RefEntry id="assoc">
<!-- This file is generated automatically from the DSSSL source. -->
<!-- Do not edit this file! -->
<?html-filename assoc.html>
<RefMeta>
<RefEntryTitle>assoc</RefEntryTitle>
<RefMiscInfo Role="file">dblib.dsl</RefMiscInfo>
</RefMeta>
<RefNameDiv>
<RefName>assoc</RefName>
<RefPurpose>Returns the association of an object in an associative list</RefPurpose>
</RefNameDiv>
<RefSynopsisDiv><Title>Synopsis</Title>
<Synopsis>
(assoc obj alist)
</Synopsis>
</RefSynopsisDiv>
<RefSect1><Title>Description</Title>
<para>
Given an associative list, returns the pair that has <literal>obj</literal> as a <literal>car</literal>
or <literal>#f</literal> if no such pair exists.
</para>
<variablelist>
<varlistentry><term>obj</term>
<listitem>
<para>
The associative key to locate.
</para>
</listitem>
</varlistentry>
<varlistentry><term>alist</term>
<listitem>
<para>
The associative list.
</para>
</listitem>
</varlistentry>
</variablelist>
</RefSect1>
<RefSect1><Title>Example</Title>
<para>
<literal>(assoc "a" (("a" "b") ("c" "d")))</literal> returns <literal>("a" "b")</literal>
</para>
</RefSect1>
<RefSect1><Title>Author</Title>
<para>
Norman Walsh, <ndw@nwalsh.com>
</para>
</RefSect1>
<RefSect1><Title>Source Code</Title>
<ProgramListing>
(define (assoc obj alist)
;; Returns the association of an object in an associative list
(let loop ((al alist))
(if (null? al)
#f
(if (equal? obj (car (car al)))
(car al)
(loop (cdr al))))))
</ProgramListing>
</RefSect1>
</RefEntry>
|