wjb
2022-1-22 19:16:53

Are there some tutorials on writing hash langs?



sorawee
2022-1-22 19:19:05

and also beautiful racket


soegaard2
2022-1-22 19:19:31

One of the summer schools had some materials too?


soegaard2
2022-1-22 19:26:47

Note that if you can reuse the existing reader, it is simple to make a new #lang.


wjb
2022-1-22 19:31:26

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.


soegaard2
2022-1-22 19:33:33

Maybe just concrete examples? (Assuming they already know how to write macros)


wjb
2022-1-22 19:34:50

Yeah, the guide’s examples are a little terse and might assume familiarity with macros.


soegaard2
2022-1-22 19:36:35

It’s worthwhile explaining #%module-begin, #%app and #%datum. They don’t show up in “daily” use.


wjb
2022-1-22 19:37:30

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.


soegaard2
2022-1-22 19:38:53

If they have one from an earlier project, I bet that would be an eye opener.



soegaard2
2022-1-22 19:50:54

@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.


wjb
2022-1-22 19:52:35

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).


spdegabrielle
2022-1-22 20:27:06

samth
2022-1-22 21:01:42

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


wjb
2022-1-22 21:15:32

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…


wjb
2022-1-22 21:16:20

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


wjb
2022-1-22 21:17:24

(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)


samth
2022-1-22 21:18:40

Right, I’ve done exactly that implementation myself using a Redex model


wjb
2022-1-22 21:18:56

Right


wjb
2022-1-22 21:19:21

Does that tutorial exist somewhere? Or should I just write it


samth
2022-1-22 21:19:26

My question about the goal stands though.


samth
2022-1-22 21:20:43

The advantage of our use of Redex was a combination of slick demo and then doing tricks to add binding arrows for further demoability


wjb
2022-1-22 21:21:17

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.


wjb
2022-1-22 21:22:06

But one I showed them the module-begin trick, they dived in.


samth
2022-1-22 21:23:01

Did they end up with a Racket style language


samth
2022-1-22 21:24:21

I guess I think the big problem here is that at 311 style interpreter isn’t really a useful starting point


wjb
2022-1-22 21:24:59

Well it’s a typed language, for one, and they’re modeling it in Redex.


wjb
2022-1-22 21:25:34

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.


camoy
2022-1-22 22:02:21

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


camoy
2022-1-22 22:02:53

Might be a good starting point?


ben.knoble
2022-1-22 22:30:24

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.