HuoLanguage / huo

interpreted language written in C
MIT License
212 stars 21 forks source link

Return example regression #30

Closed TheLoneWolfling closed 8 years ago

TheLoneWolfling commented 8 years ago

For reference:

(def pair x y (return [x, y]))
(def nest x y (return [x, [1, y]]))
(let z (pair 10 1))
(let y (nest "hey" "you"))
(print x)
(print y)

Previously:

[ 10, 1 ]
[ "hey", [ 1, "you" ] ]

Now:

[ "x", "y" ]
[ "x", [ 1, "y" ] ]
TheLoneWolfling commented 8 years ago

Found the problem:

This is a problem with doing things lazily - in this case, binding late. What's happening is that nothing ever actually goes over the array to substitute variables for their values. I.e. here.

incrediblesound commented 8 years ago

I see, so the let_bind functions store x and y as references to the function parameters inside the scope of the function, but when that value is returned the scope is lost and those variables loose meaning. That's slightly painful, but I think what needs to be done is to replace those variables with the values before exiting the function scope, and thankfully we have acess to both the value and the scope around line 136 in execute.c.