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 qualified words ;
8 : , ( -- * ) "Only valid inside a fry" throw ;
9 : @ ( -- * ) "Only valid inside a fry" throw ;
16 : ((shallow-fry)) ( accum quot adder -- result )
19 [ prepose ] curry append
20 ] unless-empty ; inline
22 : (shallow-fry) ( accum quot -- result )
25 { \ , [ [ curry ] ((shallow-fry)) ] }
26 { \ @ [ [ compose ] ((shallow-fry)) ] }
28 ! to avoid confusion, remove if fry goes core
29 { \ make:, [ [ curry ] ((shallow-fry)) ] }
31 [ swap >r suffix r> (shallow-fry) ]
35 : shallow-fry ( quot -- quot' ) [ ] swap (shallow-fry) ;
37 PREDICATE: fry-specifier < word { , make:, @ } memq? ;
39 GENERIC: count-inputs ( quot -- n )
41 M: callable count-inputs [ count-inputs ] sigma ;
42 M: fry-specifier count-inputs drop 1 ;
43 M: object count-inputs drop 0 ;
47 : fry ( quot -- quot' )
51 [ count-inputs \ , <repetition> % ] [ fry % ] bi
54 ] [ ] make shallow-fry ;
56 : '[ \ ] parse-until fry over push-all ; parsing