@@ -32,20 +32,86 @@ proto! bank {
32
32
}
33
33
}
34
34
35
- fn macros ( ) {
36
- #macro[
37
- [ #move[ x] ,
38
- unsafe { let y <- * ptr:: addr_of ( x ) ; y } ]
39
- ] ;
35
+ macro_rules! move {
36
+ { $x: expr } => { unsafe { let y <- * ptr:: addr_of( $x) ; y } }
40
37
}
41
38
39
+ fn switch < T : send , U > ( +endp : pipes:: recv_packet < T > ,
40
+ f : fn ( +option < T > ) -> U ) -> U {
41
+ f ( pipes:: try_recv ( endp) )
42
+ }
43
+
44
+ fn move < T > ( -x : T ) -> T { x }
45
+
46
+ macro_rules! follow {
47
+ {
48
+ $( $message: path( $( $x: ident) ,+) => $next: ident $e: expr) +
49
+ } => (
50
+ |m| alt move( m) {
51
+ $( some( $message( $( $x, ) * next) ) {
52
+ let $next = move!{ next} ;
53
+ $e } ) +
54
+ _ { fail }
55
+ }
56
+ ) ;
57
+
58
+ {
59
+ $( $message: path => $next: ident $e: expr) +
60
+ } => (
61
+ |m| alt move( m) {
62
+ $( some( $message( next) ) {
63
+ let $next = move!{ next} ;
64
+ $e } ) +
65
+ _ { fail }
66
+ }
67
+ )
68
+ }
69
+
70
+ /*
71
+ fn client_follow(+bank: bank::client::login) {
72
+ import bank::*;
73
+
74
+ let bank = client::login(bank, ~"theincredibleholk", ~"1234");
75
+ let bank = switch(bank, follow! {
76
+ ok => connected { connected }
77
+ invalid => _next { fail ~"bank closed the connected" }
78
+ });
79
+
80
+ /* // potential alternate syntax
81
+ let bank = recv_alt! {
82
+ bank => {
83
+ | ok -> connected { connected }
84
+ | invalid -> _next { fail }
85
+ }
86
+ bank2 => {
87
+ | foo -> _n { fail }
88
+ }
89
+ }
90
+ */
91
+
92
+ let bank = client::deposit(bank, 100.00);
93
+ let bank = client::withdrawal(bank, 50.00);
94
+ alt try_recv(bank) {
95
+ some(money(m, _)) {
96
+ io::println(~"Yay! I got money!");
97
+ }
98
+ some(insufficient_funds(_)) {
99
+ fail ~"someone stole my money"
100
+ }
101
+ none {
102
+ fail ~"bank closed the connection"
103
+ }
104
+ }
105
+ }
106
+ */
107
+
42
108
fn bank_client( +bank : bank:: client:: login ) {
43
109
import bank:: * ;
44
110
45
111
let bank = client:: login ( bank, ~"theincredibleholk", ~"1234 ") ;
46
112
let bank = alt try_recv ( bank) {
47
113
some ( ok ( connected) ) {
48
- # move( connected)
114
+ move ! { connected}
49
115
}
50
116
some ( invalid ( _) ) { fail ~"login unsuccessful" }
51
117
none { fail ~"bank closed the connection" }
0 commit comments