1 /*
2  * ListProcedures.h - list utilities
3  *
4  *   Copyright (c) 2008  Higepon(Taro Minowa)  <higepon@users.sourceforge.jp>
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *   1. Redistributions of source code must retain the above copyright
11  *      notice, this list of conditions and the following disclaimer.
12  *
13  *   2. Redistributions in binary form must reproduce the above copyright
14  *      notice, this list of conditions and the following disclaimer in the
15  *      documentation and/or other materials provided with the distribution.
16  *
17  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23  *   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  *   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  *   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  *  $Id: ListProcedures.h 261 2008-07-25 06:16:44Z higepon $
30  */
31 
32 #ifndef SCHEME_LIST_PROCEDURES_
33 #define SCHEME_LIST_PROCEDURES_
34 
35 #include "scheme.h"
36 
37 namespace scheme {
38     Object setAnnotationDEx(VM* theVM, int argc, const Object* argv);
39     Object getAnnotationEx(VM* theVM, int argc, const Object* argv);
40     Object annotatedPairPEx(VM* theVM, int argc, const Object* argv);
41     Object annotatedConsEx(VM* theVM, int argc, const Object* argv);
42     Object listEx(VM* theVM, int argc, const Object* argv);
43     Object listTransposeAddEx(VM* theVM, int argc, const Object* argv);
44     Object caaaarEx(VM* theVM, int argc, const Object* argv);
45     Object caaadrEx(VM* theVM, int argc, const Object* argv);
46     Object caaarEx(VM* theVM, int argc, const Object* argv);
47     Object caadarEx(VM* theVM, int argc, const Object* argv);
48     Object caaddrEx(VM* theVM, int argc, const Object* argv);
49     Object caadrEx(VM* theVM, int argc, const Object* argv);
50     Object caarEx(VM* theVM, int argc, const Object* argv);
51     Object cadaarEx(VM* theVM, int argc, const Object* argv);
52     Object cadadrEx(VM* theVM, int argc, const Object* argv);
53     Object cadarEx(VM* theVM, int argc, const Object* argv);
54     Object caddarEx(VM* theVM, int argc, const Object* argv);
55     Object cadddrEx(VM* theVM, int argc, const Object* argv);
56     Object caddrEx(VM* theVM, int argc, const Object* argv);
57     Object cadrEx(VM* theVM, int argc, const Object* argv);
58     Object cdaaarEx(VM* theVM, int argc, const Object* argv);
59     Object cdaadrEx(VM* theVM, int argc, const Object* argv);
60     Object cdaarEx(VM* theVM, int argc, const Object* argv);
61     Object cdadarEx(VM* theVM, int argc, const Object* argv);
62     Object cdaddrEx(VM* theVM, int argc, const Object* argv);
63     Object cdadrEx(VM* theVM, int argc, const Object* argv);
64     Object cdarEx(VM* theVM, int argc, const Object* argv);
65     Object cddaarEx(VM* theVM, int argc, const Object* argv);
66     Object cddadrEx(VM* theVM, int argc, const Object* argv);
67     Object cddarEx(VM* theVM, int argc, const Object* argv);
68     Object cdddarEx(VM* theVM, int argc, const Object* argv);
69     Object cddddrEx(VM* theVM, int argc, const Object* argv);
70     Object cdddrEx(VM* theVM, int argc, const Object* argv);
71     Object cddrEx(VM* theVM, int argc, const Object* argv);
72     Object listRefEx(VM* theVM, int argc, const Object* argv);
73     Object listTailEx(VM* theVM, int argc, const Object* argv);
74     Object consEx(VM* theVM, int argc, const Object* argv);
75     Object carEx(VM* theVM, int argc, const Object* argv);
76     Object cdrEx(VM* theVM, int argc, const Object* argv);
77     Object consMulEx(VM* theVM, int argc, const Object* argv);
78     Object setSourceInfoDEx(VM* theVM, int argc, const Object* argv);
79     Object sourceInfoEx(VM* theVM, int argc, const Object* argv);
80     Object nullPEx(VM* theVM, int argc, const Object* argv);
81     Object setCarDEx(VM* theVM, int argc, const Object* argv);
82     Object setCdrDEx(VM* theVM, int argc, const Object* argv);
83     Object reverseEx(VM* theVM, int argc, const Object* argv);
84     Object listPEx(VM* theVM, int argc, const Object* argv);
85     Object memqEx(VM* theVM, int argc, const Object* argv);
86     Object memvEx(VM* theVM, int argc, const Object* argv);
87     Object memberEx(VM* theVM, int argc, const Object* argv);
88     Object assqEx(VM* theVM, int argc, const Object* argv);
89     Object assocEx(VM* theVM, int argc, const Object* argv);
90     Object assvEx(VM* theVM, int argc, const Object* argv);
91     Object appendEx(VM* theVM, int argc, const Object* argv);
92     Object append2Ex(VM* theVM, int argc, const Object* argv);
93     Object appendDEx(VM* theVM, int argc, const Object* argv);
94     Object lengthEx(VM* theVM, int argc, const Object* argv);
95     Object makeVectorEx(VM* theVM, int argc, const Object* argv);
96     Object vectorRefEx(VM* theVM, int argc, const Object* argv);
97     Object vectorSetDEx(VM* theVM, int argc, const Object* argv);
98     Object vectorLengthEx(VM* theVM, int argc, const Object* argv);
99 
existsInList(Object o,Object list)100     inline bool existsInList(Object o, Object list)
101     {
102         for (Object q = list; q.isPair(); q = q.cdr()) {
103             if (q.car() == o) return true;
104         }
105         return false;
106     }
107 
108 
109     // callee should check <list>.
memq(Object o,Object list)110     inline Object memq(Object o, Object list)
111     {
112         for (Object p = list; p.isPair(); p = p.cdr()) {
113             if (p.car() == o) {
114                 return p;
115             }
116         }
117         return Object::False;
118     }
119 
120     Object uniq(Object list);
121     Object assq(Object o, Object alist);
assq(Object o,Object alist)122     inline Object assq(Object o, Object alist)
123     {
124         for (Object p = alist; p.isPair(); p = p.cdr()) {
125             if (p.car().car() == o) {
126                 return p.car();
127             }
128         }
129         return Object::False;
130     }
131 
132     Object listTovectorEx(VM* theVM, int argc, const Object* argv);
133 
134     // for nmosh
135     Object sexpMapDebugEx(VM* theVM, int argc, const Object* argv);
136     Object sexpMapEx(VM* theVM, int argc, const Object* argv);
137 
138 
139 } // namespace scheme
140 
141 #endif // SCHEME_LIST_PROCEDURES_
142