nth
This commit is contained in:
@@ -17,6 +17,11 @@ class SpecialForms {
|
|||||||
expr: EBlock([for (bodyExp in args) convert(bodyExp)])
|
expr: EBlock([for (bodyExp in args) convert(bodyExp)])
|
||||||
};
|
};
|
||||||
|
|
||||||
|
map["nth"] = (args:Array<ReaderExp>, convert:ExprConversion) -> {
|
||||||
|
pos: Context.currentPos(),
|
||||||
|
expr: EArray(convert(args[0]), convert(args[1]))
|
||||||
|
};
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ class BasicTestCase extends Test {
|
|||||||
Assert.equals(1, arr[-3]);
|
Assert.equals(1, arr[-3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testArrayAccess() {
|
||||||
|
Assert.equals(3, BasicTestCase.myArrayLast);
|
||||||
|
}
|
||||||
|
|
||||||
function testVariadicAdd() {
|
function testVariadicAdd() {
|
||||||
Assert.equals(6, BasicTestCase.mySum);
|
Assert.equals(6, BasicTestCase.mySum);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,9 @@
|
|||||||
// [...] returns a Kiss array (they have special features and convert implicitly)
|
// [...] returns a Kiss array (they have special features and convert implicitly)
|
||||||
(defvar myArray [1 2 3])
|
(defvar myArray [1 2 3])
|
||||||
|
|
||||||
|
// Array access is via nth
|
||||||
|
(defvar myArrayLast (nth myArray -1))
|
||||||
|
|
||||||
// Variadic math uses haxe's Lambda.fold under the hood
|
// Variadic math uses haxe's Lambda.fold under the hood
|
||||||
(defvar mySum (+ 1 2 3))
|
(defvar mySum (+ 1 2 3))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user