Substituion of a Let(name, bound, body)-Expression (pseudo code)

32 views Asked by At

one of my tasks in my studies is to consider which of those possibilities of that pseudo-code is right. I have to take care about variable shadowing and variable capturing. Here's following task:

(let y 3 (let y x (let x 1 (* y x))))

and i have to choose one of the answers:

(* 1 3)
(* 1 1)
(* 3 1)
(* 3 3)
(* y 1)
(* 3 x)
(* x 1)
(* y x)

Maybe you could help me out there:)

I already thought about that problem and i already got an example exercise in study-script but that task was a way easier and there's not explain how to solve that expression step-by-step.

My answer would be: (* x 1), because I tried to follow the nesting of these expression through the outer to the inner one, which leads to that solution. But if try to write a programm in a actual language it throw me a exception that the variable x isn't bounded and if I ask chatGPT he give me multiple different answers but the most frequent one was: (* 3 1), so I'm really not sure.....

0

There are 0 answers