macroExpand expand type aliases in lambda

This commit is contained in:
2024-02-17 11:05:33 -07:00
parent 6a1c66cae7
commit c2ab12909f
3 changed files with 15 additions and 1 deletions

View File

@@ -947,4 +947,12 @@ class Helpers {
return result.withPosOf(exp);
}
public static function expandTypeAliases(exp:ReaderExp, k:KissState) {
return switch (exp.def) {
case TypedExp(path, innerExp):
TypedExp(replaceTypeAliases(path, k), innerExp).withPosOf(exp);
default:
expMap(exp, expandTypeAliases.bind(_, k));
};
}
}

View File

@@ -669,7 +669,7 @@ class SpecialForms {
map["lambda"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
var b = wholeExp.expBuilder();
b.callSymbol("lambda", [args[0]].concat([for (exp in args.slice(1)) Kiss.macroExpand(exp, k)]));
b.callSymbol("lambda", [Helpers.expandTypeAliases(args[0], k)].concat([for (exp in args.slice(1)) Kiss.macroExpand(exp, k)]));
};
return map;

View File

@@ -1,4 +1,5 @@
(defAlias &ident Stream kiss.Stream)
(defAlias &type Stream kiss.Stream)
(defMacro makeExample [expression &body b]
`(let [normal ,(printExp expression)
@@ -17,4 +18,9 @@
(normal null)
(expanded null))
(makeExample
(lambda [:Stream s] (Stream.fromString ""))
(normal null)
(expanded null))
)