Browse Source

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

simon 3 years ago
parent
commit
7f8c85741a
1 changed files with 2 additions and 0 deletions
  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())
 			}