2
sequence.d -- Sequence routines.
5
Copyright (c) 1984, Taiichi Yuasa and Masami Hagiya.
6
Copyright (c) 1990, Giuseppe Attardi.
7
Copyright (c) 2001, Juan Jose Garcia Ripoll.
9
ECL is free software; you can redistribute it and/or
10
modify it under the terms of the GNU Library General Public
11
License as published by the Free Software Foundation; either
12
version 2 of the License, or (at your option) any later version.
14
See file '../Copyright' for full details.
19
#include <ecl/ecl-inl.h>
22
I know the following name is not good.
25
cl_alloc_simple_vector(cl_index l, cl_elttype aet)
30
return cl_alloc_simple_string(l);
32
x = cl_alloc_object(t_bitvector);
33
x->vector.hasfillp = FALSE;
34
x->vector.adjustable = FALSE;
35
x->vector.displaced = Cnil;
36
x->vector.dim = x->vector.fillp = l;
38
x->vector.self.bit = NULL;
40
x = cl_alloc_object(t_vector);
41
x->vector.hasfillp = FALSE;
42
x->vector.adjustable = FALSE;
43
x->vector.displaced = Cnil;
44
x->vector.dim = x->vector.fillp = l;
45
x->vector.self.t = NULL;
46
x->vector.elttype = (short)aet;
53
cl_elt(cl_object x, cl_object i)
55
@(return elt(x, fixint(i)))
59
elt(cl_object seq, cl_fixnum index)
66
switch (type_of(seq)) {
68
for (i = index, l = seq; i > 0; --i)
79
if (index >= seq->vector.fillp)
81
return(aref(seq, index));
84
if (index >= seq->string.fillp)
86
return(CODE_CHAR(seq->string.self[index]));
92
FEwrong_type_argument(@'sequence', seq);
95
FEtype_error_index(seq, MAKE_FIXNUM(index));
99
si_elt_set(cl_object seq, cl_object index, cl_object val)
101
@(return elt_set(seq, fixint(index), val))
105
elt_set(cl_object seq, cl_fixnum index, cl_object val)
112
switch (type_of(seq)) {
114
for (i = index, l = seq; i > 0; --i)
121
return(CAR(l) = val);
125
if (index >= seq->vector.fillp)
127
return(aset(seq, index, val));
130
if (index >= seq->string.fillp)
132
/* INV: char_code() checks the type of `val' */
133
seq->string.self[index] = char_code(val);
137
FEwrong_type_argument(@'sequence', seq);
140
FEtype_error_index(seq, MAKE_FIXNUM(index));
143
@(defun subseq (sequence start &optional end &aux x)
152
switch (type_of(sequence)) {
154
if (Null(sequence)) {
156
goto ILLEGAL_START_END;
158
goto ILLEGAL_START_END;
161
FEwrong_type_argument(@'sequence', sequence);
166
goto ILLEGAL_START_END;
169
goto ILLEGAL_START_END;
170
sequence = CDR(sequence);
173
return cl_copy_list(sequence);
175
for (i = 0; i < e; i++) {
177
goto ILLEGAL_START_END;
178
z = &CDR(*z = CONS(CAR(sequence), Cnil));
179
sequence = CDR(sequence);
187
if (s > sequence->vector.fillp)
188
goto ILLEGAL_START_END;
190
e = sequence->vector.fillp;
191
else if (e < s || e > sequence->vector.fillp)
192
goto ILLEGAL_START_END;
193
x = cl_alloc_simple_vector(e - s, array_elttype(sequence));
194
ecl_copy_subarray(x, 0, sequence, s, e-s);
198
FEwrong_type_argument(@'sequence', sequence);
202
FEerror("~S and ~S are illegal as :START and :END~%\
203
for the sequence ~S.", 3, start, end, sequence);
207
cl_copy_seq(cl_object x)
209
return @subseq(2, x, MAKE_FIXNUM(0));
213
cl_length(cl_object x)
215
@(return MAKE_FIXNUM(length(x)))
223
switch (type_of(x)) {
227
FEwrong_type_argument(@'sequence', x);
230
/* INV: A list's length always fits in a fixnum */
240
return(x->vector.fillp);
243
FEwrong_type_argument(@'sequence', x);
248
cl_reverse(cl_object seq)
252
switch (type_of(seq)) {
257
FEwrong_type_argument(@'sequence', seq);
260
for (x = seq, output = Cnil; !endp(x); x = CDR(x))
261
output = CONS(CAR(x), output);
267
output = cl_alloc_simple_vector(seq->vector.fillp, array_elttype(seq));
268
ecl_copy_subarray(output, 0, seq, 0, seq->vector.fillp);
269
ecl_reverse_subarray(output, 0, seq->vector.fillp);
273
FEwrong_type_argument(@'sequence', seq);
279
cl_nreverse(cl_object seq)
281
switch (type_of(seq)) {
284
FEwrong_type_argument(@'sequence', seq);
288
for (x = Cnil, y = seq; !endp(CDR(y));) {
301
ecl_reverse_subarray(seq, 0, seq->vector.fillp);
304
FEwrong_type_argument(@'sequence', seq);