Skip to content

Commit c8088b7

Browse files
committed
---
yaml --- r: 139247 b: refs/heads/try2 c: 62c1f04 h: refs/heads/master i: 139245: 254b975 139243: 030c99a 139239: a150daf 139231: f7185e7 v: v3
1 parent d4833cd commit c8088b7

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
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: df171e4b6898db92610bcccb22d996d361e16902
8+
refs/heads/try2: 62c1f049f82608446ef80d800d03944e63d2f053
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/RELEASES.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Version 0.6 (March 2013)
22
---------------------------
33

4-
* ~??? changes, numerous bugfixes
4+
* ~2000 changes, numerous bugfixes
55

66
* TODO:
77
* Ord/Cmp
@@ -39,6 +39,8 @@ Version 0.6 (March 2013)
3939
* Newtype enums removed. Used tuple-structs.
4040
* Trait implementations no longer support visibility modifiers
4141
* Pattern matching over vectors improved and expanded
42+
* `const` renamed to `static` to correspond to lifetime name,
43+
and make room for future `static mut` unsafe mutable globals.
4244

4345
* Semantic changes
4446
* Types with owned pointers or custom destructors move by default,
@@ -52,8 +54,9 @@ Version 0.6 (March 2013)
5254
* Name resolution continues to be tweaked
5355
* Method visibility is inherited from the implementation declaration
5456
* Structural records have been removed
55-
* Many more types can be used in constants, including enums,
56-
`static lifetime pointers and vectors
57+
* Many more types can be used in static items, including enums
58+
`static-lifetime pointers and vectors
59+
* Pattern matching over vectors improved and expanded
5760
* Typechecking of closure types has been overhauled to
5861
improve inference and eliminate unsoundness
5962

@@ -85,6 +88,7 @@ Version 0.6 (March 2013)
8588
* Improved foreign function ABI implementation for x86, x86_64
8689
* Various memory usage improvements
8790
* Rust code may be embedded in foreign code under limited circumstances
91+
* Inline assembler supported by new asm!() syntax extension.
8892

8993
Version 0.5 (December 2012)
9094
---------------------------

branches/try2/doc/tutorial-macros.md

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
# Introduction
44

55
Functions are the primary tool that programmers can use to build abstractions.
6-
Sometimes, however, programmers want to abstract over compile-time syntax
7-
rather than run-time values.
8-
Macros provide syntactic abstraction.
9-
For an example of how this can be useful, consider the following two code fragments,
10-
which both pattern-match on their input and both return early in one case,
11-
doing nothing otherwise:
6+
Sometimes, however, programmers want to perform abstractions over things that are not
7+
runtime values. Macros provide a syntactic abstraction. For an example of how this
8+
can be useful, consider the following two code fragments, which both pattern-match
9+
on their input and return early in one case, and do nothing otherwise:
1210

1311
~~~~
1412
# enum t { special_a(uint), special_b(uint) };
@@ -27,10 +25,9 @@ match input_2 {
2725
# }
2826
~~~~
2927

30-
This code could become tiresome if repeated many times.
31-
However, no function can capture its functionality to make it possible
32-
to abstract the repetition away.
33-
Rust's macro system, however, can eliminate the repetition. Macros are
28+
This code could become tiresome if repeated many times. However, no function
29+
can capture its functionality to make it possible to rewrite the repetition
30+
away. Rust's macro system, however, can eliminate the repetition. Macros are
3431
lightweight custom syntax extensions, themselves defined using the
3532
`macro_rules!` syntax extension. The following `early_return` macro captures
3633
the pattern in the above code:
@@ -40,7 +37,7 @@ the pattern in the above code:
4037
# fn f() -> uint {
4138
# let input_1 = special_a(0), input_2 = special_a(0);
4239
macro_rules! early_return(
43-
($inp:expr $sp:ident) => ( // invoke it like `(input_5 special_e)`
40+
($inp:expr $sp:ident) => ( //invoke it like `(input_5 special_e)`
4441
match $inp {
4542
$sp(x) => { return x; }
4643
_ => {}
@@ -96,10 +93,10 @@ that could be invoked like: `my_macro!(i->(( 2+2 )))`.
9693

9794
## Invocation location
9895

99-
A macro invocation may take the place of (and therefore expand to)
100-
an expression, an item, or a statement.
101-
The Rust parser will parse the macro invocation as a "placeholder"
102-
for whichever of those three nonterminals is appropriate for the location.
96+
A macro invocation may take the place of (and therefore expand to) either an
97+
expression, an item, or a statement. The Rust parser will parse the macro
98+
invocation as a "placeholder" for whichever of those three nonterminals is
99+
appropriate for the location.
103100

104101
At expansion time, the output of the macro will be parsed as whichever of the
105102
three nonterminals it stands in for. This means that a single macro might,
@@ -115,19 +112,17 @@ The right-hand side of the `=>` follows the same rules as the left-hand side,
115112
except that a `$` need only be followed by the name of the syntactic fragment
116113
to transcribe into the macro expansion; its type need not be repeated.
117114

118-
The right-hand side must be enclosed by delimiters, which the transcriber ignores.
119-
Therefore `() => ((1,2,3))` is a macro that expands to a tuple expression,
120-
`() => (let $x=$val)` is a macro that expands to a statement,
121-
and `() => (1,2,3)` is a macro that expands to a syntax error
122-
(since the transcriber interprets the parentheses on the right-hand-size as delimiters,
123-
and `1,2,3` is not a valid Rust expression on its own).
115+
The right-hand side must be enclosed by delimiters, which are ignored by the
116+
transcriber (therefore `() => ((1,2,3))` is a macro that expands to a tuple
117+
expression, `() => (let $x=$val)` is a macro that expands to a statement, and
118+
`() => (1,2,3)` is a macro that expands to a syntax error).
124119

125120
Except for permissibility of `$name` (and `$(...)*`, discussed below), the
126121
right-hand side of a macro definition is ordinary Rust syntax. In particular,
127122
macro invocations (including invocations of the macro currently being defined)
128123
are permitted in expression, statement, and item locations. However, nothing
129124
else about the code is examined or executed by the macro system; execution
130-
still has to wait until run-time.
125+
still has to wait until runtime.
131126

132127
## Interpolation location
133128

@@ -292,6 +287,7 @@ A macro may accept multiple different input grammars. The first one to
292287
successfully match the actual argument to a macro invocation is the one that
293288
"wins".
294289

290+
295291
In the case of the example above, we want to write a recursive macro to
296292
process the semicolon-terminated lines, one-by-one. So, we want the following
297293
input patterns:
@@ -373,19 +369,19 @@ return result + val;
373369
# }
374370
~~~~
375371

376-
This technique applies to many cases where transcribing a result all at once is not possible.
377-
The resulting code resembles ordinary functional programming in some respects,
378-
but has some important differences from functional programming.
372+
This technique is applicable in many cases where transcribing a result "all
373+
at once" is not possible. It resembles ordinary functional programming in some
374+
respects, but it is important to recognize the differences.
379375

380376
The first difference is important, but also easy to forget: the transcription
381377
(right-hand) side of a `macro_rules!` rule is literal syntax, which can only
382378
be executed at run-time. If a piece of transcription syntax does not itself
383379
appear inside another macro invocation, it will become part of the final
384380
program. If it is inside a macro invocation (for example, the recursive
385-
invocation of `biased_match_rec!`), it does have the opportunity to affect
381+
invocation of `biased_match_rec!`), it does have the opprotunity to affect
386382
transcription, but only through the process of attempted pattern matching.
387383

388-
The second, related, difference is that the evaluation order of macros feels
384+
The second difference is related: the evaluation order of macros feels
389385
"backwards" compared to ordinary programming. Given an invocation
390386
`m1!(m2!())`, the expander first expands `m1!`, giving it as input the literal
391387
syntax `m2!()`. If it transcribes its argument unchanged into an appropriate

0 commit comments

Comments
 (0)