This file shows a number of syntax equivalences in the compiler.
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.
You could even start expanding out the equivalent of (1..10) which is really a shortcut for series(1, nil, 10)
. This could also be written 1.series(nil,10)
. This adds another 26 variations to the 13 variations above.
instead of writing: | you can write: |
f(x, y) | x.f(y) |
f(g(x)) | x.g.f |
instead of writing: | you can write: |
| Thing { var <>x; } |
instead of writing: | you can write: |
p.x_(y) | p.x = y or x(p) = y |
instead of writing: | you can write: |
min(x, y) | x min: y |
instead of writing: | you can write: |
Point.new(3, 4); | Point(3, 4) |
instead of writing: | you can write: |
if (x<3, {\abc}, {\def}); | if (x<3) {\abc} {\def} |
z.do({|x| x.play }); | z.do {|x| x.play }; |
while({ a < b },{ a = a * 2 }); | while { a < b } { a = a * 2 }; |
instead of writing: | you can write: |
{ arg x; x < 2 } | {|x| x < 2 } |
{ arg x = 123; x < 2 } | {|x = 123| x < 2 } |
{ arg x = 10.rand; x < 2 } | {|x = (10.rand)| x < 2 } or {|x(10.rand)| x < 2 } |
NOTE: When using the new ||
syntax, the default value needs to be enclosed in parenthesis if it's not a literal.
instead of writing: | you can write: |
f.value(x) | f.(x) |
instead of writing: | you can write: |
object.performList(\method, a, b, array) | object.method(a, b, *array) |
instead of writing: | you can write: |
{|x| object.msg(a, x, b) } | object.msg(a, _, b) |
{|x,y| object.msg(a, x, y) } | object.msg(a, _, _) |
{|x| a + x } | a + _ |
{|x| [a, b, x] } | [a, b, _] |
{|x| (a: x) } | (a: _) |
instead of writing: | you can write: |
Set.new.add(3).add(4).add(5); | Set[3, 4, 5] |
Array[3, 4, 5]; | [3, 4, 5] |
instead of writing: | you can write: |
z.at(i) | z[i] |
z.put(i, y); | z[i] = y; |
instead of writing: | you can write: |
Event[\a -> 1, \b -> 2] | (a: 1, b: 2) |
instead of writing: | you can write: |
[\a, 1, \b, 2] | [a: 1, b: 2] |
instead of writing: | you can write: |
Array.series(16,1,1) or series(1,nil,16) | (1..16) |
Array.series(6,1,2) or series(1,3,11) | (1,3..11) |
There is also the similar syntax for creating an iterating Routine :
instead of writing: | you can write: |
seriesIter(1,3,11) | (:1,3..11) |
instead of writing: | you can write: |
a.copyRange(4,8) | a[4..8] |
a.copyToEnd(4) | a[4..] |
a.copyFromStart(4) | a[..4] |
instead of writing: | you can write: |
x = z.at(0); y = z.at(1); | # x, y = z; |
instead of writing: | you can write: |
'myName'.envirGet | ~myName |
'myName'.envirPut(9); | ~myName = 9; |
instead of writing: | you can write: |
'mySymbol' | \mySymbol |
instead of writing: | you can write: |
Ref.new(thing) | `thing |