Skip to content

Commit

Permalink
if a variable does not exist in an assignment, it will be created aut…
Browse files Browse the repository at this point in the history
…omatically
  • Loading branch information
RednibCoding committed Jun 24, 2024
1 parent 2fdff20 commit 79d0d30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions example/test.rune
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 79d0d30

Please sign in to comment.