aboutsummaryrefslogtreecommitdiffstats
path: root/alv
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2025-09-14 10:12:13 +0000
committers-ol <s+removethis@s-ol.nu>2025-09-14 15:36:21 +0000
commit06c239e4f44849a3e4c8317194caacbcc47fc2d4 (patch)
tree491c8c5f9e3ad4351aa55951a0d7c70cd8686087 /alv
parentexpose Tag to Ops (diff)
downloadalive-06c239e4f44849a3e4c8317194caacbcc47fc2d4.tar.gz
alive-06c239e4f44849a3e4c8317194caacbcc47fc2d4.zip
de/fn, loop parameter lists use square brackets
Diffstat (limited to 'alv')
-rw-r--r--alv/builtins.moon16
-rw-r--r--alv/cell.moon14
2 files changed, 17 insertions, 13 deletions
diff --git a/alv/builtins.moon b/alv/builtins.moon
index 84978f1..6e36c7e 100644
--- a/alv/builtins.moon
+++ b/alv/builtins.moon
@@ -12,7 +12,7 @@ import
import Constant from require 'alv.result'
import Error from require 'alv.error'
import RTNode from require 'alv.rtnode'
-import Cell from require 'alv.cell'
+import Cell, ArrayCell from require 'alv.cell'
import Dummy from require 'alv.dummy'
import Scope from require 'alv.scope'
import Tag from require 'alv.tag'
@@ -194,7 +194,7 @@ fn = Constant.meta
meta:
name: 'fn'
summary: "Declare a function."
- examples: { '(fn (p1 [p2…]) body-expr)' }
+ examples: { '(fn [p1 p2…] body-expr)' }
description: "
The symbols `p1`, `p2`, ... will resolve to the arguments passed when the
function is invoked."
@@ -205,7 +205,7 @@ function is invoked."
assert #tail == 2, "'fn' takes exactly two arguments"
{ params, body } = tail
- assert params.__class == Cell, "'fn's first argument has to be an expression"
+ assert params.__class == ArrayCell, "'fn's first argument has to be a [parmeter list]"
param_symbols = for param in *params.children
assert param.type == T.sym, "function parameter declaration has to be a symbol"
param
@@ -220,7 +220,7 @@ defn = Constant.meta
meta:
name: 'defn'
summary: "Define a function."
- examples: { '(defn name-sym (p1 [p2…]) body-expr)' }
+ examples: { '(defn name-sym [p1 p2…] body-expr)' }
description: "
Declare a function and define it as `name-sym` in the current scope.
The symbols `p1`, `p2`, ... will resolve to the arguments passed when the
@@ -233,7 +233,7 @@ function is invoked."
{ name, params, body } = tail
name = name\unwrap T.sym
- assert params.__class == Cell, "'defn's second argument has to be an expression"
+ assert params.__class == ArrayCell, "'defn's second argument has to be a [parameter list]"
param_symbols = for param in *params.children
assert param.type == T.sym, "function parameter declaration has to be a symbol"
param
@@ -636,7 +636,7 @@ loop = Constant.meta
meta:
name: 'loop'
summary: "Loop on arbitrary data via recursion."
- examples: { '(loop (k1 v1 [k2 v2…]) body)' }
+ examples: { '(loop [k1 v1 [k2 v2…]] body)' }
description: "
Defines a recursive loop function `*recur*` with parameters `k1`, `k2`, … and
function body `body`, then invokes it immediately with arguments `v1`, `v2`, …
@@ -644,7 +644,7 @@ function body `body`, then invokes it immediately with arguments `v1`, `v2`, …
Inside the `body`, `(recur)` is used to recursively restart loop evaluation
with a different set of arguments, e.g. to sum the first `5` integers:
- (loop (n 5)
+ (loop [n 5]
(if (= n 0)
0
(+ n (recur (n - 1)))))"
@@ -655,7 +655,7 @@ with a different set of arguments, e.g. to sum the first `5` integers:
assert #tail == 2, "'loop' takes exactly two arguments"
{ binds, body } = tail
- assert binds.__class == Cell, "loops bindings have to be an cell"
+ assert binds.__class == ArrayCell, "loops bindings have to be a [parameter list]"
assert #binds.children % 2 == 0, "key without binding in loop binding"
names = {}
diff --git a/alv/cell.moon b/alv/cell.moon
index 8d1e5f6..989d4ad 100644
--- a/alv/cell.moon
+++ b/alv/cell.moon
@@ -190,9 +190,11 @@ class ArrayCell extends RootCell
tail: => @children
stringify: => '[' .. super! .. ']'
- new: (...) =>
- Cell.__init @, ...
+ eval: (...) =>
assert #@children > 0, Error 'syntax', "array literal can't be empty"
+ super ...
+
+ new: (...) => Cell.__init @, ...
--- @type StructCell
class StructCell extends RootCell
@@ -200,10 +202,12 @@ class StructCell extends RootCell
tail: => @children
stringify: => '{' .. super! .. '}'
- new: (...) =>
- Cell.__init @, ...
+ eval: (...) =>
assert #@children > 0, Error 'syntax', "struct literal can't be empty"
- assert #@children % 2 == 0, Error 'syntax', "struct literal can't have uneven number values"
+ assert #@children % 2 == 0, Error 'syntax', "struct literal must have even number of values"
+ super ...
+
+ new: (...) => Cell.__init @, ...
--- @type TemplateString
class TemplateString extends Cell