1(package pygments-test [some symbols]
2
3\* multiline
4   comment
5*\
6
7\\ With vars as functions
8
9(define super
10  [Value Succ End] Action Combine Zero ->
11  (if (End Value)
12      Zero
13      (Combine (Action Value)
14               (super [(Succ Value) Succ End]
15                      Action Combine Zero))))
16
17(define for
18  Stream Action -> (super Stream Action (function do) 0))
19
20(define filter
21  Stream Condition ->
22  (super Stream
23         (/. Val (if (Condition Val) [Val] []))
24         (function append)
25         []))
26
27(for [0 (+ 1) (= 10)] (function print))
28
29(filter [0 (+ 1) (= 100)]
30        (/. X (integer? (/ X 3))))
31
32
33\\ Typed functions
34
35(define typed-map
36  { (A --> B) --> (list A) --> (list B) }
37  F X -> (typed-map-h F X []))
38
39(define typed-map-h
40  { (A --> B) --> (list A) --> (list B) \\ comment
41       --> (list B) }
42  _ [] X -> (reverse X)
43  F [X | Y] Z -> (typed-map-h F Y [(F X) | Z]))
44
45(define append-string
46  { string --> string \* comment *\ --> string }
47  S1 S2 -> (cn S1 S2))
48
49(let X 1
50     Y 2
51  (+ (type X number) (type Y number)))
52
53\\ Yacc
54
55(defcc <st_input>
56  <lrb>  <st_input1> <rrb> <st_input2>
57   := (package-macro (macroexpand <st_input1>) <st_input2>);
58  <lcurly> <st_input> := [{ | <st_input>];
59  <rcurly> <st_input> := [} | <st_input>];
60  <bar> <st_input> := [bar! | <st_input>];
61  <semicolon> <st_input> := [; | <st_input>];
62  <colon> <equal> <st_input> := [:= | <st_input>];
63  <colon> <minus> <st_input> := [:- | <st_input>];
64  <colon> <st_input> := [: | <st_input>];
65  <comma> <st_input> := [(intern ",") | <st_input>];
66  <e> := [];)
67
68(defcc <lsb>
69   91 := skip;)
70
71\\ Pattern matching
72
73(define matches
74  1 X 3 -> X
75  X Y Z -> Y where  (and (= X 1) (= Z 3))
76  true false _ -> true
77  (@p a X c) (@s X "abc") (@v 1 2 3 <>) -> true
78  [X | Rest] [] [a b c] -> true
79  [(@p a b)] [[[1] 2] X] "string" -> true
80  _ _ _ -> false)
81
82
83\\ Prolog
84
85(defprolog th*
86  X A Hyps <-- (show [X : A] Hyps) (when false);
87  X A _ <-- (fwhen (typedf? X)) (bind F (sigf X)) (call [F A]);
88  (mode [F] -) A Hyp <-- (th* F [--> A] Hyp);
89  (mode [cons X Y] -) [list A] Hyp <-- (th* X A Hyp) (th* Y [list A] Hyp);
90  (mode [@s X Y] -) string Hyp <-- (th* X string Hyp) (th* Y string Hyp);
91  (mode [lambda X Y] -) [A --> B] Hyp <-- !
92                                           (bind X&& (placeholder))
93                                           (bind Z (ebr X&& X Y))
94                                           (th* Z B [[X&& : A] | Hyp]);
95  (mode [type X A] -) B Hyp <-- ! (unify A B) (th* X A Hyp);)
96
97\\ Macros
98
99(defmacro log-macro
100  [log N] -> [log N 10])
101
102\\ Sequent calculus
103
104(datatype rank
105
106  if (element? X [ace 2 3 4 5 6 7 8 9 10 jack queen king])
107  ________
108  X : rank;)
109
110(datatype suit
111
112  if (element? Suit [spades hearts diamonds clubs])
113  _________
114  Suit : suit;)
115
116(datatype card
117
118  Rank : rank; Suit : suit;
119  _________________
120  [Rank Suit] : card;
121
122  Rank : rank, Suit : suit >> P;
123  _____________________
124  [Rank Suit] : card >> P;)
125
126(datatype card
127
128  Rank : rank; Suit : suit;
129  ==================
130  [Rank Suit] : card;)
131
132\\ String interpolation and escape sequences
133
134"abc~A ~S~R ~% blah
135 c#30;c#31;blah"
136
137)
138