diff --git a/basis/fry/fry.factor b/basis/fry/fry.factor index 991ab76420..42518528dc 100644 --- a/basis/fry/fry.factor +++ b/basis/fry/fry.factor @@ -8,7 +8,7 @@ IN: fry ERROR: >r/r>-in-fry-error ; -DEFER: fry +GENERIC: fry ( quot -- quot' ) ; +INSTANCE: fried-callable fried : convert-curry ( quot -- quot' ) [ [ [ ] curry compose ] ] [ @@ -43,6 +45,15 @@ PREDICATE: fried-callable < callable { _ } split convert-curries spread>quot ; +: [ncurry] ( quot n -- quot ) + { + { 0 [ [ ] ] } + { 1 [ [ curry ] ] } + { 2 [ [ 2curry ] ] } + { 3 [ [ 3curry ] ] } + [ \ curry ] + } case curry ; + : [ndip] ( quot n -- quot' ) { { 0 [ \ call [ ] 2sequence ] } @@ -85,13 +96,13 @@ TUPLE: dredge-fry-state [ in-quot>> swap tail-slice ] [ quot>> ] bi push-all ; inline recursive : dredge-fry ( n dredge-fry -- ) - 2dup in-quot>> [ fried-callable? ] find-from + 2dup in-quot>> [ fried? ] find-from [ (dredge-fry-subquot) ] [ drop (dredge-fry-simple) ] if* ; inline recursive PRIVATE> -: fry ( quot -- quot' ) +M: callable fry ( quot -- quot' ) 0 swap [ dredge-fry ] [ [ prequot>> >quotation ] diff --git a/basis/locals/fry/fry.factor b/basis/locals/fry/fry.factor index ff6a491a79..30336c45e9 100644 --- a/basis/locals/fry/fry.factor +++ b/basis/locals/fry/fry.factor @@ -1,18 +1,21 @@ ! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos. ! See http://factorcode.org/license.txt for BSD license. USING: accessors fry fry.private generalizations kernel -locals.types make sequences ; +locals.types sequences ; IN: locals.fry ! Support for mixing locals with fry M: let count-inputs body>> count-inputs ; - M: lambda count-inputs body>> count-inputs ; -M: lambda deep-fry - clone [ shallow-fry swap ] change-body - [ [ vars>> length ] keep '[ _ _ mnswap @ ] , ] [ drop [ncurry] % ] 2bi ; +M: lambda fry + clone [ [ count-inputs ] [ fry ] bi ] change-body + [ [ vars>> length ] keep '[ _ _ mnswap _ call ] ] + [ drop [ncurry] [ call ] compose ] 2bi ; -M: let deep-fry - clone [ fry '[ @ call ] ] change-body , ; +M: let fry + clone [ fry ] change-body ; + +INSTANCE: lambda fried +INSTANCE: let fried