Rewriting llength in terms of folds

db4
James Cash 2008-06-05 14:32:43 -04:00
parent 6631807393
commit 7061468473
1 changed files with 3 additions and 9 deletions

View File

@ -51,12 +51,6 @@ M: object nil? drop f ;
: lnth ( n list -- elt )
swap [ cdr ] times car ;
: (llength) ( list acc -- n )
over nil? [ nip ] [ [ cdr ] dip 1+ (llength) ] if ;
: llength ( list -- n )
0 (llength) ;
: (leach) ( list quot -- cdr quot )
[ [ car ] dip call ] [ [ cdr ] dip ] 2bi ; inline
@ -74,13 +68,13 @@ M: object nil? drop f ;
[ [ cdr ] 2dip foldr ] [ nip [ car ] dip ] 3bi
call
] if ; inline
: llength ( list -- n )
0 [ drop 1+ ] foldl ;
: lreverse ( list -- newlist )
nil [ swap cons ] foldl ;
: lappend ( list1 list2 -- newlist )
;
: seq>list ( seq -- list )
<reversed> nil [ swap cons ] reduce ;