From 79d0d30d41edd284aeb4008f09b6c7170e42c9d5 Mon Sep 17 00:00:00 2001 From: Michael Binder Date: Mon, 24 Jun 2024 22:42:12 +0200 Subject: [PATCH] if a variable does not exist in an assignment, it will be created automatically --- environment.go | 6 +++--- example/test.rune | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/environment.go b/environment.go index 0d6d2ea..a06aa6d 100644 --- a/environment.go +++ b/environment.go @@ -36,9 +36,9 @@ func (env *Environment) Get(name string, exp *Expr) interface{} { func (env *Environment) Set(name string, value interface{}, exp *Expr) interface{} { scope := env.Lookup(name) - if scope == nil && env.parent != nil { - Error(exp, "Undefined variable '%s'", name) - } + // if scope == nil && env.parent != nil { + // Error(exp, "Undefined variable '%s'", name) + // } if scope != nil { scope.vars[name] = value } else { diff --git a/example/test.rune b/example/test.rune index a4d86af..9da154e 100644 --- a/example/test.rune +++ b/example/test.rune @@ -1,3 +1,14 @@ +foo = "bar" +exit() + +testFun = fun() { + foo = "bar" + println(foo) +} + +testFun() + +exit() fibonacci = fun(n) { if n <= 0 then return = 0 elif n == 1 then return = 1