slag-plt / scamper

A mini-Scheme implementation designed for teaching, targeting the web
0 stars 1 forks source link

Nested sections do not work as expected #54

Closed dapper-gh closed 1 year ago

dapper-gh commented 1 year ago

Summary

When nesting section expressions, outer sections do not ignore holes in inner sections.

Example Code

(display ((section map (section + 1 _) _) (list 1 2 3)))

This code traces as follows, according to the debugger:

(display ((section map (section + 1 _) _) (list 1 2 3)))
((lambda (_1 _2) (map (lambda (_1) (+ 1 _1)) _2)) (list 1 2 3))

Note that the outer lambda has two arguments (_1 and _2) when only _2 is expected to be part of that lambda.

psosera commented 1 year ago

Thanks, David! The problem arises because I parse/expand sections outside-in rather than inside-out. Subsequently, the inner section's bindings are reinterpreted as the outer section's bindings upon expansion. A true fix for this issue will come with #66, but in the interim, I will try to hack something together to fix the immediate problem.

psosera commented 1 year ago

66 is complete! And with that, an implementation of section that correctly respects nested lambdas. 2.5.0 produces:

(display ((section map (section + 1 _) _) (list 1 2 3)))
> (list 2 3 4)

As expected!