瀏覽代碼

fix built-in function len(), can be supported Array object.

simon 3 年之前
父節點
當前提交
7f8c85741a
共有 1 個文件被更改,包括 2 次插入0 次删除
  1. 2 0
      evaluator/builtins.go

+ 2 - 0
evaluator/builtins.go

@@ -12,6 +12,8 @@ var builtins = map[string]*object.Builtin{
 			switch arg := args[0].(type) {
 			case *object.String:
 				return &object.Integer{Value: int64(len(arg.Value))}
+			case *object.Array:
+				return &object.Integer{Value: int64(len(arg.Elements))}
 			default:
 				return newError("argument to `len` not supported, got %s", args[0].Type())
 			}