1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
7 <meta name=
"Generator" content=
"Cocoa HTML Writer">
8 <meta name=
"CocoaVersion" content=
"824.42">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; min-height: 14.0px}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco
}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco
; min-height: 16.0px}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica
}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica
; min-height: 17.0px}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco
; color: #a71e12}
18 span
.s1
{color: #0019b7}
19 span
.s2
{color: #a71e12}
20 span
.s3
{color: #000000}
21 span
.s4
{font: 12.0px Monaco
}
22 span
.s5
{font: 12.0px Helvetica
}
23 span
.Apple-tab-span
{white-space:pre
}
27 <p class=
"p1"><b>Syntax Shortcuts
</b></p>
28 <p class=
"p2"><br></p>
29 <p class=
"p3">This file shows a number of syntax equivalences in the compiler.
</p>
30 <p class=
"p2"><br></p>
31 <p class=
"p4">__________________________________________________________________________
</p>
32 <p class=
"p5"><br></p>
33 <p class=
"p6"><b>Example: multiple ways to write the same thing.
</b></p>
34 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b></p>
35 <p class=
"p3">Because of the multiple syntax equivalences, some expressions can be written in many different ways. All of the following do the same thing and compile to the same code.
<span class=
"Apple-converted-space"> </span></p>
36 <p class=
"p5"><br></p>
37 <p class=
"p8">// new argument syntax
</p>
38 <p class=
"p5"><br></p>
39 <p class=
"p4">(
1.
.10).collect({
<span class=
"s1">|n|
</span> n.squared });
<span class=
"s2">// receiver syntax
</span></p>
40 <p class=
"p5"><br></p>
41 <p class=
"p4">collect((
1.
.10), {
<span class=
"s1">|n|
</span> n.squared });
<span class=
"s2">// function call syntax
</span></p>
42 <p class=
"p5"><br></p>
43 <p class=
"p8"><span class=
"s3">(
1.
.10).collect {
</span><span class=
"s1">|n|
</span><span class=
"s3"> n.squared };
</span>// receiver syntax with trailing function arg
</p>
44 <p class=
"p5"><br></p>
45 <p class=
"p8"><span class=
"s3">collect ((
1.
.10)) {
</span><span class=
"s1">|n|
</span><span class=
"s3"> n.squared };
</span>// function call syntax with trailing function arg
</p>
46 <p class=
"p5"><br></p>
47 <p class=
"p4">(
1.
.10) collect: {
<span class=
"s1">|n|
</span> n.squared };
<span class=
"s2">// binary operator syntax
</span></p>
48 <p class=
"p5"><br></p>
49 <p class=
"p5"><br></p>
50 <p class=
"p8">// old argument syntax
</p>
51 <p class=
"p5"><br></p>
52 <p class=
"p4">(
1.
.10).collect({
<span class=
"s1">arg
</span> n; n.squared });
<span class=
"s2">// receiver syntax
</span></p>
53 <p class=
"p5"><br></p>
54 <p class=
"p4">collect((
1.
.10), {
<span class=
"s1">arg
</span> n; n.squared });
<span class=
"s2">// function call syntax
</span></p>
55 <p class=
"p5"><br></p>
56 <p class=
"p8"><span class=
"s3">(
1.
.10).collect {
</span><span class=
"s1">arg
</span><span class=
"s3"> n; n.squared };
</span>// receiver syntax with trailing function arg
</p>
57 <p class=
"p5"><br></p>
58 <p class=
"p8"><span class=
"s3">collect ((
1.
.10)) {
</span><span class=
"s1">arg
</span><span class=
"s3"> n; n.squared };
</span>// function call syntax with trailing function arg
</p>
59 <p class=
"p5"><br></p>
60 <p class=
"p4">(
1.
.10) collect: {
<span class=
"s1">arg
</span> n; n.squared };
<span class=
"s2">// binary operator syntax
</span></p>
61 <p class=
"p5"><br></p>
62 <p class=
"p5"><br></p>
63 <p class=
"p8">// partial application syntax
</p>
64 <p class=
"p5"><br></p>
65 <p class=
"p4">(
1.
.10).collect( _.squared );
<span class=
"s2">// receiver syntax
</span></p>
66 <p class=
"p5"><br></p>
67 <p class=
"p4">collect((
1.
.10), _.squared );
<span class=
"s2">// function call syntax
</span></p>
68 <p class=
"p5"><br></p>
69 <p class=
"p4">(
1.
.10) collect: _.squared ;
<span class=
"s2">// binary operator syntax
</span></p>
70 <p class=
"p5"><br></p>
71 <p class=
"p5"><br></p>
72 <p class=
"p3">You could even start expanding out the equivalent of
<span class=
"s4">(
1.
.10)
</span> which is really a shortcut for
<span class=
"s4">series(
1, nil,
10)
</span>. This could also be written
<span class=
"s4">1.series(nil,
10)
</span>. This adds another
26 variations to the
13 variations above.
</p>
73 <p class=
"p2"><br></p>
74 <p class=
"p4">__________________________________________________________________________
</p>
75 <p class=
"p2"><br></p>
76 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>functional and receiver notation
</b></p>
77 <p class=
"p2"><br></p>
78 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
79 <p class=
"p2"><br></p>
80 <p class=
"p4">f(x, y)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>x.f(y)
</p>
81 <p class=
"p4">f(g(x))
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>x.g.f
</p>
82 <p class=
"p5"><br></p>
83 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>defining instance variable accessor methods
</b></p>
84 <p class=
"p2"><br></p>
85 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
86 <p class=
"p2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b><span class=
"Apple-tab-span"> </span></b></p>
87 <p class=
"p4">Thing { var x;
<span class=
"Apple-converted-space"> <span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>Thing { var
<>x; }
<span class=
"s5"><b><span class=
"Apple-tab-span"> </span></b></span></p>
88 <p class=
"p4"><span class=
"Apple-tab-span"> </span>x { ^x }
<span class=
"Apple-converted-space"> </span></p>
89 <p class=
"p4"><span class=
"Apple-tab-span"> </span>x_ { arg z; x = z; }
<span class=
"Apple-converted-space"> </span></p>
90 <p class=
"p4">}
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
91 <p class=
"p2"><br></p>
92 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>calling an instance variable setter method
</b></p>
93 <p class=
"p2"><br></p>
94 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
95 <p class=
"p2"><br></p>
96 <p class=
"p4">p.x_(y)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>p.x = y;
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
97 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>use a selector as binary operator
</b></p>
98 <p class=
"p5"><br></p>
99 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
100 <p class=
"p2"><br></p>
101 <p class=
"p4">min(x, y)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>x min: y
</p>
102 <p class=
"p5"><br></p>
103 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>multiple assignment
</b></p>
104 <p class=
"p5"><br></p>
105 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
106 <p class=
"p2"><br></p>
107 <p class=
"p4">x = z.at(
0); y = z.at(
1);
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span># x, y = z;
</p>
108 <p class=
"p5"><br></p>
109 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>get environment variable
</b></p>
110 <p class=
"p5"><br></p>
111 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
112 <p class=
"p2"><br></p>
113 <p class=
"p4">'myName'.envirGet
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~myName
</p>
114 <p class=
"p5"><br></p>
115 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>set environment variable
</b></p>
116 <p class=
"p5"><br></p>
117 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
118 <p class=
"p2"><br></p>
119 <p class=
"p4">'myName'.envirSet(
9);
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~myName =
9;
</p>
120 <p class=
"p5"><br></p>
121 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>instantiate object
</b></p>
122 <p class=
"p5"><br></p>
123 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
124 <p class=
"p2"><br></p>
125 <p class=
"p4">Point.new(
3,
4);
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Point(
3,
4)
</p>
126 <p class=
"p5"><br></p>
127 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>create a collection
</b></p>
128 <p class=
"p5"><br></p>
129 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
130 <p class=
"p2"><br></p>
131 <p class=
"p4">Set.new.add(
3).add(
4).add(
5);
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Set[
3,
4,
5]
</p>
132 <p class=
"p5"><br></p>
133 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>moving blocks out of argument lists
</b></p>
134 <p class=
"p5"><br></p>
135 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
136 <p class=
"p2"><br></p>
137 <p class=
"p4">if (x
<3, {\abc}, {\def});
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>if (x
<3) {\abc} {\def}
</p>
138 <p class=
"p5"><br></p>
139 <p class=
"p4">z.do({|x| x.play });
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>z.do {|x| x.play };
</p>
140 <p class=
"p5"><br></p>
141 <p class=
"p4">while({ a
< b },{ a = a *
2 });
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>while { a
< b } { a = a *
2 };
</p>
142 <p class=
"p5"><br></p>
143 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>shorter argument lists
</b></p>
144 <p class=
"p5"><br></p>
145 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
146 <p class=
"p2"><br></p>
147 <p class=
"p4">{ arg x; x
< 2 }
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>{|x| x
< 2 }
</p>
148 <p class=
"p5"><br></p>
149 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>shorthand for Symbols
</b></p>
150 <p class=
"p5"><br></p>
151 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
152 <p class=
"p2"><br></p>
153 <p class=
"p4">'mySymbol'
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>\mySymbol
</p>
154 <p class=
"p5"><br></p>
155 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>creating a Ref
</b></p>
156 <p class=
"p5"><br></p>
157 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
158 <p class=
"p2"><br></p>
159 <p class=
"p4">Ref.new(thing)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>`thing
</p>
160 <p class=
"p5"><br></p>
161 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>calling the 'value' method
</b></p>
162 <p class=
"p5"><br></p>
163 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
164 <p class=
"p2"><br></p>
165 <p class=
"p4">f.value(x)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>f.(x)
</p>
166 <p class=
"p5"><br></p>
167 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>indexing with 'at'
</b></p>
168 <p class=
"p5"><br></p>
169 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
170 <p class=
"p2"><br></p>
171 <p class=
"p4">z.at(i)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>z[i]
</p>
172 <p class=
"p5"><br></p>
173 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>indexing with 'put'
</b></p>
174 <p class=
"p5"><br></p>
175 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
176 <p class=
"p2"><br></p>
177 <p class=
"p4">z.put(i, y);
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>z[i] = y;
</p>
178 <p class=
"p5"><br></p>
179 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>creating IdentityDictionaries
</b></p>
180 <p class=
"p5"><br></p>
181 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
182 <p class=
"p2"><br></p>
183 <p class=
"p4">IdentityDictionary['a'-
>1,'b'-
>2]
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>(a:
1, b:
2)
</p>
184 <p class=
"p5"><br></p>
185 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>creating arithmetic series
</b></p>
186 <p class=
"p5"><br></p>
187 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
188 <p class=
"p2"><br></p>
189 <p class=
"p4">Array.series(
16,
1,
1)
<span class=
"s5"><i>, or
<span class=
"Apple-converted-space"> </span></i></span>series(
1,nil,
16)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>(
1.
.16)
</p>
190 <p class=
"p5"><br></p>
191 <p class=
"p4">Array.series(
6,
1,
2)
<span class=
"s5"><i>, or
<span class=
"Apple-converted-space"> </span></i></span>series(
1,
3,
11)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>(
1,
3.
.11)
</p>
192 <p class=
"p5"><br></p>
193 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>accessing subranges of Arrays
</b></p>
194 <p class=
"p5"><br></p>
195 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
196 <p class=
"p2"><br></p>
197 <p class=
"p4">a.copyRange(
4,
8)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>a[
4.
.8]
</p>
198 <p class=
"p5"><br></p>
199 <p class=
"p4">a.copyToEnd(
4)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>a[
4..]
</p>
200 <p class=
"p5"><br></p>
201 <p class=
"p4">a.copyFromStart(
4)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>a[.
.4]
</p>
202 <p class=
"p5"><br></p>
203 <p class=
"p5"><br></p>
204 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>calling performList
</b></p>
205 <p class=
"p5"><br></p>
206 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
207 <p class=
"p2"><br></p>
208 <p class=
"p4">object.performList(\method, a, b, array)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>object.method(a, b, *array)
</p>
209 <p class=
"p5"><br></p>
210 <p class=
"p5"><br></p>
211 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>partial application
</b></p>
212 <p class=
"p5"><br></p>
213 <p class=
"p3"><b>instead of writing:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>you can write:
</b></p>
214 <p class=
"p2"><br></p>
215 <p class=
"p4">{|x| object.msg(a, x, b) }
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>object.msg(a, _, b)
</p>
216 <p class=
"p5"><br></p>
217 <p class=
"p4">{|x,y| object.msg(a, x, y) }
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>object.msg(a, _, _)
</p>
218 <p class=
"p5"><br></p>
219 <p class=
"p4">{|x| a + x }
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>a + _
</p>
220 <p class=
"p5"><br></p>
221 <p class=
"p4">{|x| [a, b, x] }
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>[a, b, _]
</p>
222 <p class=
"p5"><br></p>
223 <p class=
"p4">{|x| (a: x) }
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>(a: _)
</p>
224 <p class=
"p5"><br></p>
225 <p class=
"p5"><br></p>
226 <p class=
"p5"><br></p>
227 <p class=
"p4">__________________________________________________________________________
</p>