Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent function bodies from having tail position #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Prevent function bodies from having tail position #4

wants to merge 1 commit into from

Conversation

shhyou
Copy link
Contributor

@shhyou shhyou commented Apr 30, 2019

This seems to preserve more errortrace information, but I'm not sure why.

For this program, demanding (g 0) triggers the evaluation of x at line 8, which in turn demands (f A).


(define f
  (λ (z) (z 3)))

(define g
  (λ (tt)
    ((λ (x) x)
     (f A))))

(g 0)

With appropriate source information, having e (lc/main.rkt:57) at tail position produces the following backtrace:

$ racket -lt- errortrace edit2.rkt 
do not know what function the free variable `A` stands for
  errortrace...:
   /Volumes/ramdisk/edit2.rkt:4:9: (z 3)
   /Volumes/ramdisk/edit2.rkt:8:12: x

Placing e at non-tail position improves the backtrace to:

$ racket -lt- errortrace edit2.rkt 
do not know what function the free variable `A` stands for
  errortrace...:
   /Volumes/ramdisk/edit2.rkt:4:9: (z 3)
   /Volumes/ramdisk/edit2.rkt:9:5: (f A)
   /Volumes/ramdisk/edit2.rkt:8:12: x
   /Volumes/ramdisk/edit2.rkt:8:4: ((λ (x) x) (f A))
   /Volumes/ramdisk/edit2.rkt:11:0: (g 0)

DrRacket skips the (f A) frame though.

Error Arrows

@rfindler
Copy link
Owner

rfindler commented May 3, 2019

Removing tail position definitely improves error messages / stack traces (as you suggest) but it also can be problematic for space consumption.

But maybe an argument can be made that it is okay for little programs (like homework exercises, which is what this is designed for)? It still makes me nervous, tho.

Maybe a good way to go is to keep track of how many times you have gone non-tail for some given source location and then switch back to tail mode after 10 or so non-tail calls at that spot? That might lead to confusing stacktraces, tho. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants