exprCase match :Typed exps

This commit is contained in:
2021-11-27 18:57:49 -07:00
parent d50396eee3
commit ad54a02781
3 changed files with 13 additions and 4 deletions

View File

@@ -392,9 +392,10 @@ class Prelude {
return v;
}
public static function symbolNameValue(s:ReaderExp):String {
public static function symbolNameValue(s:ReaderExp, allowTyped = false):String {
return switch (s.def) {
case Symbol(name): name;
case TypedExp(_, innerExp) if (allowTyped): symbolNameValue(innerExp, false);
default: throw 'expected $s to be a plain symbol';
};
}
@@ -402,13 +403,14 @@ class Prelude {
// ReaderExp helpers for macros:
public static function symbol(?name:String):ReaderExpDef {
if (name == null)
name = '_${Uuid.v4().toShort()}';
name = '_${Uuid.v4().toShort()}'; // TODO the underscore will make fields defined with gensym names all PRIVATE!
return Symbol(name);
}
public static function symbolName(s:ReaderExp):ReaderExpDef {
public static function symbolName(s:ReaderExp, allowTyped = false):ReaderExpDef {
return switch (s.def) {
case Symbol(name): StrExp(name);
case TypedExp(_, innerExp) if (allowTyped): symbolName(innerExp, false);
default: throw 'expected $s to be a plain symbol';
};
}