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

Contents of /tests/addrbook.cd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 66 - (show annotations)
Tue Jul 10 17:02:51 2007 UTC (5 years, 10 months ago) by abate
File size: 1224 byte(s)
[r2002-10-31 16:59:46 by cvscast] Empty log message

Original author: cvscast
Date: 2002-10-31 17:00:08+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 <addrbook>[
9 <name>"Haruo Hosoya"
10 <addr>"Tokyo"
11 <name>"Benjamin Pierce"
12 <addr>"Philadelphia"
13 <tel>"123-456-789"
14 <name>"Peter Buneman"
15 <addr>"Scotland"
16 ];;
17
18 (* converting an address book into a telephone list *)
19
20 fun mkTelList ([ (Name Addr Tel?)* ] -> [ (Name Tel)* ])
21 | [ <name>n <addr>a <tel>t ; rest] -> [ <name>n <tel>t ; mkTelList rest]
22 | [ <name>n <addr>a; rest] -> mkTelList rest
23 | [ ] -> [ ]
24 ;;
25
26 fun mkTelList (Addrbook -> [ (Name Tel)* ])
27 <_>[ ( ( (x::Name) Addr (x::Tel) ) | _ )* ] -> x
28 ;;
29
30 fun (Int -> Addrbook) x ->
31 <addrbook>[
32 <name>"Haruo Hosoya"
33 <addr>"Tokyo"
34 <name>"Benjamin Pierce"
35 <addr>"Philadelphia"
36 <tel>"123-456-789"
37 <name>"Peter Buneman"
38 <addr>"Scotland"
39 ]
40 ;;
41
42 match <addrbook>[
43 <name>"Haruo Hosoya"
44 <addr>"Tokyo"
45 <name>"Benjamin Pierce"
46 <addr>"Philadelphia"
47 <tel>"123-456-789"
48 <name>"Peter Buneman"
49 <addr>"Scotland"
50 ] with
51 <_>[ ( ( (x::Name) Addr (x::Tel) ) | _ )* ] -> x;;
52
53 (*
54 (* the pattern extract the full sequence of subelements *)
55 match ex with addrbook:[;a] -> mkTelList a;;
56 *)
57

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