doc: sample: switch to kebab-case
This commit is contained in:
@@ -58,13 +58,13 @@ class Person
|
||||
|
||||
- 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
|
||||
$years => self::age = age,
|
||||
$months => self::age = age / 12,
|
||||
@@ -72,7 +72,7 @@ class Person
|
||||
_ => self::age = 0
|
||||
end!
|
||||
|
||||
- getAgeInUnit:units
|
||||
- get-age-in-units:units
|
||||
^match units in
|
||||
$years => self::age,
|
||||
$months => self::age / 12,
|
||||
@@ -104,12 +104,12 @@ class Person
|
||||
is converted to the lambda
|
||||
[ :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:
|
||||
Note that this is the only time it is legal to access private fields
|
||||
via `self` from a lambda. */
|
||||
-> exampleProperty |
|
||||
-> example-property |
|
||||
get => [ ^self::val ],
|
||||
set => [ :x | self::val = x ].
|
||||
|
||||
@@ -119,7 +119,7 @@ class Person
|
||||
|
||||
If either the `set` or `get` elements are not provided, the property
|
||||
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,
|
||||
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
|
||||
variable named by prepending two underscores to the property name
|
||||
(__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
|
||||
to create a write-only or read-only property respectively */
|
||||
-> exampleProperty4 (get)
|
||||
-> example-property-4 (get)
|
||||
end
|
||||
|
||||
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').
|
||||
|
||||
@@ -299,7 +299,7 @@ a = (32, 64).
|
||||
|
||||
try
|
||||
v = Int parse:'342'
|
||||
catch ($err:number_format, err) in
|
||||
catch ($err:number-format, err) in
|
||||
cout put:'Cannot parse integer string ({err})'
|
||||
catch (_, err) in
|
||||
cout put:'Unknown error occurred ({err})'
|
||||
@@ -308,7 +308,7 @@ end
|
||||
/* equivalent 'pure' syntax */
|
||||
|
||||
[ 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})'
|
||||
];
|
||||
onError:[ :err :data |
|
||||
@@ -382,10 +382,10 @@ cout put:'Hello, world!' if x > 10.
|
||||
**/
|
||||
|
||||
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'.
|
||||
(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')).
|
||||
|
||||
/******************************************************************************/
|
||||
@@ -440,7 +440,7 @@ pkg2 = pkg1 map:[ :x | ^x * 2 ].
|
||||
**/
|
||||
|
||||
age = Person new(name:'John Doe', age:34);
|
||||
setAge:144 inUnit:$months;
|
||||
set-age:144 in-unit:$months;
|
||||
ageInMonths.
|
||||
|
||||
-- age now has the value 144
|
||||
@@ -448,7 +448,7 @@ age = Person new(name:'John Doe', age:34);
|
||||
|
||||
age = do
|
||||
x = Person new(name:'John Doe', age:34).
|
||||
x setAge:144 inUnit:$months.
|
||||
x set-age:144 in-unit:$months.
|
||||
x ageInMonths
|
||||
end
|
||||
|
||||
@@ -471,15 +471,15 @@ end
|
||||
**/
|
||||
|
||||
p1 = Person new(name:'John Doe', age:34);
|
||||
setAge:100 inUnit:$months;
|
||||
yourself::
|
||||
set-age:100 in-unit:$months;
|
||||
yourself
|
||||
|
||||
/* p1 now contains the Person object */
|
||||
/* again, with do..end */
|
||||
|
||||
p1 = do
|
||||
x = Person new(name:'John Doe', age:34).
|
||||
x setAge:100 inUnit:$months.
|
||||
x set-age:100 in-unit:$months.
|
||||
x
|
||||
end.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user