aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--alv-lib/array.moon (renamed from alv-lib/array-.moon)2
-rw-r--r--alv-lib/math.moon4
-rw-r--r--alv-lib/struct.moon (renamed from alv-lib/struct-.moon)0
-rw-r--r--alv/ast.moon4
-rw-r--r--alv/builtins.moon14
-rw-r--r--alv/cell.moon34
-rw-r--r--alv/parsing.moon22
-rw-r--r--docs/reference/05-1_arrays.md12
-rw-r--r--docs/reference/05-2_structs.md10
-rw-r--r--examples/love.alv14
-rw-r--r--spec/internal/cell_spec.moon6
-rw-r--r--spec/lib/array_spec.moon76
-rw-r--r--spec/lib/builtins/cond_spec.moon10
-rw-r--r--spec/lib/builtins/literal_spec.moon4
-rw-r--r--spec/lib/logic_spec.moon56
-rw-r--r--spec/lib/math_spec.moon162
-rw-r--r--spec/lib/string_spec.moon26
-rw-r--r--spec/lib/struct_spec.moon20
-rw-r--r--spec/lib/testing_spec.moon4
19 files changed, 256 insertions, 224 deletions
diff --git a/alv-lib/array-.moon b/alv-lib/array.moon
index e2d2233..bbc1cbd 100644
--- a/alv-lib/array-.moon
+++ b/alv-lib/array.moon
@@ -238,7 +238,7 @@ concat = Constant.meta
@out\set out
-array_constr = builtins!\get('array').result
+array_constr = builtins!\get('mkarray').result
map = Constant.meta
meta:
name: 'map'
diff --git a/alv-lib/math.moon b/alv-lib/math.moon
index 33f215c..2cf6e26 100644
--- a/alv-lib/math.moon
+++ b/alv-lib/math.moon
@@ -291,13 +291,13 @@ also work componentwise with vectors (`num[X]`) and matrices (`num[X][Y]`).
All operators are PureOps.
(+ 1 2 3) #(<num= 6>)
- (+ (array 1 2) (array 3 4)) #(<num[2]= [4 6]>)
+ (+ [1 2] [3 4]) #(<num[2]= [4 6]>)
The arguments for an operator generally have to be of the same type.
However it is also okay to pass in scalar numbers together with a different type.
The scalars will be repeated as necessary to fit the shape of other arguments:
- (* (array (array 1 2) (array 3 4))
+ (* [[1 2] [3 4]]
2)
#(<num[2][2]= [[2 4] [6 8]]>)
diff --git a/alv-lib/struct-.moon b/alv-lib/struct.moon
index b064e81..b064e81 100644
--- a/alv-lib/struct-.moon
+++ b/alv-lib/struct.moon
diff --git a/alv/ast.moon b/alv/ast.moon
index 4d0ecae..52117c6 100644
--- a/alv/ast.moon
+++ b/alv/ast.moon
@@ -32,7 +32,7 @@
-- @function stringify
-- @treturn string the exact string this Node was parsed from
-import Cell, RootCell from require 'alv.cell'
+import Cell, RootCell, ArrayCell, StructCell from require 'alv.cell'
import TemplateString from require 'alv.template_string'
import Constant from require 'alv.result.const'
import Dummy from require 'alv.dummy'
@@ -41,6 +41,8 @@ import Tag from require 'alv.tag'
{
:Cell
:RootCell
+ :ArrayCell
+ :StructCell
:TemplateString
:Constant
:Dummy
diff --git a/alv/builtins.moon b/alv/builtins.moon
index d76effc..0d188f9 100644
--- a/alv/builtins.moon
+++ b/alv/builtins.moon
@@ -539,11 +539,11 @@ In case of collisions, the event that comes first in the argument list wins."
@out\set input!
return
-array = Constant.meta
+mkarray = Constant.meta
meta:
- name: 'array'
+ name: 'mkarray'
summary: "Construct an array."
- examples: { '(array a b c…)' }
+ examples: { '[a b c…]', '(mkarray a b c…)' }
description: "Produces an array of values.
`a`, `b`, `c`… have to be values of the same type.
@@ -559,11 +559,11 @@ This is a pure op, so at most one !-stream input is allowed."
args = @unwrap_all!
@out\set args
-struct = Constant.meta
+mkstruct = Constant.meta
meta:
- name: 'struct'
+ name: 'mkstruct'
summary: "Construct an struct."
- examples: { '(struct key1 val1 [key2 val2…])' }
+ examples: { '{key1 val1 [key2 val2…]}', '(mkstruct key1 val1 [key2 val2…])' }
description: "Produces a struct of values.
`key1`, `key2`, … have to be constant expressions.
@@ -732,7 +732,7 @@ Constant.meta
'->': thread_first
'->>': thread_last
- :array, :struct
+ :mkarray, :mkstruct
:loop, :recur
diff --git a/alv/cell.moon b/alv/cell.moon
index 7b6cf61..7f2c027 100644
--- a/alv/cell.moon
+++ b/alv/cell.moon
@@ -155,6 +155,10 @@ class RootCell extends Cell
head: => Constant.sym 'do'
tail: => @children
+ new: (...) =>
+ super ...
+ @tag = Tag.parse '0'
+
stringify: =>
buf = ''
buf ..= @white[0]
@@ -172,12 +176,34 @@ class RootCell extends Cell
--
-- @tparam table parts
-- @treturn Cell
- @parse: (...) ->
- tag, children, white = parse_args (Tag.parse '0'), ...
- RootCell tag, children, white
+ @parse: (parts) =>
+ _, children, white = parse_args nil, parts
+ @@ nil, children, white
+
+-- @type ArrayCell
+class ArrayCell extends RootCell
+ head: => Constant.sym 'mkarray'
+ tail: => @children
+ stringify: => '[' .. super! .. ']'
+
+ new: (...) =>
+ Cell.__init @, ...
+ assert #@children > 0, Error 'syntax', "array literal can't be empty"
+
+-- @type StructCell
+class StructCell extends RootCell
+ head: => Constant.sym 'mkstruct'
+ tail: => @children
+ stringify: => '{' .. super! .. '}'
+
+ new: (...) =>
+ Cell.__init @, ...
+ 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"
{
:Cell
:RootCell
- :TemplateString
+ :ArrayCell
+ :StructCell
}
diff --git a/alv/parsing.moon b/alv/parsing.moon
index d5ec313..e8cc5b6 100644
--- a/alv/parsing.moon
+++ b/alv/parsing.moon
@@ -2,7 +2,7 @@
-- Lpeg Grammar for parsing `alive` code.
--
-- @module parsing
-import Cell, RootCell, Constant, TemplateString, Tag from require 'alv.ast'
+import Cell, RootCell, ArrayCell, StructCell, Constant, TemplateString, Tag from require 'alv.ast'
import R, S, P, V, C, Ct from require 'lpeg'
-- whitespace
@@ -29,26 +29,28 @@ fract = digit^1 * '/' * digit^1
float = (digit^1 * '.' * digit^0) + (digit^0 * '.' * digit^1)
num = ((P '-')^-1 * (float + fract + int)) / Constant\parse 'num'
-atom = num + sym + str
-expr = (V 'cell') + atom
-
tplcont = ((P '\\"') + (P '\\\\') + (1 - (P '"') - (P '#')))^1 / 1
-tplstr = (P '#"') * ((P '##') / 1 + ('#' * expr) + tplcont)^0 * '"' / TemplateString\parse
+tplstr = (P '#"') * ((P '##') / 1 + ('#' * (V 'expr')) + tplcont)^0 * '"' / TemplateString\parse
-expitem = tplstr + expr
+expitem = tplstr + (V 'expr')
explist = Ct mspace * (expitem * (space * expitem)^0 * mspace)^-1
tag = (P '[') * (digit^1 / Tag.parse) * (P ']')
cell = (P '(') * tag^-1 * explist * (P ')') / Cell.parse
+array = (P '[') * explist * (P ']') / ArrayCell\parse
+struct = (P '{') * explist * (P '}') / StructCell\parse
+
+atom = num + sym + str
+expr = cell + array + struct + atom
root = P {
- explist / RootCell.parse
- :cell
+ explist / RootCell\parse
+ :expr
}
cell = P {
- 'cell'
- :cell
+ cell
+ :expr
}
program = root * -1
diff --git a/docs/reference/05-1_arrays.md b/docs/reference/05-1_arrays.md
index fdd26ff..19075f5 100644
--- a/docs/reference/05-1_arrays.md
+++ b/docs/reference/05-1_arrays.md
@@ -1,9 +1,11 @@
Arrays are composite types that contain a fixed number of values of the same
-type. Arrays values can be created using the [`(array …)`][:array:] builtin,
-which uses [Pure Op](04-2_pure-operators.html) semantics to construct an array
-from its parameters, all of which have to be of the same type.
+type. Arrays values can be created using square brackets `[1 2 3]` (which is
+syntactic sugar for the [`(mkarray …)`][:mkarray:] builtin).
- (trace (array 1 2 3))
+This uses [Pure Op](04-2_pure-operators.html) semantics to construct an array
+from several values, all of which have to be of the same type.
+
+ (trace [1 2 3])
```output
<num[3]= [1 2 3]>
```
@@ -11,4 +13,4 @@ from its parameters, all of which have to be of the same type.
The type notation `num[3]` designates an array of three numbers, whereas the
value notation `[1 2 3]` is used to show the array contents.
-The [array-][:array-/:] module provides *Op*s for working with arrays.
+The [array][:array/:] module provides *Op*s for working with arrays.
diff --git a/docs/reference/05-2_structs.md b/docs/reference/05-2_structs.md
index d3074c9..c9b234e 100644
--- a/docs/reference/05-2_structs.md
+++ b/docs/reference/05-2_structs.md
@@ -2,11 +2,13 @@ Structs are composite types that contain values of different types associated
with a set of string keys. The set of keys and their corresponding value types
is fixed at *runtime*.
-Struct values can be created using the the [`(struct …)`][:struct:] builtin,
-which uses [Pure Op](04-2_pure-operators.html) semantics to construct a struct
+Struct values can be created using curly brackets `{"key" 3}` (which is
+syntactic sugar for the [`(mkstruct …)`][:mkstruct:] builtin).
+
+This uses [Pure Op](04-2_pure-operators.html) semantics to construct a struct
from its parameters. The keys have to be constants.
- (trace (struct "a" 1 "b" 'hello world'))
+ (trace {"a" 1 "b" 'hello world'})
```output
<{a: num b: str}= {a: 1 b: "hello world"}>
```
@@ -16,4 +18,4 @@ mapping to a value of type `num` and the key `b` mapping to a value of type
`str` respectively, whereas the value notation `{a: 1 b: "hello world"}` shows
the struct contents.
-The [struct-][:struct-/:] module provides *Op*s for working with arrays.
+The [struct][:struct/:] module provides *Op*s for working with arrays.
diff --git a/examples/love.alv b/examples/love.alv
index 71a8287..113ea2d 100644
--- a/examples/love.alv
+++ b/examples/love.alv
@@ -3,17 +3,17 @@
The size changes when the left mouse button is held, and the color
changes when space is pressed.
)
-([1]import* love math time array-)
+([1]import* love math time array)
([20]def
#(cycle colors when space is pressed)
fill-color ([21]switch ([22]key-presses "space")
- ([23]array 0.3 0 0.9)
- ([24]array 0 0.9 0.3)
- ([27]array 0.9 0.3 0)
- ([28]array 0.3 0.9 0)
- ([30]array 0 0.3 0.9)
- ([31]array 0.9 0 0.3))
+ [0.3 0 0.9]
+ [0 0.9 0.3]
+ [0.9 0.3 0]
+ [0.3 0.9 0]
+ [0 0.3 0.9]
+ [0.9 0 0.3])
#(smooth out rgb channels individually)
smooth-color ([36]map fill-color
diff --git a/spec/internal/cell_spec.moon b/spec/internal/cell_spec.moon
index bd97e63..c9ccb39 100644
--- a/spec/internal/cell_spec.moon
+++ b/spec/internal/cell_spec.moon
@@ -39,18 +39,18 @@ describe 'Cell', ->
describe 'RootCell', ->
test 'tag is always [0]', ->
- cell = RootCell.parse {}
+ cell = RootCell\parse {}
assert.is.equal '[0]', cell.tag\stringify!
test 'head is always "do"', ->
- cell = RootCell.parse {}
+ cell = RootCell\parse {}
assert.is.equal (Constant.sym 'do'), cell\head!
cell = RootCell nil, { hello_world, two_plus_two }
assert.is.equal (Constant.sym 'do'), cell\head!
test 'tail is all children', ->
- cell = RootCell.parse {}
+ cell = RootCell\parse {}
assert.is.same {}, cell\tail!
cell = RootCell nil, { hello_world, two_plus_two }
diff --git a/spec/lib/array_spec.moon b/spec/lib/array_spec.moon
index b55cec6..130138c 100644
--- a/spec/lib/array_spec.moon
+++ b/spec/lib/array_spec.moon
@@ -2,147 +2,147 @@ import TestPilot from require 'spec.test_setup'
import T, Array from require 'alv'
describe "array", ->
- test = TestPilot '', '(import* array-)\n'
+ test = TestPilot '', '(import* array)\n'
svec3 = Array 3, T.str
it "can contain any type", ->
- COPILOT\eval_once '(array 1 2 3)'
- COPILOT\eval_once '(array true false)'
- COPILOT\eval_once '(array "a")'
- COPILOT\eval_once '(array (array 1 2) (array 3 4))'
+ COPILOT\eval_once '[1 2 3]'
+ COPILOT\eval_once '[true false]'
+ COPILOT\eval_once '["a"]'
+ COPILOT\eval_once '[[1 2] [3 4]]'
it "cannot contain mixed types", ->
- err = assert.has.error -> COPILOT\eval_once '(array 1 false)'
+ err = assert.has.error -> COPILOT\eval_once '[1 false]'
assert.matches "argument error: couldn't match arguments", err
describe "(set)", ->
it "can swap values", ->
- rt = COPILOT\eval_once '(set (array "f" "b" "c") 0 "a")'
+ rt = COPILOT\eval_once '(set ["f" "b" "c"] 0 "a")'
assert.is.true rt\is_const!
assert.is.equal svec3\mk_const({ 'a', 'b', 'c' }), rt.result
it "checks value type", ->
- err = assert.has.error -> COPILOT\eval_once '(set (array 1) 0 "a")'
+ err = assert.has.error -> COPILOT\eval_once '(set [1] 0 "a")'
assert.matches "expected value of type num, not str", err
it "checks index range", ->
- err = assert.has.error -> COPILOT\eval_once '(set (array 1 2) -1 0)'
+ err = assert.has.error -> COPILOT\eval_once '(set [1 2] -1 0)'
assert.matches "index '%-1' out of range!", err
- COPILOT\eval_once '(set (array 1 2) 0 0)'
+ COPILOT\eval_once '(set [1 2] 0 0)'
- COPILOT\eval_once '(set (array 1 2) 1 0)'
+ COPILOT\eval_once '(set [1 2] 1 0)'
- err = assert.has.error -> COPILOT\eval_once '(set (array 1 2) 2 0)'
+ err = assert.has.error -> COPILOT\eval_once '(set [1 2] 2 0)'
assert.matches "index '2' out of range!", err
describe "(get)", ->
it "can get a value", ->
- rt = COPILOT\eval_once '(get (array 1 2) 0)'
+ rt = COPILOT\eval_once '(get [1 2] 0)'
assert.is.true rt\is_const!
assert.is.equal '<num= 1>', tostring rt.result
it "checks index range", ->
- err = assert.has.error -> COPILOT\eval_once '(get (array 1 2) -1)'
+ err = assert.has.error -> COPILOT\eval_once '(get [1 2] -1)'
assert.matches "index '%-1' out of range!", err
- COPILOT\eval_once '(get (array 1 2) 0)'
+ COPILOT\eval_once '(get [1 2] 0)'
- COPILOT\eval_once '(get (array 1 2) 1)'
+ COPILOT\eval_once '(get [1 2] 1)'
- err = assert.has.error -> COPILOT\eval_once '(get (array 1 2) 2)'
+ err = assert.has.error -> COPILOT\eval_once '(get [1 2] 2)'
assert.matches "index '2' out of range!", err
describe '(head)', ->
it "can peek a value", ->
- rt = COPILOT\eval_once '(head (array 1 2))'
+ rt = COPILOT\eval_once '(head [1 2])'
assert.is.true rt\is_const!
assert.is.equal '<num= 1>', tostring rt.result
describe '(tail)', ->
it "gets rest of an array", ->
- rt = COPILOT\eval_once '(tail (array 1))'
+ rt = COPILOT\eval_once '(tail [1])'
assert.is.true rt\is_const!
assert.is.same (Array 0, T.num), rt.result.type
assert.is.same {}, rt.result!
- rt = COPILOT\eval_once '(tail (array 1 2))'
+ rt = COPILOT\eval_once '(tail [1 2])'
assert.is.true rt\is_const!
assert.is.same (Array 1, T.num), rt.result.type
assert.is.same { 2 }, rt.result!
- rt = COPILOT\eval_once '(tail (array 1 2 3 4))'
+ rt = COPILOT\eval_once '(tail [1 2 3 4])'
assert.is.true rt\is_const!
assert.is.same (Array 3, T.num), rt.result.type
assert.is.same { 2, 3, 4 }, rt.result!
describe '(prepend)', ->
it "prepends to array", ->
- rt = COPILOT\eval_once '(prepend (array 2) 1)'
+ rt = COPILOT\eval_once '(prepend [2] 1)'
assert.is.true rt\is_const!
assert.is.same (Array 2, T.num), rt.result.type
assert.is.same { 1, 2 }, rt.result!
- rt = COPILOT\eval_once '(prepend (array 2 3 4) 1)'
+ rt = COPILOT\eval_once '(prepend [2 3 4] 1)'
assert.is.true rt\is_const!
assert.is.same (Array 4, T.num), rt.result.type
assert.is.same { 1, 2, 3, 4 }, rt.result!
describe "(insert)", ->
it "can insert a value", ->
- rt = COPILOT\eval_once '(insert (array "b" "c") 0 "a")'
+ rt = COPILOT\eval_once '(insert ["b" "c"] 0 "a")'
assert.is.true rt\is_const!
assert.is.equal svec3\mk_const({ 'a', 'b', 'c' }), rt.result
- rt = COPILOT\eval_once '(insert (array "a" "c") 1 "b")'
+ rt = COPILOT\eval_once '(insert ["a" "c"] 1 "b")'
assert.is.true rt\is_const!
assert.is.equal svec3\mk_const({ 'a', 'b', 'c' }), rt.result
- rt = COPILOT\eval_once '(insert (array "a" "b") 2 "c")'
+ rt = COPILOT\eval_once '(insert ["a" "b"] 2 "c")'
assert.is.true rt\is_const!
assert.is.equal svec3\mk_const({ 'a', 'b', 'c' }), rt.result
it "checks index range", ->
- err = assert.has.error -> COPILOT\eval_once '(insert (array 1 2) -1 0)'
+ err = assert.has.error -> COPILOT\eval_once '(insert [1 2] -1 0)'
assert.matches "index '%-1' out of range!", err
- COPILOT\eval_once '(insert (array 1 2) 0 0)'
+ COPILOT\eval_once '(insert [1 2] 0 0)'
- COPILOT\eval_once '(insert (array 1 2) 1 0)'
+ COPILOT\eval_once '(insert [1 2] 1 0)'
- COPILOT\eval_once '(insert (array 1 2) 2 0)'
+ COPILOT\eval_once '(insert [1 2] 2 0)'
- err = assert.has.error -> COPILOT\eval_once '(insert (array 1 2) 3 0)'
+ err = assert.has.error -> COPILOT\eval_once '(insert [1 2] 3 0)'
assert.matches "index '3' out of range!", err
describe "(remove)", ->
it "can remove a value", ->
- rt = COPILOT\eval_once '(remove (array "d" "a" "b" "c") 0)'
+ rt = COPILOT\eval_once '(remove ["d" "a" "b" "c"] 0)'
assert.is.true rt\is_const!
assert.is.equal svec3\mk_const({ 'a', 'b', 'c' }), rt.result
- rt = COPILOT\eval_once '(remove (array "a" "b" "c" "d") 3)'
+ rt = COPILOT\eval_once '(remove ["a" "b" "c" "d"] 3)'
assert.is.true rt\is_const!
assert.is.equal svec3\mk_const({ 'a', 'b', 'c' }), rt.result
it "checks index range", ->
- err = assert.has.error -> COPILOT\eval_once '(remove (array 1 2 3) -1)'
+ err = assert.has.error -> COPILOT\eval_once '(remove [1 2 3] -1)'
assert.matches "index '%-1' out of range!", err
- err = assert.has.error -> COPILOT\eval_once '(remove (array 1 2 3) 3)'
+ err = assert.has.error -> COPILOT\eval_once '(remove [1 2 3] 3)'
assert.matches "index '3' out of range!", err
it "can be concatenated with (concat)", ->
- rt = COPILOT\eval_once '(concat (array "a" "b") (array "c"))'
+ rt = COPILOT\eval_once '(concat ["a" "b"] ["c"])'
assert.is.true rt\is_const!
assert.is.equal svec3\mk_const({ 'a', 'b', 'c' }), rt.result
it "size can be read using (size)", ->
- rt = COPILOT\eval_once '(size (array 1))'
+ rt = COPILOT\eval_once '(size [1])'
assert.is.true rt\is_const!
assert.is.equal '<num= 1>', tostring rt.result
- rt = COPILOT\eval_once '(size (array 1 2 3))'
+ rt = COPILOT\eval_once '(size [1 2 3])'
assert.is.true rt\is_const!
assert.is.equal '<num= 3>', tostring rt.result
diff --git a/spec/lib/builtins/cond_spec.moon b/spec/lib/builtins/cond_spec.moon
index 04c56ef..b075f8b 100644
--- a/spec/lib/builtins/cond_spec.moon
+++ b/spec/lib/builtins/cond_spec.moon
@@ -5,7 +5,7 @@ describe "if", ->
COPILOT = TestPilot!
it "checks truthiness", ->
- for truthy in *{'true', '1', '-1', '1234', '(array 1 2 3)', '"test"', '""'}
+ for truthy in *{'true', '1', '-1', '1234', '[1 2 3]', '"test"', '""'}
with COPILOT\eval_once "(if #{truthy} 'yes' 'no')"
assert.is.true \is_const!
assert.is.equal 'yes', .result!
@@ -41,7 +41,7 @@ describe "if", ->
it "forwards any result", ->
with COPILOT\eval_once '
(import* time)
- (if true (every 1 (array 1 2 3)))'
+ (if true (every 1 [1 2 3]))'
assert.is.false \is_const!
assert.is.equal '<num[3]! nil>', tostring .result
@@ -49,7 +49,7 @@ describe "when", ->
COPILOT = TestPilot!
it "checks truthiness", ->
- for truthy in *{'true', '1', '-1', '1234', '(array 1 2 3)', '"test"', '""'}
+ for truthy in *{'true', '1', '-1', '1234', '[1 2 3]', '"test"', '""'}
with COPILOT\eval_once "(when #{truthy} 'yes')"
assert.is.true \is_const!
assert.is.equal 'yes', .result!
@@ -81,12 +81,12 @@ describe "when", ->
with COPILOT\eval_once '
(import* time)
(when true
- (every 1 (array 1 2 3))
+ (every 1 [1 2 3])
1 2 3)'
assert.is.false \is_const!
assert.is.equal '<num~ 3>', tostring .result
- with COPILOT\eval_once '(when true (array 1 2 3))'
+ with COPILOT\eval_once '(when true [1 2 3])'
assert.is.true \is_const!
assert.is.equal '<num[3]= [1 2 3]>', tostring .result
diff --git a/spec/lib/builtins/literal_spec.moon b/spec/lib/builtins/literal_spec.moon
index 3db010d..61a9b90 100644
--- a/spec/lib/builtins/literal_spec.moon
+++ b/spec/lib/builtins/literal_spec.moon
@@ -6,8 +6,8 @@ describe "literal", ->
(def str "hello"
num 2
bool true
- curl ([5]struct "a" 2 "b" false)
- sqre ([7]array 1 2 3 4))
+ curl {"a" 2 "b" false}
+ sqre [1 2 3 4])
(export*)'
assert.is.true COPILOT.active_module.root\is_const!
diff --git a/spec/lib/logic_spec.moon b/spec/lib/logic_spec.moon
index 2760e54..5b71465 100644
--- a/spec/lib/logic_spec.moon
+++ b/spec/lib/logic_spec.moon
@@ -9,25 +9,25 @@ describe "logic", ->
(expect= false (== 1 2))
(expect= false (== 1 "hello"))
(expect= true (== "hello" "hello"))
- (expect= true (== (array 1 2 3) (array 1 2 3)))
- (expect= false (== (array 1 2 3) (array 1 2 1)))
- (expect= false (== (array 1 2 3) (array 1 2)))
- (expect= false (== (array 1 2 3) (array 1 2 3 4)))
+ (expect= true (== [1 2 3] [1 2 3]))
+ (expect= false (== [1 2 3] [1 2 1]))
+ (expect= false (== [1 2 3] [1 2]))
+ (expect= false (== [1 2 3] [1 2 3 4]))
(expect= true (==
- (struct "a" 1 "b" true "c" (array "test"))
- (struct "a" 1 "b" true "c" (array "test"))))
+ {"a" 1 "b" true "c" ["test"]}
+ {"a" 1 "b" true "c" ["test"]}))
(expect= false (==
- (struct "a" 1 "b" false "c" (array "test"))
- (struct "a" 1 "b" true "c" (array "test"))))
+ {"a" 1 "b" false "c" ["test"]}
+ {"a" 1 "b" true "c" ["test"]}))
(expect= false (==
- (struct "a" 1 "b" true "c" (array "test" "toast"))
- (struct "a" 1 "b" true "c" (array "test"))))
+ {"a" 1 "b" true "c" ["test" "toast"]}
+ {"a" 1 "b" true "c" ["test"]}))
(expect= false (==
- (struct "a" 1 "b" true)
- (struct "a" 1 "b" true "c" (array "test"))))
+ {"a" 1 "b" true}
+ {"a" 1 "b" true "c" ["test"]}))
(expect= false (==
- (struct "a" 1 "b" true)
- (struct "a" 1)))
+ {"a" 1 "b" true}
+ {"a" 1}))
(expect= true (== print print))
(expect= false (== print ==))
'
@@ -42,25 +42,25 @@ describe "logic", ->
(expect= true (!= 1 2))
(expect= true (!= 1 "hello"))
(expect= false (!= "hello" "hello"))
- (expect= false (!= (array 1 2 3) (array 1 2 3)))
- (expect= true (!= (array 1 2 3) (array 1 2 1)))
- (expect= true (!= (array 1 2 3) (array 1 2)))
- (expect= true (!= (array 1 2 3) (array 1 2 3 4)))
+ (expect= false (!= [1 2 3] [1 2 3]))
+ (expect= true (!= [1 2 3] [1 2 1]))
+ (expect= true (!= [1 2 3] [1 2]))
+ (expect= true (!= [1 2 3] [1 2 3 4]))
(expect= false (!=
- (struct "a" 1 "b" true "c" (array "test"))
- (struct "a" 1 "b" true "c" (array "test"))))
+ {"a" 1 "b" true "c" ["test"]}
+ {"a" 1 "b" true "c" ["test"]}))
(expect= true (!=
- (struct "a" 1 "b" false "c" (array "test"))
- (struct "a" 1 "b" true "c" (array "test"))))
+ {"a" 1 "b" false "c" ["test"]}
+ {"a" 1 "b" true "c" ["test"]}))
(expect= true (!=
- (struct "a" 1 "b" true "c" (array "test" "toast"))
- (struct "a" 1 "b" true "c" (array "test"))))
+ {"a" 1 "b" true "c" ["test" "toast"]}
+ {"a" 1 "b" true "c" ["test"]}))
(expect= true (!=
- (struct "a" 1 "b" true)
- (struct "a" 1 "b" true "c" (array "test"))))
+ {"a" 1 "b" true}
+ {"a" 1 "b" true "c" ["test"]}))
(expect= true (!=
- (struct "a" 1 "b" true)
- (struct "a" 1)))
+ {"a" 1 "b" true}
+ {"a" 1}))
(expect= false (!= print print))
(expect= true (!= print ==))
'
diff --git a/spec/lib/math_spec.moon b/spec/lib/math_spec.moon
index 23a353b..40c7abd 100644
--- a/spec/lib/math_spec.moon
+++ b/spec/lib/math_spec.moon
@@ -88,85 +88,83 @@ describe "math", ->
describe "add, sub, mul, div, pow, mod", ->
it "handle scalar/vector", ->
COPILOT\eval_once '
- (expect= (array 3 4 5)
- (+ 1 (array 1 2 3) 1))
+ (expect= [3 4 5]
+ (+ 1 [1 2 3] 1))
- (expect= (array 0 1 2)
- (- (array 1 2 3) 1))
+ (expect= [0 1 2]
+ (- [1 2 3] 1))
- (expect= (array 3 6 9)
- (* 3 (array 1 2 3)))
- (expect= (array 3 6 9)
- (* (array 1 2 3) 3))
+ (expect= [3 6 9]
+ (* 3 [1 2 3]))
+ (expect= [3 6 9]
+ (* [1 2 3] 3))
- (expect= (array 12 9 4)
- (/ 36 (array 3 4 9)))
+ (expect= [12 9 4]
+ (/ 36 [3 4 9]))
- (expect= (array 9 16 25)
- (^ (array 3 4 5) 2))
- (expect= (array 1 2 4 8)
- (^ 2 (array 0 1 2 3)))
+ (expect= [9 16 25]
+ (^ [3 4 5] 2))
+ (expect= [1 2 4 8]
+ (^ 2 [0 1 2 3]))
- (expect= (array 3 0 1)
- (% (array 3 4 5) 4))
+ (expect= [3 0 1]
+ (% [3 4 5] 4))
'
it "handle vector/vector and matrix/matrix", ->
COPILOT\eval_once '
- (expect= (array 5 7 9)
- (+ (array 1 2 3)
- (array 4 5 6)))
+ (expect= [5 7 9]
+ (+ [1 2 3]
+ [4 5 6]))
- (expect= (array (array 11 12)
- (array 13 14))
+ (expect= [[11 12]
+ [13 14]]
(+
- (array (array 1 2)
- (array 3 4))
+ [[1 2]
+ [3 4]]
5
5))
- (expect= (array 2 0 -2)
- (- (array 3 2 1)
- (array 1 2 3)))
+ (expect= [2 0 -2]
+ (- [3 2 1]
+ [1 2 3]))
- (expect= (array 1 -2 -3)
- (- (array -1 2 3)))
+ (expect= [1 -2 -3]
+ (- [-1 2 3]))
'
err = assert.has.error ->
COPILOT\eval_once '
- (+ (array 1 2 3)
- (array 1 2))'
+ (+ [1 2 3]
+ [1 2])'
err = assert.has.error ->
COPILOT\eval_once '
- (+ (array (array 1 2) (array 1 2))
- (array 1 2))'
+ (+ [[1 2] [1 2]]
+ [1 2])'
err = assert.has.error ->
COPILOT\eval_once '
- (- (array 1 2 3)
- (array 1 2))'
+ (- [1 2 3]
+ [1 2])'
err = assert.has.error ->
COPILOT\eval_once '
- (- (array (array 1 2) (array 1 2))
- (array 1 2))'
+ (- [[1 2] [1 2]]
+ [1 2])'
describe "mul", ->
it "handles scalars and matrices", ->
with COPILOT\eval_once '
(* 3
- (array
- (array 1 2)
- (array 4 5)))'
+ [[1 2]
+ [4 5]])'
assert.is.true \is_const!
assert.is.equal '<num[2][2]= [[3 6] [12 15]]>', tostring .result
with COPILOT\eval_once '
- (* (array
- (array 1 2)
- (array 4 5))
+ (* [[1 2]
+ [4 5]]
3)'
assert.is.true \is_const!
assert.is.equal '<num[2][2]= [[3 6] [12 15]]>', tostring .result
@@ -174,90 +172,90 @@ describe "math", ->
it "handles vectors and matrices", ->
with COPILOT\eval_once '
(*
- (array (array 1 0 0)
- (array 0 1 0)
- (array 0 0 1))
- (array 4 5 6))'
+ [[1 0 0]
+ [0 1 0]
+ [0 0 1]]
+ [4 5 6])'
assert.is.true \is_const!
assert.is.equal '<num[3]= [4 5 6]>', tostring .result
with COPILOT\eval_once '
(*
- (array (array 1 0 0)
- (array 0 1 0)
- (array 3 2 1))
- (array 4 5 1))'
+ [[1 0 0]
+ [0 1 0]
+ [3 2 1]]
+ [4 5 1])'
assert.is.true \is_const!
assert.is.equal '<num[3]= [4 5 23]>', tostring .result
it "handles matrices", ->
with COPILOT\eval_once '
(*
- (array (array 1 2 3)
- (array 4 5 6))
- (array (array 10 11)
- (array 20 21)
- (array 30 31)))'
+ [[1 2 3]
+ [4 5 6]]
+ [[10 11]
+ [20 21]
+ [30 31]])'
assert.is.true \is_const!
assert.is.equal '<num[2][2]= [[140 146] [320 335]]>', tostring .result
it "handles everything mixed", ->
with COPILOT\eval_once '
(*
- (array (array 1 2 3)
- (array 4 5 6))
+ [[1 2 3]
+ [4 5 6]]
2
- (array (array 10 11)
- (array 20 21)
- (array 30 31)))'
+ [[10 11]
+ [20 21]
+ [30 31]])'
assert.is.true \is_const!
assert.is.equal '<num[2][2]= [[280 292] [640 670]]>', tostring .result
with COPILOT\eval_once '
(*
- (array (array 1 2 3)
- (array 4 5 6))
+ [[1 2 3]
+ [4 5 6]]
2
- (array (array 10 11)
- (array 20 21)
- (array 30 31))
- (array 4 7))'
+ [[10 11]
+ [20 21]
+ [30 31]]
+ [4 7])'
assert.is.true \is_const!
assert.is.equal '<num[2]= [3164 7250]>', tostring .result
it "errors with wrong sizes (matrix and vector)", ->
err = assert.has.error -> COPILOT\eval_once '
(*
- (array (array 1 2 3)
- (array 4 5 6))
- (array 1 2))'
+ [[1 2 3]
+ [4 5 6]]
+ [1 2])'
-- assert.matches "", err
err = assert.has.error -> COPILOT\eval_once '
(*
- (array 1 2 3)
- (array (array 1 2 3)
- (array 4 5 6)))'
+ [1 2 3]
+ [[1 2 3]
+ [4 5 6]])'
-- assert.matches "", err
it "errors with wrong sizes (matrix)", ->
err = assert.has.error -> COPILOT\eval_once '
(*
- (array (array 1 2 3)
- (array 4 5 6))
- (array (array 1 2)
- (array 4 5)))'
+ [[1 2 3]
+ [4 5 6)]
+ [[1 2]
+ [4 5]])'
-- assert.matches "", err
it "min, max, clamp, huge", ->
COPILOT\eval_once '
- (expect= (array 3 2 1)
- (min (array 3 4 1) (array 5 2 huge)))
- (expect= (array 5 huge 4)
- (max (array 3 huge 4) (array 5 999 2)))
+ (expect= [3 2 1]
+ (min [3 4 1] [5 2 huge]))
+ (expect= [5 huge 4]
+ (max [3 huge 4] [5 999 2]))
- (expect= (array -2 -1 0 1 3.5)
- (clamp -2 3.5 (array -4 -1 0 1 4)))
+ (expect= [-2 -1 0 1 3.5]
+ (clamp -2 3.5 [-4 -1 0 1 4]))
(expect= 1 (inc 0))
(expect= -1 (dec 0))
diff --git a/spec/lib/string_spec.moon b/spec/lib/string_spec.moon
index 859c402..c787609 100644
--- a/spec/lib/string_spec.moon
+++ b/spec/lib/string_spec.moon
@@ -16,22 +16,22 @@ describe "string", ->
it "stringifies arrays", ->
COPILOT\eval_once '
- (expect= "[1 2 3]" (string/str (array 1 2 3)))
- (expect= \'["a" "b" "c"]\' (string/str (array "a" "b" "c")))
+ (expect= "[1 2 3]" (string/str [1 2 3]))
+ (expect= \'["a" "b" "c"]\' (string/str ["a" "b" "c"]))
'
it "stringifies structs", ->
COPILOT\eval_once '
(expect= \'{a: 1 b: true c: "hello"}\'
- (string/str (struct "a" 1
- "b" true
- "c" "hello")))
+ (string/str {"a" 1
+ "b" true
+ "c" "hello"}))
'
it "stringifies deeply", ->
COPILOT\eval_once '
(expect= "{a: {b: [1 2 3]}}"
- (string/str (struct "a" (struct "b" (array 1 2 3)))))
+ (string/str {"a" {"b" [1 2 3]}}))
'
it "joins multiple arguments", ->
@@ -48,23 +48,23 @@ describe "string", ->
describe "concat", ->
it "concatenates string-arrays", ->
COPILOT\eval_once '
- (expect= "hello" (string/concat (array "hello")))
- (expect= "helloworld" (string/concat (array "hello" "world")))
- (expect= "helloobeautifulworld" (string/concat (array "hello" "o" "beautiful" "world")))
+ (expect= "hello" (string/concat ["hello"]))
+ (expect= "helloworld" (string/concat ["hello" "world"]))
+ (expect= "helloobeautifulworld" (string/concat ["hello" "o" "beautiful" "world"]))
'
it "takes custom separator", ->
COPILOT\eval_once '
- (expect= "a, b, c" (string/concat ", " (array "a" "b" "c")))
- (expect= "hello world" (string/concat " " (array "hello" "world")))
- (expect= "hello o beautiful world" (string/concat " " (array "hello" "o" "beautiful" "world")))
+ (expect= "a, b, c" (string/concat ", " ["a" "b" "c"]))
+ (expect= "hello world" (string/concat " " ["hello" "world"]))
+ (expect= "hello o beautiful world" (string/concat " " ["hello" "o" "beautiful" "world"]))
'
describe "join", ->
it "concatenates and stringifies", ->
COPILOT\eval_once '
(expect= "that is 1 beautiful tree" (string/join " " "that is" 1 "beautiful tree"))
- (expect= "my favorite color is [0.9 0.2 1]" (string/join " " "my favorite color is" (array 0.9 0.2 1)))
+ (expect= "my favorite color is [0.9 0.2 1]" (string/join " " "my favorite color is" [0.9 0.2 1]))
(expect= "i_am_snek" (string/join "_" "i" "am" "snek"))
'
diff --git a/spec/lib/struct_spec.moon b/spec/lib/struct_spec.moon
index 9937f99..94dcc5a 100644
--- a/spec/lib/struct_spec.moon
+++ b/spec/lib/struct_spec.moon
@@ -2,50 +2,50 @@ import TestPilot from require 'spec.test_setup'
import T, Struct from require 'alv'
describe "struct", ->
- test = TestPilot '', '(import* struct-)\n'
+ test = TestPilot '', '(import* struct)\n'
ab = Struct { a: T.num, b: T.bool }
describe "(set)", ->
it "can update values", ->
- rt = COPILOT\eval_once '(set (struct "a" 1 "b" false) "a" 2)'
+ rt = COPILOT\eval_once '(set {"a" 1 "b" false} "a" 2)'
assert.is.true rt\is_const!
assert.is.equal ab\mk_const({ a: 2, b: false }), rt.result
it "cannot add members", ->
- err = assert.has.error -> COPILOT\eval_once '(set (struct "a" 1) "b" 2)'
+ err = assert.has.error -> COPILOT\eval_once '(set {"a" 1} "b" 2)'
assert.matches "{a: num} has no 'b' key", err
it "checks value type", ->
- err = assert.has.error -> COPILOT\eval_once '(set (struct "a" 1) "a" "str")'
+ err = assert.has.error -> COPILOT\eval_once '(set {"a" 1} "a" "str")'
assert.matches "expected value for key 'a' to be num, not str", err
describe "(get)", ->
it "can get values", ->
- rt = COPILOT\eval_once '(get (struct "a" 1 "b" false) "a")'
+ rt = COPILOT\eval_once '(get {"a" 1 "b" false} "a")'
assert.is.true rt\is_const!
assert.is.equal '<num= 1>', tostring rt.result
it "checks keys", ->
- err = assert.has.error -> COPILOT\eval_once '(get (struct "a" 1) "b")'
+ err = assert.has.error -> COPILOT\eval_once '(get {"a" 1} "b")'
assert.matches "has no 'b' key", err
describe "(insert)", ->
it "can add members", ->
- rt = COPILOT\eval_once '(insert (struct "b" true) "a" 1)'
+ rt = COPILOT\eval_once '(insert {"b" true} "a" 1)'
assert.is.true rt\is_const!
assert.is.equal ab\mk_const({ a: 1, b: true }), rt.result
it "doesn't clobber existing members", ->
- err = assert.has.error -> COPILOT\eval_once '(insert (struct "a" 1) "a" 2)'
+ err = assert.has.error -> COPILOT\eval_once '(insert {"a" 1} "a" 2)'
assert.matches "key 'a' already exists in value of type {a: num}", err
describe "(remove)", ->
it "can remove members", ->
- rt = COPILOT\eval_once '(remove (struct "a" 1 "b" false "c" "abc") "c")'
+ rt = COPILOT\eval_once '(remove {"a" 1 "b" false "c" "abc"} "c")'
assert.is.true rt\is_const!
assert.is.equal ab\mk_const({ a: 1, b: false }), rt.result
it "checks keys", ->
- err = assert.has.error -> COPILOT\eval_once '(remove (struct "a" 1) "b")'
+ err = assert.has.error -> COPILOT\eval_once '(remove {"a" 1} "b")'
assert.matches "has no 'b' key", err
diff --git a/spec/lib/testing_spec.moon b/spec/lib/testing_spec.moon
index 5be7848..0605c00 100644
--- a/spec/lib/testing_spec.moon
+++ b/spec/lib/testing_spec.moon
@@ -46,7 +46,7 @@ describe "testing", ->
assert.is.true \is_const!
assert.is.nil .result
- with COPILOT\eval_once '(expect= (array 1 2) (array 1 2))'
+ with COPILOT\eval_once '(expect= [1 2] (mkarray 1 2))'
assert.is.true \is_const!
assert.is.nil .result
@@ -58,7 +58,7 @@ describe "testing", ->
assert.has.error -> COPILOT\eval_once '(expect= true false)'
assert.has.error -> COPILOT\eval_once '(expect= "asdf" "bsdf")'
- assert.has.error -> COPILOT\eval_once '(expect= (array 1 2) (array 1 3))'
+ assert.has.error -> COPILOT\eval_once '(expect= [1 2] [1 3])'
it "fails different types", ->
assert.has.error -> COPILOT\eval_once '(expect= true 2)'