type checks with (the [type] [value])
This commit is contained in:
@@ -48,7 +48,16 @@ class SpecialForms {
|
|||||||
|
|
||||||
// TODO special form for switch
|
// TODO special form for switch
|
||||||
|
|
||||||
// TODO special form for try
|
// Type check syntax:
|
||||||
|
map["the"] = (args:Array<ReaderExp>, convert:ExprConversion) -> {
|
||||||
|
if (args.length != 2) {
|
||||||
|
throw '(the [type] [value]) expression has wrong number of arguments: ${args.length}';
|
||||||
|
}
|
||||||
|
ECheckType(convert(args[1]), switch (args[0]) {
|
||||||
|
case Symbol(type): Helpers.parseTypePath(type);
|
||||||
|
default: throw 'first argument to (the... ) should be a valid type';
|
||||||
|
}).withPos();
|
||||||
|
};
|
||||||
|
|
||||||
map["try"] = (args:Array<ReaderExp>, convert:ExprConversion) -> {
|
map["try"] = (args:Array<ReaderExp>, convert:ExprConversion) -> {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
|
|||||||
@@ -137,4 +137,8 @@ class BasicTestCase extends Test {
|
|||||||
Assert.equals(6, BasicTestCase.myTryCatch(404));
|
Assert.equals(6, BasicTestCase.myTryCatch(404));
|
||||||
Assert.equals(7, BasicTestCase.myTryCatch(["list error"]));
|
Assert.equals(7, BasicTestCase.myTryCatch(["list error"]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testTypeCheck() {
|
||||||
|
Assert.equals(5, BasicTestCase.myTypeCheck());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,3 +83,6 @@
|
|||||||
(catch [:String error] 5)
|
(catch [:String error] 5)
|
||||||
(catch [:Int error] 6)
|
(catch [:Int error] 6)
|
||||||
(catch [error] 7)))
|
(catch [error] 7)))
|
||||||
|
|
||||||
|
(defun myTypeCheck []
|
||||||
|
(the Int 5))
|
||||||
Reference in New Issue
Block a user