ERROR: >r/r>-in-fry-error ;
-DEFER: fry
+GENERIC: fry ( quot -- quot' )
<PRIVATE
M: fry-specifier count-inputs drop 1 ;
M: object count-inputs drop 0 ;
+MIXIN: fried
PREDICATE: fried-callable < callable
count-inputs 0 > ;
+INSTANCE: fried-callable fried
: convert-curry ( quot -- quot' )
[ [ [ ] curry compose ] ] [
{ _ } split convert-curries
spread>quot ;
+: [ncurry] ( quot n -- quot )
+ {
+ { 0 [ [ ] ] }
+ { 1 [ [ curry ] ] }
+ { 2 [ [ 2curry ] ] }
+ { 3 [ [ 3curry ] ] }
+ [ \ curry <repetition> ]
+ } case curry ;
+
: [ndip] ( quot n -- quot' )
{
{ 0 [ \ call [ ] 2sequence ] }
[ 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>
[ dredge-fry ] [
[ prequot>> >quotation ]
! 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 fry
+ clone [ fry ] change-body ;
-M: let deep-fry
- clone [ fry '[ @ call ] ] change-body , ;
+INSTANCE: lambda fried
+INSTANCE: let fried