Merge remote branch 'master'
[prop.git] / tests / list1.pcc
blobf515ce6eab3fda61f3fea43ce78884a5b721299c
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 //  Testing the list features. 
4 //
5 //////////////////////////////////////////////////////////////////////////////
6 #include <iostream.h>
8 //////////////////////////////////////////////////////////////////////////////
9 //  Defines a list type.
10 //////////////////////////////////////////////////////////////////////////////
11 datatype LIST = #[] 
12               | #[ char * ... LIST ]
13               ;
15 //////////////////////////////////////////////////////////////////////////////
16 //  Method to print a list.
17 //////////////////////////////////////////////////////////////////////////////
18 ostream& operator << (ostream& f, LIST l)
19 {  match (l) 
20    {  #[]:        { return f; }
21    |  #[x]:       { return f << x; }
22    |  #[x ... y]: { return f << x << ", " << y; }
23    }
26 //////////////////////////////////////////////////////////////////////////////
27 //  Try the new list constructor in expressions.
28 //////////////////////////////////////////////////////////////////////////////
29 int main()
30 {  LIST fruits  = #["apple", "orange", "pear"];
31    LIST scums   = #["marketing", "lawyers", "Republicans"];
32    LIST animals = #["weasels", "skunks" ... scums]; 
33    cout << "Fruits        = " << fruits  << '\n';
34    cout << "Animals       = " << animals << '\n';
35    cout << "Mathematicans = " << #["Skolem", "Curry", "Thue", "Church"] << '\n';
36    return 0;