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 namespaces qualified ;
8 : , ( -- * ) "Only valid inside a fry" throw ;
9 : @ ( -- * ) "Only valid inside a fry" throw ;
10 : _ ( -- * ) "Only valid inside a fry" throw ;
15 : ((shallow-fry)) ( accum quot adder -- result )
17 append swap dup empty? [ drop ] [
18 [ prepose ] curry append
21 : (shallow-fry) ( accum quot -- result )
26 { \ , [ [ curry ] ((shallow-fry)) ] }
27 { \ @ [ [ compose ] ((shallow-fry)) ] }
29 ! to avoid confusion, remove if fry goes core
30 { \ namespaces:, [ [ curry ] ((shallow-fry)) ] }
32 [ swap >r suffix r> (shallow-fry) ]
36 : shallow-fry ( quot -- quot' ) [ ] swap (shallow-fry) ;
38 : deep-fry ( quot -- quot )
39 { _ } last-split1 dup [
40 shallow-fry [ >r ] rot
41 deep-fry [ [ dip ] curry r> compose ] 4array concat
46 : fry-specifier? ( obj -- ? ) { , namespaces:, @ } member? ;
48 : count-inputs ( quot -- n )
51 { [ dup callable? ] [ count-inputs ] }
52 { [ dup fry-specifier? ] [ drop 1 ] }
57 : fry ( quot -- quot' )
61 [ count-inputs \ , <repetition> % ] [ fry % ] bi
66 : '[ \ ] parse-until fry over push-all ; parsing