mirror of
https://github.com/hi-language/hi-language.github.io.git
synced 2026-01-14 08:38:36 +00:00
Refactor: Improve clarity of introductory examples
This commit is contained in:
10
index.html
10
index.html
@@ -93,13 +93,14 @@ _("Hi world")
|
|||||||
|
|
||||||
## Declaration and Assignment
|
## Declaration and Assignment
|
||||||
|
|
||||||
Variable lifecycle is split into two distinct symbolic operations. A semicolon \`;\` can be used to separate expressions on a single line.
|
Variable lifecycle is split into two distinct symbolic operations.
|
||||||
|
|
||||||
- \`:\` **Declaration**: Binds a name in the current scope.
|
- \`:\` **Declaration**: Binds a name in the current scope.
|
||||||
- \`=\` **Assignment**: Reassigns the value of an existing name.
|
- \`=\` **Assignment**: Reassigns the value of an existing name.
|
||||||
|
|
||||||
\`\`\`javascript
|
\`\`\`javascript
|
||||||
version: 1.0; version = 1.1
|
version: 1.0 // Declaration and initialization
|
||||||
|
version = 1.1 // Assignment
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
## The Block: A Unified Structure
|
## The Block: A Unified Structure
|
||||||
@@ -118,7 +119,6 @@ sayHi() // Invokes the block
|
|||||||
A Block with named properties is an object. A \`#\` prefix denotes a private property, inaccessible from outside the block's scope.
|
A Block with named properties is an object. A \`#\` prefix denotes a private property, inaccessible from outside the block's scope.
|
||||||
|
|
||||||
\`\`\`javascript
|
\`\`\`javascript
|
||||||
// A Block can be defined on one line using ';'
|
|
||||||
player: { name: "Orion"; #hp: 100 }
|
player: { name: "Orion"; #hp: 100 }
|
||||||
_(player.name) // "Orion"
|
_(player.name) // "Orion"
|
||||||
\`\`\`
|
\`\`\`
|
||||||
@@ -129,8 +129,8 @@ Blocks can contain both state and methods. Inner blocks lexically inherit the sc
|
|||||||
\`\`\`javascript
|
\`\`\`javascript
|
||||||
counter: {
|
counter: {
|
||||||
#value: 0
|
#value: 0
|
||||||
inc: { value = value + 1 } // Concise one-liner methods
|
inc: { value = value + 1 }
|
||||||
get: { value } // Last expression is implicitly returned
|
get: { value }
|
||||||
}
|
}
|
||||||
|
|
||||||
counter.inc()
|
counter.inc()
|
||||||
|
|||||||
Reference in New Issue
Block a user