0 constant nil
: cons here rot , here swap , swap , ;
: list 0 ?do cons loop ;
: list nil swap list ;
variable list-start : (list list-start @ sp@ list-start ! ;
: list) sp@ list-start @ swap - cell / list swap list-start ! ;
: car @ @ ;
: cdr cell+ @ ;
: rplaca @ ! ;
: rplacd cell+ ! ;
: elt 0 ?do cdr loop ;
: elt@ elt car ;
: elt! elt rplaca ;
: last dup 0<> if begin dup cdr 0<> while cdr repeat then ;
: nconc over last rplacd ;
: copy-list dup 0<> if dup car swap cdr recurse cons then ;
: append swap copy-list swap nconc ;
: length 0 begin swap ?dup while cdr swap 1+ repeat ;
: mapc
begin ?dup while 2dup car swap execute cdr repeat drop ;
: mapc swap mapc ;
: list. ['] . mapc ;
: mapcar
dup 0= if nip else 2dup car swap execute -rot cdr recurse cons then ;
: mapcar swap mapcar ;
: reverse
?dup 0<> if dup car rot cons swap cdr recurse then ;
: reverse nil swap reverse ;
: list-swap
>r over r> 2dup 2>r elt@ -rot 2dup elt@ 2r> elt! elt! ;
: nreverse dup length dup 1+ 2 / 0 ?do 1- 2dup i list-swap loop drop ;
(list 1 2 3 4 5 6 list) constant mylist
mylist length . mylist 3 elt@ . mylist (list 7 8 9 list) append list. mylist nreverse list. mylist :noname dup * ; mapcar list. (list 1 (list 2 3 list) 4 list) constant nested-list
nested-list 1 elt@ list.