-
Notifications
You must be signed in to change notification settings - Fork 0
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
[WIP] Tree interpreter #1
Open
porglezomp
wants to merge
22
commits into
master
Choose a base branch
from
tree-interpreter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loop bindings allow "tail calls" in loops without the need to do tail call analysis, and so they're a good quick and dirty way to make the language more useful.
porglezomp
force-pushed
the
tree-interpreter
branch
from
January 4, 2017 02:55
b8b5129
to
ec5a1cb
Compare
Holes are values that can be filled in later with the hole/fill function. They're useful for manually implementing tail-recursion-modulo-cons, which is where you fill in the second part of a cons later so that you can make a tail call. It's possible to use the hole function unsafely: if you make a cyclic structure it will never be collected. Unsafe example: (let! rest (hole)) (let! all-ones (cons 1 rest)) (hole/fill rest all-ones) now all-ones is a circular list! Useful example: (defn (list/map f xs) (let! result (hole)) (loop ((xs xs) (spot result)) (if (nil? xs) (break (hole/fill spot nil))) (let! new-spot (hole)) (hole/fill spot (cons (f (car xs)) new-spot)) (continue (cdr xs) new-spot)) result) Here we define map tail recursively, and without having to do any post-processing like reversing the list.
Pretty-print tuples as #tuple or #tuple<tag>. Add instructions for getting and setting the tuple tag. Make struct generation set the tag inside the constructor. Thanks to Roshni for pair programming on this, I had fun explaining it.
Rewrite (#tuple<cons> 1 (#tuple<cons> 2 ())) as (1 2) and (#tuple<cons> 1 2) as (1 . 2).
For instance, a symbol like a will print as 'a in the alternate printing mode. Now the repl prints using {:#} instead of {} to get the quoting.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Run the code by directly walking the AST