(rest [list])

This commit is contained in:
2020-12-07 19:16:22 -07:00
parent 74d070d7b3
commit a13b2db10f
3 changed files with 12 additions and 2 deletions

View File

@@ -55,7 +55,10 @@ class SpecialForms {
makeQuickNth(9, "tenth");
makeQuickNth(-1, "last");
// TODO rest
map["rest"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
wholeExp.checkNumArgs(1, 1, '(rest [list])');
macro ${k.convert(args[0])}.slice(1);
};
// Declare anonymous objects
map["object"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {

View File

@@ -250,6 +250,10 @@ class BasicTestCase extends Test {
function testRange() {
_testRange();
}
function testRest() {
_testRest();
}
}
class BasicObject {

View File

@@ -367,4 +367,7 @@
(set myList (for i (range 7 17 2) i))
(Assert.equals 7 (first myList))
(Assert.equals 9 (second myList))
(Assert.equals 15 (last myList)))
(Assert.equals 15 (last myList)))
(defun _testRest []
(Assert.equals (.toString [2 3 4]) (.toString (rest [1 2 3 4]))))