stack-lang-triangle.modal
· 1.6 KiB · Text
Ham
Playground
<> (?0 ?1 >> `?:) (?: >>)
<> (>> +) (>> `+)
<> (>> -) (>> `-)
<> (>> *) (>> `*)
<> (>> >) (>> `>)
<> (>> &) (>> `&)
<> (>> =) (>> `=)
<> (?x ?y >> swap) (?y ?x >>)
<> (?x >> dup) (?x ?x >>)
<> (?x >> drop) (>>)
<> (() >> call) (>>)
<> (?. >> call) (>> ?.)
<> (?x ?. >> dip) (>> ?. lit ?x)
<> (?x ?. >> curry) ((?x ?.) >>)
<> (?. ?x >> compose) (1 () .. ?. #composer ?x ])
<> (.. #composer ?.) (.. ?.)
<> (?x ?y ?z >> bury) (?z ?x ?y >>)
<> (1 ?t ?f >> if) (?t >> call)
<> (0 ?t ?f >> if) (?f >> call)
<> (>> lit ?x) (?x >>)
<> (() ?x #snoc) ((?x))
<> (?. ?x #snoc) ((?. ?x))
<> (>> : ?x) (?x () ..)
<> (?x ?. .. ;) ([edit>>] <> (>> ?x) (>> ?.) [/edit>>] >>)
<> (>> [) (1 () ..)
<> (.. [) (0 () ..)
<> (0 ?x .. ]) (?x #snoc ..)
<> (1 ?x .. ]) (?x >>)
<> (?: #print) (?:)
<> (.. .") (() ...")
<> (..." ") (#snoc . #snoc ..)
<> (..." ?x) (?x #snoc ...")
<> (>> .) (#print >>)
<> (>> .s) (() >>.s)
<> (?x () >>.s) ((?x) >>.s)
<> (?x ?. >>.s) ((?x ?.) >>.s)
<> (?. >>.s) ((?.\n) #print ?. >>)
<> ([edit>>]) (>< (>> ?x))
<> ([/edit>>]) (<> (>> ?x) (?x >>))
<> ([edit..]) (>< (.. ?x))
<> ([/edit..]) (<> (.. ?x) (?x #snoc ..))
[/edit..]
[/edit>>]
>>
: 3drop drop drop drop ;
: when [ ] if ;
: over [ dup ] dip swap ;
: 2dup over over ;
: [each-int] [ 2dup ] dip bury > [ 2dup call [ 1 + ] dip [each-int] ] when ;
: each-int 0 swap [each-int] 3drop ;
: times [ drop ] swap compose each-int ;
: with [ swap ] dip [ [ swap ] dip call ] curry curry ;
: plot & 0 = [ ." *\s " ] [ ." \s\s " ] if ;
: tuck swap over ;
: pad 1 - [ ." \s " ] times ;
: plot-row dup 1 + [ tuck - plot ] with each-int ;
: sierpinski dup [ over - pad plot-row \n . ] curry each-int ;
64 sierpinski
1 | <> (?0 ?1 >> `?:) (?: >>) |
2 | <> (>> +) (>> `+) |
3 | <> (>> -) (>> `-) |
4 | <> (>> *) (>> `*) |
5 | <> (>> >) (>> `>) |
6 | <> (>> &) (>> `&) |
7 | <> (>> =) (>> `=) |
8 | |
9 | <> (?x ?y >> swap) (?y ?x >>) |
10 | <> (?x >> dup) (?x ?x >>) |
11 | <> (?x >> drop) (>>) |
12 | <> (() >> call) (>>) |
13 | <> (?. >> call) (>> ?.) |
14 | <> (?x ?. >> dip) (>> ?. lit ?x) |
15 | <> (?x ?. >> curry) ((?x ?.) >>) |
16 | <> (?. ?x >> compose) (1 () .. ?. #composer ?x ]) |
17 | <> (.. #composer ?.) (.. ?.) |
18 | |
19 | <> (?x ?y ?z >> bury) (?z ?x ?y >>) |
20 | <> (1 ?t ?f >> if) (?t >> call) |
21 | <> (0 ?t ?f >> if) (?f >> call) |
22 | |
23 | <> (>> lit ?x) (?x >>) |
24 | |
25 | <> (() ?x #snoc) ((?x)) |
26 | <> (?. ?x #snoc) ((?. ?x)) |
27 | |
28 | <> (>> : ?x) (?x () ..) |
29 | <> (?x ?. .. ;) ([edit>>] <> (>> ?x) (>> ?.) [/edit>>] >>) |
30 | <> (>> [) (1 () ..) |
31 | <> (.. [) (0 () ..) |
32 | <> (0 ?x .. ]) (?x #snoc ..) |
33 | <> (1 ?x .. ]) (?x >>) |
34 | |
35 | <> (?: #print) (?:) |
36 | <> (.. .") (() ...") |
37 | <> (..." ") (#snoc . #snoc ..) |
38 | <> (..." ?x) (?x #snoc ...") |
39 | <> (>> .) (#print >>) |
40 | |
41 | <> (>> .s) (() >>.s) |
42 | <> (?x () >>.s) ((?x) >>.s) |
43 | <> (?x ?. >>.s) ((?x ?.) >>.s) |
44 | <> (?. >>.s) ((?.\n) #print ?. >>) |
45 | |
46 | <> ([edit>>]) (>< (>> ?x)) |
47 | <> ([/edit>>]) (<> (>> ?x) (?x >>)) |
48 | <> ([edit..]) (>< (.. ?x)) |
49 | <> ([/edit..]) (<> (.. ?x) (?x #snoc ..)) |
50 | |
51 | [/edit..] |
52 | [/edit>>] |
53 | |
54 | >> |
55 | |
56 | : 3drop drop drop drop ; |
57 | : when [ ] if ; |
58 | : over [ dup ] dip swap ; |
59 | : 2dup over over ; |
60 | : [each-int] [ 2dup ] dip bury > [ 2dup call [ 1 + ] dip [each-int] ] when ; |
61 | : each-int 0 swap [each-int] 3drop ; |
62 | : times [ drop ] swap compose each-int ; |
63 | : with [ swap ] dip [ [ swap ] dip call ] curry curry ; |
64 | : plot & 0 = [ ." *\s " ] [ ." \s\s " ] if ; |
65 | : tuck swap over ; |
66 | : pad 1 - [ ." \s " ] times ; |
67 | : plot-row dup 1 + [ tuck - plot ] with each-int ; |
68 | : sierpinski dup [ over - pad plot-row \n . ] curry each-int ; |
69 | |
70 | 64 sierpinski |