1 ! Copyright (C) 2008 Slava Pestov, Eduardo Cavazos.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel sequences combinators parser splitting math
4 quotations arrays make words locals.backend summary sets ;
7 : _ ( -- * ) "Only valid inside a fry" throw ;
8 : @ ( -- * ) "Only valid inside a fry" throw ;
10 ERROR: >r/r>-in-fry-error ;
14 : [ncurry] ( n -- quot )
20 [ [ curry ] <repetition> ]
23 M: >r/r>-in-fry-error summary
25 "Explicit retain stack manipulation is not permitted in fried quotations" ;
27 : check-fry ( quot -- quot )
28 dup { >r r> load-locals get-local drop-locals } intersect
29 empty? [ >r/r>-in-fry-error ] unless ;
31 : shallow-fry ( quot -- quot' )
33 [ dup \ @ = [ drop [ _ call ] ] [ 1array ] if ] map concat
34 { _ } split [ length 1- [ncurry] ] [ spread>quot ] bi prefix ;
36 PREDICATE: fry-specifier < word { _ @ } memq? ;
38 GENERIC: count-inputs ( quot -- n )
40 M: callable count-inputs [ count-inputs ] sigma ;
41 M: fry-specifier count-inputs drop 1 ;
42 M: object count-inputs drop 0 ;
46 : fry ( quot -- quot' )
50 [ count-inputs \ _ <repetition> % ] [ fry % ] bi
53 ] [ ] make shallow-fry ;
55 : '[ \ ] parse-until fry over push-all ; parsing