Debian Codegraph @

examples/prism-factor.html

raw symbols SCIP
1 <h2>Comments</h2>
2 <pre><code>! FIXME: a comment
3
4 USE: multiline
5
6 ![[ comment ]]
7 /* comment */</code></pre>
8
9 <h2>Strings</h2>
10 <pre><code>"a string" "\"" "\x8" "%s"
11
12 SBUF" asbdef"
13
14 USE: multiline
15
16 STRING: name
17 content
18 ;
19
20 HEREDOC: marker
21 text
22 marker
23
24 [==[
25 str
26 ing
27 ]==]
28 </code></pre>
29
30 <h2>Numbers</h2>
31 <pre><code>5 1/5 +9 -9 +1/5 -1/5 -1/5. 23+1/5 -23-1/5 23-1/5 ! NOTE: last one = word
32
33 +12.13 0.01 0e0 3E4 3e-4 3E-4 030 0xd 0o30 0b1100
34 -12.13 -0 -0.01 -0e0 -3E4 -3E-4 -030 -0xd -0o30 -0b1100
35
36 348756424956392657834385437598743583648756332457
37 -348756424956392657834385437598743583648756332457
38
39 NAN: a
40 NAN: 80000deadbeef
41
42 0b1.010p2 0x1.0p3 0x1.p1 0b1.111111p1111 ...</code></pre>
43
44 <h2>Sequences</h2>
45 <pre><code>{ 1 2 3 4 }
46 { a b c d e t f }
47 { "a" "b" "c" }
48
49 { { a b } { c d } }
50 H{ { a b } { c d } }
51 H{ { "a" "b" } { "c" "d" } }
52 V{ 1 2 3 4 }
53 V{ "1" "2" "3" "4" }
54 BV{ 1 2 3 4 }</code></pre>
55
56 <h2>Regular Expressions</h2>
57 <pre><code>USE: regexp
58 R/ abcde?.*+\?\.\*\+\/\\\/idmsr-idmsr/idmsr-idmsr</code></pre>
59
60 <h2>Colon parsing words</h2>
61 <pre><code>: a ( -- ) ;
62 :: ; ! ; is not a word name
63 :: ;a ! ;a is a word name
64 USING: a b c ;
65 USE: a
66 IN: a.b
67 CHAR: a
68 GENERIC#: x 1 ( x: integer quot: ( x -- y ) -- )</code></pre>
69
70 <h2>Special words (builtins, conventions)</h2>
71 <pre><code>and not with map filter
72
73 new last-index + - neg
74
75 &lt;array&gt; &lt;=> SYNTAX: x $[ xyz ]
76
77 set-x change-x with-variable ?of if* (gensym) hex. $description reader>> >>setter writer&lt;&lt;
78
79 string>number >hex base> mutater!
80 </code></pre>
81
82 <h2>Full example</h2>
83 <pre><code>USING: accessors arrays assocs combinators
84 combinators.short-circuit effects io kernel sequences
85 sequences.deep splitting strings vocabs words ;
86 IN: prism
87
88 : make-prism-syntax ( syntax-vocab -- seq )
89 vocab-words [
90 dup name>> ">>" = [ drop t ] [
91 {
92 [ "delimiter" word-prop ]
93 [ name>> last { CHAR: : CHAR: { CHAR: [ CHAR: ( CHAR: ) CHAR: ? CHAR: " } member? ]
94 [ name>> { "t" "f" } member? ]
95 } 1|| not
96 ] if
97 ] filter ;
98
99 : combinator? ( word -- ? )
100 [ "declared-effect" word-prop in>> flatten
101 [
102 [ effect? ] [ { "quots" "quot" } member? ] bi or
103 ] any?
104 ] [
105 "help" word-prop ?first flatten [ dup word? [ name>> ] when "quot" swap subseq? ] any?
106 ] bi or ;
107
108 : classify ( vocab-spec -- seq )
109 vocab-words [
110 dup {
111 { [ dup combinator? ] [ drop "combinator" ] }
112 { [ dup "macro" word-prop ] [ drop "macro" ] }
113 [ drop "ordinary" ]
114 } cond 2array
115 ] map ;
116
117 : print-strings ( strs -- )
118 [ name>> "'" dup surround ] map ", " join print ; recursive ! WARN: not recursive
119
120 : combinators. ( vocab-spec -- )
121 classify [ nip "combinator" = ] assoc-filter keys print-strings ; flushable
122
123 : ordinaries. ( vocab-spec -- )
124 classify [ nip "ordinary" = ] assoc-filter keys print-strings ; foldable
125
126 : macros. ( vocab-spec -- )
127 classify [ nip "macro" = ] assoc-filter keys print-strings ; inline</code></pre>