mirror of
https://github.com/hi-language/hi-language.github.io.git
synced 2026-01-14 08:38:36 +00:00
Refactor: Move Block separator info to section end
This commit is contained in:
28
index.html
28
index.html
@@ -111,25 +111,18 @@ version = 1.1 // Assignment
|
||||
In Hi, the distinction between objects and functions is eliminated. Both concepts are unified into a single, foundational structure: the **Block** (\`{}\`). A Block is a sequence of expressions that can hold data, executable code, or both, making it a powerful tool for building complex structures.
|
||||
|
||||
### As a Data Structure (Object)
|
||||
When a Block contains primarily named declarations (\`key: value\`), it behaves like a traditional object or dictionary. A \`#\` prefix denotes a private property.
|
||||
When a Block contains primarily named declarations (\`key: value\`), it behaves like a traditional object or dictionary. A \`#\` prefix denotes a private property, making it inaccessible from outside the block.
|
||||
|
||||
\`\`\`javascript
|
||||
// Multi-line: separators are optional
|
||||
player: {
|
||||
name: "Orion"
|
||||
#hp: 100
|
||||
}
|
||||
|
||||
// Single-line: separators are required
|
||||
player: { name: "Orion", #hp: 100 }
|
||||
point: { x: 10; y: 20 }
|
||||
_(player.name) // "Orion"
|
||||
_(player.hp) // -0 (null) because #hp is private
|
||||
\`\`\`
|
||||
|
||||
To support code golfing, expression separators are flexible:
|
||||
|
||||
- **Newlines** act as separators. Commas or semicolons are optional.
|
||||
- **Commas (\`,\`) or semicolons (\`;\`)** must be used to separate expressions on the same line.
|
||||
|
||||
### As Executable Code (Function)
|
||||
When a Block is defined with parameters (\`()\`) or invoked, it behaves like a function. It executes its sequence of expressions.
|
||||
|
||||
@@ -155,6 +148,21 @@ counter.inc()
|
||||
_(counter.get()) // Prints 1
|
||||
\`\`\`
|
||||
|
||||
### Expression Separators
|
||||
To support code golfing, expression separators within a Block are flexible. Newlines act as implicit separators, while commas (\`,\`) or semicolons (\`;\`) are required to separate expressions on the same line.
|
||||
|
||||
\`\`\`javascript
|
||||
// Multi-line style (separators optional)
|
||||
point: {
|
||||
x: 10
|
||||
y: 20
|
||||
}
|
||||
|
||||
// Single-line style (separators required)
|
||||
point: { x: 10, y: 20 }
|
||||
point: { x: 10; y: 20 }
|
||||
\`\`\`
|
||||
|
||||
## Arrow Expressions
|
||||
|
||||
For concise single-expression functions, Hi provides the \`=>\` arrow syntax, inspired by JavaScript. It serves as a shorthand for a Block that immediately returns an expression, making it ideal for callbacks and functional patterns.
|
||||
|
||||
Reference in New Issue
Block a user