@@ -264,10 +264,10 @@ package body BBS.lisp.evaluate.symb is
264
264
-- Concatinate lists
265
265
--
266
266
declare
267
- cons_head : cons_index := NIL_CONS;
268
- dest_cons : cons_index := NIL_CONS;
269
- temp_cons : cons_index := NIL_CONS;
270
- src_cons : cons_index := NIL_CONS;
267
+ cons_head : cons_index := NIL_CONS; -- Head of list being built
268
+ dest_cons : cons_index := NIL_CONS; -- Current element in list being built
269
+ temp_cons : cons_index := NIL_CONS; -- New cons cell to add to list
270
+ src_cons : cons_index := NIL_CONS; -- Source list to copy from
271
271
begin
272
272
if s1 = NIL_CONS then
273
273
error(" concatenate" , " Cannot concatenate a single element." );
@@ -279,31 +279,40 @@ package body BBS.lisp.evaluate.symb is
279
279
if t2.kind = V_ERROR then
280
280
error(" concatenate" , " Error reported evaluating additional parameters." );
281
281
e := t2;
282
+ BBS.lisp.conses.deref(cons_head);
282
283
return ;
283
284
end if ;
284
285
src_cons := getList(t2);
285
286
if src_cons = NIL_CONS then
286
287
error(" concatenate" , " Parameter does not evaluate to a list" );
287
288
BBS.lisp.memory.deref(t2);
289
+ BBS.lisp.conses.deref(cons_head);
288
290
e := make_error(ERR_WRONGTYPE);
289
291
return ;
290
292
end if ;
291
293
loop
292
294
if not BBS.lisp.conses.alloc(temp_cons) then
293
295
error(" concatenate" , " Unable to allocate cons cell." );
294
296
BBS.lisp.conses.deref(cons_head);
297
+ BBS.lisp.conses.deref(src_cons);
295
298
e := make_error(ERR_ALLOCCONS);
296
299
return ;
297
300
end if ;
298
301
if cons_head = NIL_CONS then
299
302
cons_head := temp_cons;
300
303
dest_cons := temp_cons;
301
304
else
305
+ --
306
+ -- Point end of list to new cons cell and update end of list.
307
+ --
302
308
BBS.lisp.conses.set_cdr(dest_cons, (kind => V_LIST, l => temp_cons));
303
309
dest_cons := temp_cons;
304
310
end if ;
311
+ --
312
+ -- Copy the value from the source list and move to the next
313
+ -- element in the source.
314
+ --
305
315
BBS.lisp.conses.set_car(dest_cons, BBS.lisp.conses.get_car(src_cons));
306
- BBS.lisp.memory.ref(BBS.lisp.conses.get_car(dest_cons));
307
316
src_cons := getList(BBS.lisp.conses.get_cdr(src_cons));
308
317
if src_cons = NIL_CONS then
309
318
exit ;
0 commit comments