Refactor: Move Block separator info to section end

This commit is contained in:
2025-09-22 12:41:32 -07:00
parent 29bbb91363
commit 50b8acc963

View File

@@ -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. 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) ### 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 \`\`\`javascript
// Multi-line: separators are optional
player: { player: {
name: "Orion" name: "Orion"
#hp: 100 #hp: 100
} }
// Single-line: separators are required _(player.name) // "Orion"
player: { name: "Orion", #hp: 100 } _(player.hp) // -0 (null) because #hp is private
point: { x: 10; y: 20 }
\`\`\` \`\`\`
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) ### As Executable Code (Function)
When a Block is defined with parameters (\`()\`) or invoked, it behaves like a function. It executes its sequence of expressions. 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 _(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 ## 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. 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.