Rewriting llength in terms of folds
parent
6631807393
commit
7061468473
|
@ -52,12 +52,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
|
||||
|
||||
|
@ -75,12 +69,12 @@ M: object nil? drop f ;
|
|||
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 ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue