mirror of
https://github.com/hi-language/hi-language.github.io.git
synced 2026-01-14 16:48:37 +00:00
Feat: Introduce arrow blocks for concise functions
This commit is contained in:
21
index.html
21
index.html
@@ -10,7 +10,7 @@
|
||||
|
||||
<!-- Google Fonts -->
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic" crossorigin>
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
|
||||
|
||||
<!-- Markdown & Highlighting Styles -->
|
||||
@@ -157,6 +157,25 @@ greet: (name) {
|
||||
greet("Orion")
|
||||
\`\`\`
|
||||
|
||||
## Arrow Blocks
|
||||
|
||||
To enhance conciseness, Hi adopts the \`=>\` ("fat arrow") from JavaScript for single-expression blocks. This provides a shorthand for a block that immediately returns the value of its expression, perfect for callbacks and functional patterns.
|
||||
|
||||
It's a direct replacement for \`(params) { ^ expression }\`.
|
||||
|
||||
\`\`\`javascript
|
||||
// Standard block
|
||||
add: (a, b) { ^ a + b }
|
||||
|
||||
// Equivalent Arrow Block
|
||||
add: (a, b) => a + b
|
||||
|
||||
// Useful for functional helpers
|
||||
numbers: [1, 2, 3]
|
||||
doubled: numbers.map((n) => n * 2)
|
||||
_(doubled) // [2, 4, 6]
|
||||
\`\`\`
|
||||
|
||||
## Booleans and Equality
|
||||
|
||||
Hi dispenses with boolean keywords in favor of canonical numeric values for truthiness.
|
||||
|
||||
Reference in New Issue
Block a user