You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(define (g a) (let ((b 3)) (* a b)))
(display (g 2))
The let expression above is transformed into the one below, which is perfectly fine.
(define (f a) ((lambda (b) (* a b)) 3))
(display (f 2))
The problem arises when a lambda expression refers to a variable that has been bound in a nested manner outside of it. In this case, that is a. The result for both of these is 9, but it should be 6. The first argument to f or g is referred to as [rbp + 16] as a stack offset. The bound variable b is also referred to as [rbp + 16] since it is the first argument passed to that function. That creates a collision. I believe that this is part of what makes the funarg problem so difficult.
In order for this code to work, I would need a record structure storing the current bound variables within the environment with a pointer to that environment's enclosing environment, if any. Newly bound variables would have to live on the heap rather than the stack. Seeing as my compiler is built fundamentally on passing arguments via the stack I do not know when this problem can be solved.
The text was updated successfully, but these errors were encountered:
I recently added
let
as a feature:The let expression above is transformed into the one below, which is perfectly fine.
The problem arises when a lambda expression refers to a variable that has been bound in a nested manner outside of it. In this case, that is
a
. The result for both of these is 9, but it should be 6. The first argument tof
org
is referred to as[rbp + 16]
as a stack offset. The bound variableb
is also referred to as[rbp + 16]
since it is the first argument passed to that function. That creates a collision. I believe that this is part of what makes the funarg problem so difficult.In order for this code to work, I would need a record structure storing the current bound variables within the environment with a pointer to that environment's enclosing environment, if any. Newly bound variables would have to live on the heap rather than the stack. Seeing as my compiler is built fundamentally on passing arguments via the stack I do not know when this problem can be solved.
The text was updated successfully, but these errors were encountered: