/[svn]/tests/addrbook.cd
ViewVC logotype

Contents of /tests/addrbook.cd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1370 - (show annotations)
Tue Jul 10 18:43:29 2007 UTC (5 years, 10 months ago) by abate
File size: 1442 byte(s)
[r2004-12-26 15:36:17 by afrisch] New compilation seems to work, but horribly slow...

Original author: afrisch
Date: 2004-12-26 15:36:18+00:00
1 type Content = [(Name Addr Tel?)*];;
2 type Addrbook = <addrbook>Content;;
3 type Name = <name>[ PCDATA ];;
4 type Addr = <addr>[ PCDATA ];;
5 type Tel = <tel>[ PCDATA ];;
6
7
8 (*
9 <addrbook>[
10 <name>"Haruo Hosoya"
11 <addr>"Tokyo"
12 <name>"Benjamin Pierce"
13 <addr>"Philadelphia"
14 <tel>"123-456-789"
15 <name>"Peter Buneman"
16 <addr>"Scotland"
17 ];;
18 *)
19
20 (* converting an address book into a telephone list *)
21
22 let mkTelList ([ (Name Addr Tel?)* ] -> [ (Name Tel)* ])
23 | [ <name>n <addr>_ <tel>t ; rest] -> [ <name>n <tel>t ; mkTelList rest]
24 | [ <name>_ <addr>_; rest] -> mkTelList rest
25 | [ ] -> [ ]
26 ;;
27
28 mkTelList [
29 <name>"Haruo Hosoya"
30 <addr>"Tokyo"
31 <name>"Benjamin Pierce"
32 <addr>"Philadelphia"
33 <tel>"123-456-789"
34 <name>"Peter Buneman"
35 <addr>"Scotland"
36 ];;
37
38 (*
39 fun mkTelList (Addrbook -> [ (Name Tel)* ])
40 <_>[ ( ( (x::Name) Addr (x::Tel) ) | _ )* ] -> x
41 ;;
42
43
44 fun (Int -> Addrbook) _ ->
45 <addrbook>[
46 <name>"Haruo Hosoya"
47 <addr>"Tokyo"
48 <name>"Benjamin Pierce"
49 <addr>"Philadelphia"
50 <tel>"123-456-789"
51 <name>"Peter Buneman"
52 <addr>"Scotland"
53 ]
54 ;;
55
56 *)
57
58 (*
59 match <addrbook>[
60 <name>"Haruo Hosoya"
61 <addr>"Tokyo"
62 <name>"Benjamin Pierce"
63 <addr>"Philadelphia"
64 <tel>"123-456-789"
65 <name>"Peter Buneman"
66 <addr>"Scotland"
67 ] with
68 <_>[ ( ( (x::Name) Addr (x::Tel) ) | _ )* ] -> print (print_xml <doc>x);;
69 *)
70 (*
71 (*
72 (* the pattern extract the full sequence of subelements *)
73 match ex with addrbook:[;a] -> mkTelList a;;
74 *)
75
76 *)

CVS Admin">CVS Admin
ViewVC Help
Powered by ViewVC 1.1.5