Are there some tutorials on writing hash langs?
and also beautiful racket
One of the summer schools had some materials too?
Note that if you can reuse the existing reader, it is simple to make a new #lang.
Yeah I know, but my students seemed to have difficulty understanding this until I wrote a series of examples. I’m trying to figure out what’s missing from the current resources.
Maybe just concrete examples? (Assuming they already know how to write macros)
Yeah, the guide’s examples are a little terse and might assume familiarity with macros.
It’s worthwhile explaining #%module-begin, #%app and #%datum. They don’t show up in “daily” use.
Yeah, one neat trick that’s missing and I think a helpful starting point is using #%module-begin to expose a normal recursive interpreter as a hash lang.
If they have one from an earlier project, I bet that would be an eye opener.
@wjb I can’t remember whether it’s already in the docs. A simple example would be a to make a stripped down language. Say only allow lambda, if, application and for datums only booleans and integers.
There’s one like that. The thing all these have in common is they start from explaining interposition points, which I think is an intimidating place to start, particularly since most students will be familiar with a different way of implementing a language (like a recursive function over syntax, either interpreter or compiler).
Any use? https://github.com/racket-templates/lang\|https://github.com/racket-templates/lang Contributed by @samth
A couple thoughts on this. 1. What are the learning goals here? Eventually we want to get to using the interposition points, because that’s what building languages in Racket is about. 2. It might be useful to start with the interposition points, and just write those as regular macros. You can do that without a #lang
Yeah I understand why most of the tutorials start there. But it means there’s a lot of understand before you can implement a working prototype, which I think is putting some students off.
E.g., you can get to a running prototype with just #%module-begin wrapping an existing recursive interpreter. That’s 1 interposition point to explain, and then you can motivate the cons of this approach: no integration into Racket, need to roll your own top-level environment and linking…
Coming from a 311 style course, it feels like everything they’ve learned is completely useless, because now you need to understand how to turn an interpreter into a bunch of weird macros
(There’s no particular learning goal; this isn’t part of a course, just some students who had 311 experience, mentioned wanting to use a hash-lang but feeling intimidated by the high learning curve)
Right, I’ve done exactly that implementation myself using a Redex model
Right
Does that tutorial exist somewhere? Or should I just write it
My question about the goal stands though.
The advantage of our use of Redex was a combination of slick demo and then doing tricks to add binding arrows for further demoability
I mean my goal is I have a (very clever) student who said “I want to turn my interpreter into a hash-lang but it seems too hard so I’m not going to”, and I want to figure out why they think it’s too hard, and how to make a more gentle introduction.
But one I showed them the module-begin trick, they dived in.
Did they end up with a Racket style language
I guess I think the big problem here is that at 311 style interpreter isn’t really a useful starting point
Well it’s a typed language, for one, and they’re modeling it in Redex.
I think it is a useful starting point if your goal is to experiment. And it quickly motivates some of the things you want out of the hash-lang system—lots more reuse.
DVH has a mostly-written tutorial on going from a PCF redex model to a proper hash lang: https://docs.racket-lang.org/redex-to-lang@pcf/index.html\|https://docs.racket-lang.org/redex-to-lang@pcf/index.html
Might be a good starting point?
BR makes writing a hash lang feel like writing an interpreter via structural recursion on syntax; it’s just that the recursion isn’t self-evident (the macro expander does it for us), and the case analysis is also gone—the cases are replaced by macros expressing each case. Perhaps drawing that line more clearly is helpful? OTOH, I’m not sure how that helps with a Redex model.