Add a "typeof" builtin

This commit is contained in:
Cheer Xiao 2015-01-19 22:04:37 +01:00
parent 4fa9f46759
commit a25ffba632

View File

@ -21,6 +21,7 @@ type builtinFunc struct {
var builtinFuncs = map[string]builtinFunc{
"fn": builtinFunc{fn, [2]StreamType{}},
"put": builtinFunc{put, [2]StreamType{0, chanStream}},
"typeof": builtinFunc{typeof, [2]StreamType{0, fdStream}},
"print": builtinFunc{print, [2]StreamType{0, fdStream}},
"println": builtinFunc{println, [2]StreamType{0, fdStream}},
"printchan": builtinFunc{printchan, [2]StreamType{chanStream, fdStream}},
@ -66,6 +67,14 @@ func put(ev *Evaluator, args []Value) string {
return ""
}
func typeof(ev *Evaluator, args []Value) string {
out := ev.ports[1].ch
for _, a := range args {
out <- NewString(fmt.Sprintf("%#v", a.Type()))
}
return ""
}
func print(ev *Evaluator, args []Value) string {
out := ev.ports[1].f
for _, a := range args {