update terms of fry–locals peace treaty

db4
Joe Groff 2009-11-07 13:03:46 -06:00
parent a4508e9c43
commit 28b09d6d57
2 changed files with 24 additions and 10 deletions

View File

@ -8,7 +8,7 @@ IN: fry
ERROR: >r/r>-in-fry-error ;
DEFER: fry
GENERIC: fry ( quot -- quot' )
<PRIVATE
@ -24,8 +24,10 @@ M: callable count-inputs [ count-inputs ] map-sum ;
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 ] ] [
@ -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 <repetition> ]
} 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>
[ dredge-fry ] [
[ prequot>> >quotation ]

View File

@ -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