doc: add var syntax samples

This commit is contained in:
2025-04-15 11:05:52 +01:00
parent ae35c15f78
commit ccb31ae545
4 changed files with 26 additions and 23 deletions

View File

@@ -1,30 +1,30 @@
y = 1 + 2 * 3 / 4 * 5 - 6 + 7 multiplyBy:2. var y = 1 + 2 * 3 / 4 * 5 - 6 + 7 multiplyBy:2.
z = w = 2 + 3 multiplyBy:2. var z = w = 2 + 3 multiplyBy:2.
x = (((1 + 2 * 3) multiplyBy:3) add: 5) + 2. var x = (((1 + 2 * 3) multiplyBy:3) add: 5) + 2.
x = ((1 + 2 * 3) multiplyBy:3). x = ((1 + 2 * 3) multiplyBy:3).
p = 5 multiply(by:3 add:(2 + 1)). var p = 5 multiply(by:3 add:(2 + 1)).
q = 10 squared squared. var q = 10 squared squared.
p1 p1
setAge:2 squared squared + 4 squared multiply(by:2 add:4 + 1 * 3) setAge:2 squared squared + 4 squared multiply(by:2 add:4 + 1 * 3)
in:"mon" + "ths". in:"mon" + "ths".
M = xz multiply(by:3 add:2) squared. var m = xz multiply(by:3 add:2) squared.
M = xz multiply(by:3 add:2); squared. m = xz multiply(by:3 add:2); squared.
x = OrderedCollection new var x = OrderedCollection new
add: 2; add: 2;
add: 4; add: 4;
add: 6; add: 6;
yourself. yourself.
age = Person new(name:"John Doe" age:34) var age = Person new(name:"John Doe" age:34)
setAge:144 inUnit:"months"; setAge:144 inUnit:"months";
ageInMonths. ageInMonths.
x = 5. x = 5.
q = 10 if x > 2. var q = 10 if x > 2 else 20.
q = if x > 2 then 10 else 20 end. q = if x > 2 then 10 else 20 end.
cout put:5 multiply(by:5 add:2) if x > 2. cout put:5 multiply(by:5 add:2) if x > 2.
@@ -35,7 +35,7 @@ else
cout put:"Less" cout put:"Less"
end end
Q = match yz in var q = match yz in
1 => age = age, 1 => age = age,
2 => age = age / 12, 2 => age = age / 12,
3 => age = age / 365, 3 => age = age / 365,
@@ -53,14 +53,14 @@ end
cout put:"message" while x > 2. cout put:"message" while x > 2.
cout put:'Count is {i}' for i in 0 to:100 step:2. cout put:'Count is {i}' for i in 0 to:100 step:2.
z = do var z = do
x = 1. var x = 1.
y = 2. var y = 2.
^x + y ^x + y
end. end.
j = [ cout put:'Hello!' ]. var j = [ cout put:'Hello!' ].
k = [ :x :y | cout put:'Hello, {x}, {y}!' ]. var k = [ :x :y | cout put:'Hello, {x}, {y}!' ].
x > 2 x > 2
if:[ cout put:'True' ] if:[ cout put:'True' ]
@@ -70,7 +70,7 @@ x > 2
p1 test(param:'Hello' :'World'). p1 test(param:'Hello' :'World').
pkg = {}. var pkg = {}.
pkg = { 0 }. pkg = { 0 }.
pkg = { 1, 2, 3, 4, 5 }. pkg = { 1, 2, 3, 4, 5 }.
pkg = { 10, 2 => "Hello", 9, 5 => "World", 14 }. pkg = { 10, 2 => "Hello", 9, 5 => "World", 14 }.
@@ -92,11 +92,11 @@ pkg['x'] = 32.
pkg->x = 32. pkg->x = 32.
pkg at:'x' put:32. pkg at:'x' put:32.
v = pkg['x']. var v = pkg['x'].
v = pkg->x. v = pkg->x.
v = pkg at:'x'. v = pkg at:'x'.
pkg2 = { var pkg2 = {
onEnter => [ onEnter => [
cout put:'start!' cout put:'start!'
], ],
@@ -106,6 +106,6 @@ pkg2 = {
] ]
}. }.
index = 'x'. var index = 'x'.
pkg[index] = 32. pkg[index] = 32.
pkg at:index put:32. pkg at:index put:32.

1
doc/sample/Person.im Executable file → Normal file
View File

@@ -48,6 +48,7 @@ class Person
compatibility with lambdas. compatibility with lambdas.
**/ **/
- init(name:name age:age) - init(name:name age:age)
var x.
self::name = name. self::name = name.
self::age = age! self::age = age!

View File

@@ -1,3 +1 @@
v = 2 + 3 * 4. 2 + 3 * 4.
cout put:v

4
doc/sample/Var.im Normal file
View File

@@ -0,0 +1,4 @@
var x = 2 + 3.
var y = x.
var z.
var (x, y) = (3, 4).