Skip to content

Commit 82bad43

Browse files
committed
---
yaml --- r: 148671 b: refs/heads/try2 c: d62097d h: refs/heads/master i: 148669: 725b52a 148667: 9751617 148663: 076354e 148655: 0b1c420 148639: fe3b860 148607: 621c762 v: v3
1 parent 1dd76a5 commit 82bad43

File tree

194 files changed

+1517
-1047
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+1517
-1047
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: c3ae182d5ce005e15d3d1f2906bd67cb65c61f8d
8+
refs/heads/try2: d62097d88cee0ced0eb9508313c48d03ba355e51
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ src/.DS_Store
7474
/doc/html
7575
/doc/latex
7676
/doc/std
77-
/doc/arena
7877
/doc/extra
7978
/doc/flate
80-
/doc/glob
8179
/doc/green
8280
/doc/native
8381
/doc/rustc

branches/try2/doc/guide-conditions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,15 @@ use std::task;
261261
fn main() {
262262
263263
// Isolate failure within a subtask.
264-
let result = task::try(proc() {
264+
let result = do task::try {
265265
266266
// The protected logic.
267267
let pairs = read_int_pairs();
268268
for &(a,b) in pairs.iter() {
269269
println!("{:4.4d}, {:4.4d}", a, b);
270270
}
271271
272-
});
272+
};
273273
if result.is_err() {
274274
println!("parsing failed");
275275
}

branches/try2/doc/guide-pointers.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ struct Point {
221221

222222
fn main() {
223223
let a = Point { x: 10, y: 20 };
224-
spawn(proc() {
224+
do spawn {
225225
println!("{}", a.x);
226-
});
226+
}
227227
}
228228
~~~
229229

@@ -238,9 +238,9 @@ struct Point {
238238

239239
fn main() {
240240
let a = ~Point { x: 10, y: 20 };
241-
spawn(proc() {
241+
do spawn {
242242
println!("{}", a.x);
243-
});
243+
}
244244
}
245245
~~~
246246

branches/try2/doc/guide-runtime.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ extern mod green;
236236
237237
#[start]
238238
fn start(argc: int, argv: **u8) -> int {
239-
green::start(argc, argv, proc() {
239+
do green::start(argc, argv) {
240240
main();
241-
})
241+
}
242242
}
243243
244244
fn main() {}

branches/try2/doc/guide-tasks.md

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ spawn(print_message);
7777
7878
// Print something more profound in a different task using a lambda expression
7979
spawn(proc() println!("I am also running in a different task!") );
80+
81+
// The canonical way to spawn is using `do` notation
82+
do spawn {
83+
println!("I too am running in a different task!");
84+
}
8085
~~~~
8186

8287
In Rust, there is nothing special about creating tasks: a task is not a
@@ -98,10 +103,10 @@ an environment that it carries across tasks.
98103
// Generate some state locally
99104
let child_task_number = generate_task_number();
100105
101-
spawn(proc() {
106+
do spawn {
102107
// Capture it in the remote task
103108
println!("I am child number {}", child_task_number);
104-
});
109+
}
105110
~~~
106111

107112
## Communication
@@ -127,10 +132,10 @@ concurrently:
127132
128133
let (port, chan): (Port<int>, Chan<int>) = Chan::new();
129134
130-
spawn(proc() {
135+
do spawn || {
131136
let result = some_expensive_computation();
132137
chan.send(result);
133-
});
138+
}
134139
135140
some_other_expensive_computation();
136141
let result = port.recv();
@@ -155,10 +160,10 @@ spawns the child task.
155160
# use std::task::spawn;
156161
# fn some_expensive_computation() -> int { 42 }
157162
# let (port, chan) = Chan::new();
158-
spawn(proc() {
163+
do spawn || {
159164
let result = some_expensive_computation();
160165
chan.send(result);
161-
});
166+
}
162167
~~~~
163168

164169
Notice that the creation of the task closure transfers `chan` to the child
@@ -190,15 +195,15 @@ of tasks? The following program is ill-typed:
190195
# fn some_expensive_computation() -> int { 42 }
191196
let (port, chan) = Chan::new();
192197
193-
spawn(proc() {
198+
do spawn {
194199
chan.send(some_expensive_computation());
195-
});
200+
}
196201
197202
// ERROR! The previous spawn statement already owns the channel,
198203
// so the compiler will not allow it to be captured again
199-
spawn(proc() {
204+
do spawn {
200205
chan.send(some_expensive_computation());
201-
});
206+
}
202207
~~~
203208

204209
Instead we can use a `SharedChan`, a type that allows a single
@@ -212,9 +217,9 @@ let (port, chan) = SharedChan::new();
212217
for init_val in range(0u, 3) {
213218
// Create a new channel handle to distribute to the child task
214219
let child_chan = chan.clone();
215-
spawn(proc() {
220+
do spawn {
216221
child_chan.send(some_expensive_computation(init_val));
217-
});
222+
}
218223
}
219224
220225
let result = port.recv() + port.recv() + port.recv();
@@ -242,9 +247,9 @@ might look like the example below.
242247
// Create a vector of ports, one for each child task
243248
let ports = vec::from_fn(3, |init_val| {
244249
let (port, chan) = Chan::new();
245-
spawn(proc() {
250+
do spawn {
246251
chan.send(some_expensive_computation(init_val));
247-
});
252+
}
248253
port
249254
});
250255
@@ -291,7 +296,7 @@ fn partial_sum(start: uint) -> f64 {
291296
}
292297
293298
fn main() {
294-
let mut futures = vec::from_fn(1000, |ind| extra::future::Future::spawn( proc() { partial_sum(ind) }));
299+
let mut futures = vec::from_fn(1000, |ind| do extra::future::Future::spawn { partial_sum(ind) });
295300
296301
let mut final_res = 0f64;
297302
for ft in futures.mut_iter() {
@@ -334,11 +339,11 @@ fn main() {
334339
let (port, chan) = Chan::new();
335340
chan.send(numbers_arc.clone());
336341
337-
spawn(proc() {
342+
do spawn {
338343
let local_arc : Arc<~[f64]> = port.recv();
339344
let task_numbers = local_arc.get();
340345
println!("{}-norm = {}", num, pnorm(task_numbers, num));
341-
});
346+
}
342347
}
343348
}
344349
~~~
@@ -412,13 +417,13 @@ termination with an error).
412417
# use std::task;
413418
# fn some_condition() -> bool { false }
414419
# fn calculate_result() -> int { 0 }
415-
let result: Result<int, ()> = task::try(proc() {
420+
let result: Result<int, ()> = do task::try {
416421
if some_condition() {
417422
calculate_result()
418423
} else {
419424
fail!("oops!");
420425
}
421-
});
426+
};
422427
assert!(result.is_err());
423428
~~~
424429

@@ -497,9 +502,9 @@ Here is the code for the parent task:
497502
498503
let (from_child, to_child) = DuplexStream::new();
499504
500-
spawn(proc() {
505+
do spawn {
501506
stringifier(&to_child);
502-
});
507+
};
503508
504509
from_child.send(22);
505510
assert!(from_child.recv() == ~"22");

branches/try2/doc/index.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ li {list-style-type: none; }
3737
* [The Rust parser, `libsyntax`](syntax/index.html)
3838
* [The Rust compiler, `librustc`](rustc/index.html)
3939

40-
* [The `arena` allocation library](arena/index.html)
4140
* [The `flate` compression library](flate/index.html)
42-
* [The `glob` file path matching library](glob/index.html)
4341

4442
# Tooling
4543

branches/try2/doc/rust.md

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,6 +2751,52 @@ but must enclose it.
27512751

27522752
A `loop` expression is only permitted in the body of a loop.
27532753

2754+
### Do expressions
2755+
2756+
~~~~ {.ebnf .gram}
2757+
do_expr : "do" expr [ '|' ident_list '|' ] ? '{' block '}' ;
2758+
~~~~
2759+
2760+
A _do expression_ provides a more-familiar block syntax
2761+
for invoking a function and passing it a newly-created a procedure.
2762+
2763+
The optional `ident_list` and `block` provided in a `do` expression are parsed
2764+
as though they constitute a procedure expression;
2765+
if the `ident_list` is missing, an empty `ident_list` is implied.
2766+
2767+
The procedure expression is then provided as a _trailing argument_
2768+
to the outermost [call](#call-expressions) or
2769+
[method call](#method-call-expressions) expression
2770+
in the `expr` following `do`.
2771+
If the `expr` is a [path expression](#path-expressions), it is parsed as though it is a call expression.
2772+
If the `expr` is a [field expression](#field-expressions), it is parsed as though it is a method call expression.
2773+
2774+
In this example, both calls to `f` are equivalent:
2775+
2776+
~~~~
2777+
# fn f(f: proc(int)) { }
2778+
# fn g(i: int) { }
2779+
2780+
f(proc(j) { g(j) });
2781+
2782+
do f |j| {
2783+
g(j);
2784+
}
2785+
~~~~
2786+
2787+
In this example, both calls to the (binary) function `k` are equivalent:
2788+
2789+
~~~~
2790+
# fn k(x:int, f: proc(int)) { }
2791+
# fn l(i: int) { }
2792+
2793+
k(3, proc(j) { l(j) });
2794+
2795+
do k(3) |j| {
2796+
l(j);
2797+
}
2798+
~~~~
2799+
27542800
### For expressions
27552801

27562802
~~~~ {.ebnf .gram}
@@ -2818,14 +2864,15 @@ match_pat : pat [ ".." pat ] ? [ "if" expr ] ;
28182864

28192865
A `match` expression branches on a *pattern*. The exact form of matching that
28202866
occurs depends on the pattern. Patterns consist of some combination of
2821-
literals, destructured enum constructors, structures, records and tuples, variable binding
2822-
specifications, wildcards (`..`), and placeholders (`_`). A `match` expression has a *head
2823-
expression*, which is the value to compare to the patterns. The type of the
2824-
patterns must equal the type of the head expression.
2867+
literals, destructured vectors or enum constructors, structures, records and
2868+
tuples, variable binding specifications, wildcards (`..`), and placeholders
2869+
(`_`). A `match` expression has a *head expression*, which is the value to
2870+
compare to the patterns. The type of the patterns must equal the type of the
2871+
head expression.
28252872

2826-
In a pattern whose head expression has an `enum` type, a placeholder (`_`) stands for a
2827-
*single* data field, whereas a wildcard `..` stands for *all* the fields of a particular
2828-
variant. For example:
2873+
In a pattern whose head expression has an `enum` type, a placeholder (`_`)
2874+
stands for a *single* data field, whereas a wildcard `..` stands for *all* the
2875+
fields of a particular variant. For example:
28292876

28302877
~~~~
28312878
enum List<X> { Nil, Cons(X, ~List<X>) }
@@ -2839,11 +2886,35 @@ match x {
28392886
}
28402887
~~~~
28412888

2842-
The first pattern matches lists constructed by applying `Cons` to any head value, and a
2843-
tail value of `~Nil`. The second pattern matches _any_ list constructed with `Cons`,
2844-
ignoring the values of its arguments. The difference between `_` and `..` is that the pattern
2845-
`C(_)` is only type-correct if `C` has exactly one argument, while the pattern `C(..)` is
2846-
type-correct for any enum variant `C`, regardless of how many arguments `C` has.
2889+
The first pattern matches lists constructed by applying `Cons` to any head
2890+
value, and a tail value of `~Nil`. The second pattern matches _any_ list
2891+
constructed with `Cons`, ignoring the values of its arguments. The difference
2892+
between `_` and `..` is that the pattern `C(_)` is only type-correct if `C` has
2893+
exactly one argument, while the pattern `C(..)` is type-correct for any enum
2894+
variant `C`, regardless of how many arguments `C` has.
2895+
2896+
Used inside a vector pattern, `..` stands for any number of elements. This
2897+
wildcard can be used at most once for a given vector, which implies that it
2898+
cannot be used to specifically match elements that are at an unknown distance
2899+
from both ends of a vector, like `[.., 42, ..]`. If followed by a variable name,
2900+
it will bind the corresponding slice to the variable. Example:
2901+
2902+
~~~~
2903+
fn is_symmetric(list: &[uint]) -> bool {
2904+
match list {
2905+
[] | [_] => true,
2906+
[x, ..inside, y] if x == y => is_symmetric(inside),
2907+
_ => false
2908+
}
2909+
}
2910+
2911+
fn main() {
2912+
let sym = &[0, 1, 4, 2, 4, 1, 0];
2913+
let not_sym = &[0, 1, 7, 2, 4, 1, 0];
2914+
assert!(is_symmetric(sym));
2915+
assert!(!is_symmetric(not_sym));
2916+
}
2917+
~~~~
28472918

28482919
A `match` behaves differently depending on whether or not the head expression
28492920
is an [lvalue or an rvalue](#lvalues-rvalues-and-temporaries).
@@ -2926,7 +2997,7 @@ let z = match x { &0 => "zero", _ => "some" };
29262997
assert_eq!(y, z);
29272998
~~~~
29282999

2929-
A pattern that's just an identifier, like `Nil` in the previous answer,
3000+
A pattern that's just an identifier, like `Nil` in the previous example,
29303001
could either refer to an enum variant that's in scope, or bind a new variable.
29313002
The compiler resolves this ambiguity by forbidding variable bindings that occur
29323003
in `match` patterns from shadowing names of variants that are in scope.

0 commit comments

Comments
 (0)