2 USING: kernel sbufs strings sequences assocs math
3 combinators.lib vars lsys.strings combinators.short-circuit ;
5 IN: lsys.strings.rewrite
7 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
11 : lookup ( str -- str ) [ 1 head rules> at ] [ ] bi or ;
13 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
17 : push-next ( next -- ) lookup accum> push-all ;
19 : (rewrite) ( slice -- )
20 { { [ empty? ] [ drop ] }
21 { [ has-param? ] [ next+rest* [ push-next ] [ (rewrite) ] bi* ] }
22 { [ t ] [ next+rest [ push-next ] [ (rewrite) ] bi* ] } }
25 : rewrite ( string -- string )
26 dup length 10 * <sbuf> >accum
27 <flat-slice> (rewrite)
30 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
34 : iterate ( -- ) result> rewrite >result ;
36 : iterations ( n -- ) [ iterate ] times ;