doc: sample: switch to kebab-case

This commit is contained in:
2025-11-07 10:07:44 +00:00
parent c8f0be14a1
commit 77791d91e3
9 changed files with 66 additions and 67 deletions

View File

@@ -1,9 +1,9 @@
pkg2 = { pkg2 = {
onEnter => [ on-enter => [
cout put:'start!' cout put:'start!'
], ],
onExit => [ on-exit => [
cout put:'end!' cout put:'end!'
] ]
}. }.

View File

@@ -15,32 +15,31 @@ while true do
end end
end end
shiftWidth = 0 shift-width = 0
while true do while true do
cout print:'Shift size: ' cout print:'Shift size: '
cout flush cout flush
shiftStr = '' shift-str = cin read-line.
cin get:shiftStr
if shiftStr == '' then if shift-str == '' then
continue continue
end end
try try
shiftWidth = Int parse:shiftStr shift-width = Int parse:shift-str
catch (#err:number_format, err) catch ($err:number-format, err)
continue continue
end end
break break
end end
encodedMessage = '' encoded-message = ''
for c in message do for c in message do
i = c toOrdinal i = c to-ordinal
sub = 0 sub = 0
if i >= 65 && i <= 90 then if i >= 65 && i <= 90 then
@@ -52,14 +51,14 @@ for c in message do
end end
i -= sub i -= sub
i += shiftWidth i += shift-width
if i >= 26 then if i >= 26 then
i -= 26 i -= 26
end end
c2 = i toChar c2 = i to-char
encodedMessage += c2 encoded-message += c2
end end
cout put:encodedMessage cout put:encoded-message

View File

@@ -1,7 +1,7 @@
try try
x = 0 x = 0
--v = Int parse:'342' --v = Int parse:'342'
catch ($err:number_format, err) in catch ($err:number-format, err) in
x = 1 x = 1
--cout put:'Cannot parse integer string ({err})' --cout put:'Cannot parse integer string ({err})'
catch (_, err) in catch (_, err) in

View File

@@ -1,12 +1,12 @@
y = 1 + 2 * 3 / 4 * 5 - 6 + 7 multiplyBy:2. y = 1 + 2 * 3 / 4 * 5 - 6 + 7 multiply-by:2.
z = w = 2 + 3 multiplyBy:2. z = w = 2 + 3 multiply-by:2.
x = (((1 + 2 * 3) multiplyBy:3) add: 5) + 2. x = (((1 + 2 * 3) multiply-by:3) add: 5) + 2.
x = ((1 + 2 * 3) multiplyBy:3). x = ((1 + 2 * 3) multiply-by:3).
p = 5 multiply(by:3, add:(2 + 1)). p = 5 multiply(by:3, add:(2 + 1)).
q = 10 squared squared. q = 10 squared squared.
p1 p1
setAge:2 squared squared + 4 squared multiply(by:2, add:4 + 1 * 3) set-age: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. m = xz multiply(by:3 add:2) squared.
@@ -20,7 +20,7 @@ x = OrderedCollection new
yourself. yourself.
age = Person new(name:"John Doe", age:34) age = Person new(name:"John Doe", age:34)
setAge:144 inUnit:"months"; set-age:144 in-unit:"months";
ageInMonths. ageInMonths.
x = 5. x = 5.
@@ -76,10 +76,10 @@ pkg = { 1, 2, 3, 4, 5 }.
pkg = { 10, 2 => "Hello", 9, 5 => "World", 14 }. pkg = { 10, 2 => "Hello", 9, 5 => "World", 14 }.
pkg = { { 0 }, { 1 }, { y for y in huh } }. pkg = { { 0 }, { 1 }, { y for y in huh } }.
pkg = { x multiplyBy:2 for x in wow if x > 2 }. pkg = { x multiply-by:2 for x in wow if x > 2 }.
pkg->x = 32. pkg->x = 32.
k = (1 multiplyBy:2, 4). k = (1 multiply-by:2, 4).
for (x, y) in pkg do for (x, y) in pkg do
cout put:'{x}: {y}' cout put:'{x}: {y}'
@@ -97,11 +97,11 @@ v = pkg->x.
v = pkg at:'x'. v = pkg at:'x'.
pkg2 = { pkg2 = {
onEnter => [ on-enter => [
cout put:'start!' cout put:'start!'
], ],
onExit => [ on-exit => [
cout put:'end!' cout put:'end!'
] ]
}. }.

View File

@@ -58,13 +58,13 @@ class Person
- age | ^self::age. - age | ^self::age.
- ageInMonths | ^self::age * 12. - age-in-months | ^self::age * 12.
- setName:name | self::name = name. - set-name:name | self::name = name.
- setAge:age | self::age = age. - set-age:age | self::age = age.
- setAge:age inUnit:units - set-age:age in-unit:units
match units in match units in
$years => self::age = age, $years => self::age = age,
$months => self::age = age / 12, $months => self::age = age / 12,
@@ -72,7 +72,7 @@ class Person
_ => self::age = 0 _ => self::age = 0
end! end!
- getAgeInUnit:units - get-age-in-units:units
^match units in ^match units in
$years => self::age, $years => self::age,
$months => self::age / 12, $months => self::age / 12,
@@ -104,12 +104,12 @@ class Person
is converted to the lambda is converted to the lambda
[ :x | self::val = x ] [ :x | self::val = x ]
*/ */
-> exampleProperty | get => self::val, set => self::val = value. -> example-property | get => self::val, set => self::val = value.
/* Without the lambda synthesis, the property would look like this: /* Without the lambda synthesis, the property would look like this:
Note that this is the only time it is legal to access private fields Note that this is the only time it is legal to access private fields
via `self` from a lambda. */ via `self` from a lambda. */
-> exampleProperty | -> example-property |
get => [ ^self::val ], get => [ ^self::val ],
set => [ :x | self::val = x ]. set => [ :x | self::val = x ].
@@ -119,7 +119,7 @@ class Person
If either the `set` or `get` elements are not provided, the property If either the `set` or `get` elements are not provided, the property
becomes read-only or write-only respectively */ becomes read-only or write-only respectively */
-> exampleProperty2 | get => 42. -> example-property-2 | get => 42.
/* A property can also be configured to act just like a regular variable, /* A property can also be configured to act just like a regular variable,
by setting the getter and setters to default implementations. by setting the getter and setters to default implementations.
@@ -131,15 +131,15 @@ class Person
Similarly, the default setter will set the value of a private member Similarly, the default setter will set the value of a private member
variable named by prepending two underscores to the property name variable named by prepending two underscores to the property name
(__exampleProperty3 in this case) to the value provided to the setter. */ (__exampleProperty3 in this case) to the value provided to the setter. */
-> exampleProperty3 (get, set) -> example-property-3 (get, set)
/* Just like in the earlier examples, either `get` or `set` can be omitted /* Just like in the earlier examples, either `get` or `set` can be omitted
to create a write-only or read-only property respectively */ to create a write-only or read-only property respectively */
-> exampleProperty4 (get) -> example-property-4 (get)
end end
p1 = Person new(name:'John Doe', age:34). p1 = Person new(name:'John Doe', age:34).
p1 setAge:100 inUnit:$months. p1 set-age:100 in-unit:$months.
p1 test(param:'Hello', 'World'). p1 test(param:'Hello', 'World').
@@ -299,7 +299,7 @@ a = (32, 64).
try try
v = Int parse:'342' v = Int parse:'342'
catch ($err:number_format, err) in catch ($err:number-format, err) in
cout put:'Cannot parse integer string ({err})' cout put:'Cannot parse integer string ({err})'
catch (_, err) in catch (_, err) in
cout put:'Unknown error occurred ({err})' cout put:'Unknown error occurred ({err})'
@@ -308,7 +308,7 @@ end
/* equivalent 'pure' syntax */ /* equivalent 'pure' syntax */
[ v = Int parse:'342' ] [ v = Int parse:'342' ]
on:$err:number_format do:[ :err :data | on:$err:number-format do:[ :err :data |
cout put:'Cannot parse integer string ({err})' cout put:'Cannot parse integer string ({err})'
]; ];
onError:[ :err :data | onError:[ :err :data |
@@ -382,10 +382,10 @@ cout put:'Hello, world!' if x > 10.
**/ **/
p1 p1
setAge:2 squared squared + 4 squared multiply(by:2, add:4 + 1 * 3) set-age:2 squared squared + 4 squared multiply(by:2, add:4 + 1 * 3)
in:'mon' + 'ths'. in:'mon' + 'ths'.
(p1 (p1
setAge:(((2 squared) squared) + ((4 squared) multiply(by:2, add:(4 + (1 * 3))))) set-age:(((2 squared) squared) + ((4 squared) multiply(by:2, add:(4 + (1 * 3)))))
in:('mon' + 'ths')). in:('mon' + 'ths')).
/******************************************************************************/ /******************************************************************************/
@@ -440,7 +440,7 @@ pkg2 = pkg1 map:[ :x | ^x * 2 ].
**/ **/
age = Person new(name:'John Doe', age:34); age = Person new(name:'John Doe', age:34);
setAge:144 inUnit:$months; set-age:144 in-unit:$months;
ageInMonths. ageInMonths.
-- age now has the value 144 -- age now has the value 144
@@ -448,7 +448,7 @@ age = Person new(name:'John Doe', age:34);
age = do age = do
x = Person new(name:'John Doe', age:34). x = Person new(name:'John Doe', age:34).
x setAge:144 inUnit:$months. x set-age:144 in-unit:$months.
x ageInMonths x ageInMonths
end end
@@ -471,15 +471,15 @@ end
**/ **/
p1 = Person new(name:'John Doe', age:34); p1 = Person new(name:'John Doe', age:34);
setAge:100 inUnit:$months; set-age:100 in-unit:$months;
yourself:: yourself
/* p1 now contains the Person object */ /* p1 now contains the Person object */
/* again, with do..end */ /* again, with do..end */
p1 = do p1 = do
x = Person new(name:'John Doe', age:34). x = Person new(name:'John Doe', age:34).
x setAge:100 inUnit:$months. x set-age:100 in-unit:$months.
x x
end. end.

View File

@@ -1,27 +1,27 @@
y = 1 + 2 * 3 / 4 * 5 - 6 + 7 multiplyBy:2. y = -1 + 2 * 3 / 4 * 5 - 6 + 7 multiply-by:2.
z = w = 2 + 3 multiplyBy:2. z = w = 2 + 3 multiply-by:2.
x = (((1 + 2 * 3) multiplyBy:3) add: 5) + 2. x = (((1 + 2 * 3) multiply-by:3) add: 5) + 2.
x = ((1 + 2 * 3) multiplyBy:3). x = ((1 + 2 * 3) multiply-by:3).
p = 5 multiply(by:3, add:(2 + 1)). p = 5 multiply(by:3, add:(2 + 1)).
q = 10 squared squared. q = 10 squared squared.
p1 p1
setAge:2 squared squared + 4 squared multiply(by:2, add:4 + 1 * 3) set-age: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. 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 x = Ordered-Collection new
add: 2; add: 2;
add: 4; add: 4;
add: 6; add: 6;
yourself. yourself.
age = Person new(name:"John Doe", age:34) age = Person new(name:"John Doe", age:34)
setAge:144 inUnit:"months"; set-age:144 in-unit:"months";
ageInMonths. age-in-months.
x = 5. x = 5.
q = 10 if x > 2 else 20. q = 10 if x > 2 else 20.

View File

@@ -3,4 +3,4 @@ package net.doorstuck.test
s1 = 'hello world' s1 = 'hello world'
s2 = s1 map:[ :c | ^c uppercase ] s2 = s1 map:[ :c | ^c uppercase ]
s3 = s1 map:[ :c | ^((c ordinal) + 1) toChar ] s3 = s1 map:[ :c | ^((c ordinal) + 1) to-char ]

View File

@@ -9,7 +9,7 @@ while true do
cout flush. cout flush.
v = 0. v = 0.
input = cin readLine. input = cin read-line.
if input == '' then if input == '' then
break break

View File

@@ -3,8 +3,8 @@ package net.doorstuck.vehicles
protocol Vehicle protocol Vehicle
- startup - startup
- shutdown - shutdown
- nrWheels - nr-wheels
- nrDoors - nr-doors
- turn(direction:dir) - turn(direction:dir)
- accelerate(direction:dir) - accelerate(direction:dir)
- velocity - velocity
@@ -12,33 +12,33 @@ end
class Car <Vehicle> class Car <Vehicle>
- startup - startup
self.engineRunning = true self.engine-running = true
end end
- shutdown - shutdown
self.engineRunning = false self.engine-running = false
end end
- nrWheels - nr-wheels
^4 ^4
end end
- nrDoors - nr-doors
^4 ^4
end end
- turn(direction:dir) - turn(direction:dir)
self.currentDirection = dir self.current-direction = dir
end end
- accelerate(direction:dir) - accelerate(direction:dir)
match dir match dir
#forward => self.currentVelocity += 1, $forward => self.current-velocity += 1,
#backward => self.currentVelocity -= 1, $backward => self.current-velocity -= 1,
end end
end end
- velicity - velocity
^self.currentVelocity ^self.current-velocity
end end
end end