@@ -1305,14 +1305,14 @@ An example function that accepts an alias parameter:
1305
1305
@example
1306
1306
type point3d = @{ x: int, y: int, z: int@} ;
1307
1307
1308
- fn extract_z(&point3d p ) -> int @{
1308
+ fn extract_z(p: &point3d) -> int @{
1309
1309
ret p.z;
1310
1310
@}
1311
1311
@end example
1312
1312
1313
1313
An example function that accepts an alias to a mutable value:
1314
1314
@example
1315
- fn incr(& mutable int i ) @{
1315
+ fn incr(i: & mutable int) @{
1316
1316
i = i + 1;
1317
1317
@}
1318
1318
@end example
@@ -1360,10 +1360,10 @@ indicated with the unary @emph{star} operator @code{*}. Examples of such
1360
1360
1361
1361
An example of an explicit-dereference operation performed on box values:
1362
1362
@example
1363
- fn takes_boxed(@@ int b ) @{
1363
+ fn takes_boxed(b: @@ int) @{
1364
1364
@}
1365
1365
1366
- fn takes_unboxed(int b ) @{
1366
+ fn takes_unboxed(b: int ) @{
1367
1367
@}
1368
1368
1369
1369
fn main() @{
@@ -1716,7 +1716,7 @@ mod foo @{
1716
1716
helper(3, 4);
1717
1717
@}
1718
1718
1719
- fn helper(int x, int y ) @{
1719
+ fn helper(x: int, y: int ) @{
1720
1720
@dots {}
1721
1721
@}
1722
1722
@}
@@ -1754,15 +1754,15 @@ during compilation, returning the implicit @code{()} value.
1754
1754
1755
1755
An example of a function:
1756
1756
@example
1757
- fn add(int x, int y ) -> int @{
1757
+ fn add(x: int, y: int ) -> int @{
1758
1758
ret x + y;
1759
1759
@}
1760
1760
@end example
1761
1761
1762
1762
A special kind of function can be declared with a @code {! } character where the
1763
1763
output slot type would normally be. For example:
1764
1764
@example
1765
- fn my_err(str s ) -> ! @{
1765
+ fn my_err(s: str ) -> ! @{
1766
1766
log s;
1767
1767
fail;
1768
1768
@}
@@ -1781,7 +1781,7 @@ with a @code{ret}, @code{be}, or diverging expression. So, if @code{my_err}
1781
1781
were declared without the @code {! } annotation, the following code would not
1782
1782
typecheck:
1783
1783
@example
1784
- fn f(int i ) -> int @{
1784
+ fn f(i: int ) -> int @{
1785
1785
if (i == 42) @{
1786
1786
ret 42;
1787
1787
@}
@@ -1849,7 +1849,7 @@ each} loop or as the argument in a @code{put each} expression.
1849
1849
1850
1850
An example of an iterator:
1851
1851
@example
1852
- iter range(int lo, int hi) -> int @{
1852
+ iter range(lo: int, hi: int ) -> int @{
1853
1853
let i: int = lo;
1854
1854
while (i < hi) @{
1855
1855
put i;
@@ -1881,16 +1881,16 @@ constructor function when used in value context (such as a call).
1881
1881
1882
1882
Example of an object item:
1883
1883
@example
1884
- obj counter(int state) @{
1884
+ obj counter(state: @@ mutable int ) @{
1885
1885
fn incr() @{
1886
- state += 1;
1886
+ * state += 1;
1887
1887
@}
1888
1888
fn get() -> int @{
1889
- ret state;
1889
+ ret * state;
1890
1890
@}
1891
1891
@}
1892
1892
1893
- let c: counter = counter(1);
1893
+ let c: counter = counter(@@ mutable 1);
1894
1894
1895
1895
c.incr();
1896
1896
c.incr();
@@ -2287,7 +2287,7 @@ slot. @xref{Ref.Item.Fn}.
2287
2287
2288
2288
An example of a @code {fn } type:
2289
2289
@example
2290
- fn add(int x, int y ) -> int @{
2290
+ fn add(x: int, y: int ) -> int @{
2291
2291
ret x + y;
2292
2292
@}
2293
2293
@@ -2308,7 +2308,7 @@ constraints and an output slot. @xref{Ref.Item.Iter}.
2308
2308
2309
2309
An example of an @code {iter } type:
2310
2310
@example
2311
- iter range(int x, int y ) -> int @{
2311
+ iter range(x: int, y: int ) -> int @{
2312
2312
while (x < y) @{
2313
2313
put x;
2314
2314
x += 1;
@@ -2433,31 +2433,31 @@ a client function using both items via the object type:
2433
2433
@example
2434
2434
2435
2435
type taker =
2436
- state obj @{
2436
+ obj @{
2437
2437
fn take(int);
2438
2438
@} ;
2439
2439
2440
- obj adder(mutable int x ) @{
2441
- fn take(int y ) @{
2442
- x += y;
2440
+ obj adder(x: @@ mutable int) @{
2441
+ fn take(y: int ) @{
2442
+ * x += y;
2443
2443
@}
2444
2444
@}
2445
2445
2446
- obj sender(chan[int] c ) @{
2447
- fn take(int z ) @{
2446
+ obj sender(c: chan[int]) @{
2447
+ fn take(z: int ) @{
2448
2448
c <| z;
2449
2449
@}
2450
2450
@}
2451
2451
2452
- fn give_ints(taker t ) @{
2452
+ fn give_ints(t: taker ) @{
2453
2453
t.take(1);
2454
2454
t.take(2);
2455
2455
t.take(3);
2456
2456
@}
2457
2457
2458
2458
let p: port[int] = port();
2459
2459
2460
- let t1: taker = adder(0);
2460
+ let t1: taker = adder(@@ mutable 0);
2461
2461
let t2: taker = sender(chan(p));
2462
2462
2463
2463
give_ints(t1);
@@ -2939,7 +2939,7 @@ The result of a @code{spawn} expression is a @code{task} value.
2939
2939
2940
2940
An example of a @code {spawn } expression:
2941
2941
@example
2942
- fn helper(chan[u8] out ) @{
2942
+ fn helper(out: chan[u8]) @{
2943
2943
// do some work.
2944
2944
out <| result;
2945
2945
@}
@@ -3033,7 +3033,7 @@ and residual arguments that was specified during the binding.
3033
3033
3034
3034
An example of a @code {bind } expression:
3035
3035
@example
3036
- fn add(int x, int y ) -> int @{
3036
+ fn add(x: int, y: int ) -> int @{
3037
3037
ret x + y;
3038
3038
@}
3039
3039
type single_param_fn = fn(int) -> int;
@@ -3070,7 +3070,7 @@ and transfers control to the caller frame.
3070
3070
3071
3071
An example of a @code {ret } expression:
3072
3072
@example
3073
- fn max(int a, int b ) -> int @{
3073
+ fn max(a: int, b: int ) -> int @{
3074
3074
if (a > b) @{
3075
3075
ret a;
3076
3076
@}
@@ -3094,7 +3094,7 @@ last expression in a block.
3094
3094
3095
3095
An example of a @code {be } expression:
3096
3096
@example
3097
- fn print_loop(int n ) @{
3097
+ fn print_loop(n: int ) @{
3098
3098
if (n <= 0) @{
3099
3099
ret;
3100
3100
@} else @{
@@ -3182,7 +3182,7 @@ diagnostic buffer.
3182
3182
3183
3183
An example of a @code {note } expression:
3184
3184
@example
3185
- fn read_file_lines(&str path ) -> vec[str] @{
3185
+ fn read_file_lines(path: &str) -> vec[str] @{
3186
3186
note path;
3187
3187
let r: vec[str];
3188
3188
let f: file = open_read(path);
@@ -3514,11 +3514,11 @@ and statically comparing implied states and their
3514
3514
specifications. @xref {Ref.Typestate }.
3515
3515
3516
3516
@example
3517
- pred even(&int x ) -> bool @{
3517
+ pred even(x: &int) -> bool @{
3518
3518
ret x & 1 == 0;
3519
3519
@}
3520
3520
3521
- fn print_even(int x ) : even(x) @{
3521
+ fn print_even(x: int ) : even(x) @{
3522
3522
print(x);
3523
3523
@}
3524
3524
0 commit comments