fry: make-free deep-fry

db4
Eduardo Cavazos 2008-07-03 11:25:27 -05:00
parent d0cddcfc41
commit 9b3d124157
1 changed files with 11 additions and 15 deletions

View File

@ -1,7 +1,7 @@
! Copyright (C) 2008 Slava Pestov, Eduardo Cavazos.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel sequences combinators parser splitting
quotations arrays namespaces qualified ;
USING: kernel sequences combinators parser splitting math
quotations arrays namespaces qualified sequences.deep sequences.lib ;
QUALIFIED: namespaces
IN: fry
@ -35,26 +35,22 @@ DEFER: shallow-fry
: shallow-fry ( quot -- quot' ) [ ] swap (shallow-fry) ;
: deep-fry ( quot -- quot' )
{ _ } last-split1 [
[
shallow-fry %
[ >r ] %
deep-fry %
[ [ dip ] curry r> compose ] %
] [ ] make
: deep-fry ( quot -- quot )
{ _ } last-split1 dup [
shallow-fry [ >r ] rot
deep-fry [ [ dip ] curry r> compose ] 4array concat
] [
shallow-fry
] if* ;
drop shallow-fry
] if ;
: fry-specifier? ( obj -- ? ) { , namespaces:, @ } member? ;
: count-inputs ( quot -- n )
[
{
{ [ dup callable? ] [ count-inputs ] }
{ [ dup fry-specifier? ] [ drop 1 ] }
[ drop 0 ]
{ [ dup callable? ] [ count-inputs ] }
{ [ dup fry-specifier? ] [ drop 1 ] }
[ drop 0 ]
} cond
] map sum ;