finally prop compiles too
[prop.git] / tests / prop1.pcc
blob4b07d5c7cb2a475c40e19275bb50f8657ba4c047
1 #include <iostream.h>
2 #include <AD/strings/quark.h>
4 datatype List<T> :: collectable rewrite = #[] | #[ T ... List<T> ];
5 datatype List2<T> :: collectable rewrite = #{} | #{ T ... List2<T> };
6 datatype Sexpr :: collectable rewrite
7                = ATOM of Quark
8                | INTEGER of int
9                | REAL of double
10                | #()
11                | #( Sexpr ... Sexpr )
13 law inline LAMBDA(x,e) = #(ATOM(#"lambda"),#(x),e)
14                ;
16 instantiate datatype List<int>, List2<int>, Sexpr, List<Sexpr>;
18 extern ostream& operator << (ostream& s, Sexpr e);
19 extern ostream& print_list(ostream& s, Sexpr e);
21 ostream& print_list(ostream& s, Sexpr e)
22 {  s << '(';
23    match while(e)
24    {  #(h):       { s << h; e = #(); }
25    |  #(h ... t): { s << h << ' '; e = t; }
26    }
27    return s << ')';
30 ostream& operator << (ostream& s, Sexpr e)
31 {  match (e) 
32    {  ATOM id:       { return s << id; }
33    |  INTEGER i:     { return s << i; }
34    |  REAL r:        { return s << r; }
35    |  #():           { return s << "nil"; }
36    |  #( _ ... _ ):  { return print_list(s,e); }
37    }
38
40 int main()
41 {  Sexpr x    = ATOM(#"x");
42    Sexpr succ = LAMBDA(x,#(ATOM(#"+"),x,INTEGER(1)));
43    cout << succ << '\n';
44    return 0;