Simple REPL Implementation
Scott Rostrup
Hey Patrick,
Thanks, Scott |
|
Hi Scott. Your implementation is along the same lines as what I would write if I were writing a fresh s-expression parser and I wanted complete control over the syntax. The only line that stands out as suspicious is the
Cheers. -Patrick |
|
Scott Rostrup
Thanks Patrick, I don't need complete control over the syntax actually, I would be happy to reuse stanza's and take any shortcuts I can. The read-line sounds like was going for with the unwrap, thanks for the suggestion.
follow up question, is there a way to print type information manually for debugging/comprehension purposes? Like a typeof function or something? ~Scott |
|
Hi Scott. Hmm there is an internal For now, you can copy and paste it into your own code, for quick and dirty debugging purposes. (Don't fret about how it works though. It's essentially black magic.)
|
|
Scott Rostrup
Thanks! That was exactly the kind of thing I was looking for.
For context, myself and some friends are implementing our own microkanren's this week (http://webyrd.net/scheme-2013/papers/HemannMuKanren2013.pdf) and I thought it was a good opportunity to use stanza. Cheers, Scott |
|
Thanks for the great reference. I've been interested in Kanren since I went through The Reasoned Schemer. It's great that they've condensed the implementation down so far. |
|
Scott Rostrup
Yes it's pretty remarkable, but you still need scheme :) So basically a super basic scheme interpreter is where I have gotten with my implementation. I decided the fastest course of action was to build a scheme interpreter and then just run the scheme version in it, then migrate things over once I understand them better. |
|
Hi Scott. Thank you very much for taking the time to document your learning process. It's very helpful for us! You have a very good point about the union types. It's not a common language feature and it is used so prevalently in Stanza that it should be explained in more detail. Type aliases are on the very top of our implementation priority list for the next version. So hold tight! I also feel your pain when the type annotations themselves start to get too long. This will be fixed before long. And I'm glad that you found the optional type system helpful for making your development process more incremental. That is exactly what we were hoping for and we're glad that it worked out! -Patrick |
|
Scott Rostrup
Just an update been plugging away at this a bit more, it seems to have turned into an sicp style meta circular interpreter implementation, https://github.com/sarostru/doggerel/blob/master/skanren/scheme.stanza . It's passed the size of being able to just kind of hack on so I'm starting to go through and add tests to solidify the functionality.
I wanted to add quoting but wasn't sure of the best way to do it, is there a way I could inherit stanza's quoting? I'm using the reader package already to get the s expressions. ~Scott |
|
Looks pretty cool. The meta circular interpreter is certainly a work of art. You can inherit Stanza's quoting by just looking for the automatically-inserted So, if the user types something like this:
The lexer returns the s-expression:
Thus the quoted s-expression is always the second element in the list that starts with -Patrick |
|
Scott Rostrup
Thanks Patrick,
So it seems like I'm doing ok for the quoting, but what about doing quasi quoting? e.g. something like this:
``` `(1 ,(+ 1 1) 3) ```
Another thing I was wondering about, how to define a struct such that equality on it only returns whether the objects reference the same object without inspecting any of the fields? > values of immutable types are defined to be equal if their subfields are equal. Different mutable values, such as arrays, are never defined to be equal unless they refer to the same object. |
|
Hi Scott. For quasiquoting, you need to do two things:
For the first step, you have to choose something other than comma as Stanza's reader treats commas as whitespace. Stanza uses For the second step, you should write a function that looks something like this:
For defining a struct that has a fast equality check, you have to give an integer ID field to the struct. For example:
The above assumes that Cheers. -Patrick |
|
Scott Rostrup
I really appreciate your detailed answers Patrick, this is super helpful, thanks!
|
|
No problem at all Scott. Hope you're enjoying your time with Stanza! |
|