eval: add len

This commit is contained in:
2018-05-14 22:03:46 +02:00
parent 4be6927dc2
commit f114369c65
3 changed files with 37 additions and 10 deletions

View File

@@ -94,14 +94,14 @@ func (ast *AST) Pretty() string {
rest = " . " + *val.Rest
}
// TODO: opt
opt := ""
opt := ""
iter := val.Opt.IterFunc()
for kv, ok := iter(); ok; kv, ok = iter() {
opt += "(o " + kv.Key.(string) + " " + kv.Value.(*AST).Pretty() + ")"
}
if val.HasOpt() && (val.HasRest() || len(agg) != 0) {
opt = " " + opt
}
opt += "(o " + kv.Key.(string) + " " + kv.Value.(*AST).Pretty() + ")"
}
if val.HasOpt() && (val.HasRest() || len(agg) != 0) {
opt = " " + opt
}
body := val.Body.Pretty()
return "(fn (" + strings.Join(agg, " ") + rest + opt + ") " + body + ")"
} else if ast.Tag == Char {
@@ -167,5 +167,5 @@ func (f *Func) HasRest() bool {
}
func (f *Func) HasOpt() bool {
return f.Opt.Len() != 0
return f.Opt.Len() != 0
}