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 ;
7 : _ ( -- * ) "Only valid inside a fry" throw ;
8 : @ ( -- * ) "Only valid inside a fry" throw ;
15 : ((shallow-fry)) ( accum quot adder -- result )
18 [ prepose ] curry append
19 ] unless-empty ; inline
21 : (shallow-fry) ( accum quot -- result )
24 { \ _ [ [ curry ] ((shallow-fry)) ] }
25 { \ @ [ [ compose ] ((shallow-fry)) ] }
26 [ swap >r suffix r> (shallow-fry) ]
30 : shallow-fry ( quot -- quot' ) [ ] swap (shallow-fry) ;
32 PREDICATE: fry-specifier < word { _ @ } memq? ;
34 GENERIC: count-inputs ( quot -- n )
36 M: callable count-inputs [ count-inputs ] sigma ;
37 M: fry-specifier count-inputs drop 1 ;
38 M: object count-inputs drop 0 ;
42 : fry ( quot -- quot' )
46 [ count-inputs \ _ <repetition> % ] [ fry % ] bi
49 ] [ ] make shallow-fry ;
51 : '[ \ ] parse-until fry over push-all ; parsing