Creating Languages in Racket (2011)
queue.acm.org
queue.acm.org
I have many ideas for little DSLs in Racket, but I am too slow and am slogging my way through learning how to create them.
What type of material would you like to see?
What parts of the API are you finding difficult?
Pretty basic, but it helped me a bit.
You seem to say, I wish there was a book on X, but there is only this book on X. What more do you want? I don't mean that rhetorically, what additional things would you like to see covered?
1. You need to install the Beautiful Racket package, which makes the starting point for creating the languages easier, but is not representative of how it's used in the Racket Docs (not that I'm saying the Racket docs have a better intro)
2. Uses Brain Fuck. It feels like there has to be a language that fits in between unintelligible but easy to parse, and extremely verbose and complex. (It's probably scheme but that's taken in this context)
And sometimes I just need to see the same problem from a few different angles before it will stick. That's why Greg's Fear of Macros wasn't able to take me all the way to a comfortable place with macros.
I think BR is a great book, and I definitely learned a lot from it, I'll probably go back to it at some point to see if I can get it to click. I've been on a Racket kick recently so I've got a decent amount of hours into the language.
Also I'm always struck with a feeling when I'm coding in Racket where I go "Would a dsl be good here?" I know Racket makes it easy but I don't even know about what makes a good dsl, or how certain dsls might be harder than other based on the way Racket does L.O.P. Again this might just be from inexperience.
Lastly I would also like to see some examples of typed languages being created using typed Racket. I know there is the Turnstile library, but from my understanding it makes it easier to created typed languages, but that the possibility was there before. I'd rather learn the hard unabstracted way first before moving to using a library.
I wish there was a long tutorial on DSLs + static analysis, preferably abstract interpretation.
Develop a DSL that is a bit beyond a toy example, and show how to carry out static analysis. All in one place.
I think this would help a lot towards making the goal of Racket, language-oriented design, more popular.
A language is more than just a reader and expander for toy languages. It also includes domain specific editor functionality and domain specific errors, among other things (like understanding macros and phases at a deeper level).
Racket Programming the Fun Way An introduction to the Racket functional programming language and DrRacket development environment to explore topics in mathematics (mostly recreational) and computer science.
Two similar cases. One is Typescript. That's a new language with different syntax, a new compiler which targets JS. It also provides its own tooling for IDEs. Another is Python. Over time there were PEPs to add syntax for type hints, and now type systems are being added to the language.
When Racket did this, they were able to do it in Racket without adding more features to the compiler or IDE. There's built in support for static analysis, compiler errors, editor integration. Not to mention a way to organize all the information you need to do type checking in the compile steps, and make that information accessible in the right places. The new type safe Racket was built using plain ol Racket.
There's a reasonably accessible paper about this here: https://www2.ccs.neu.edu/racket/pubs/scheme2007-ctf.pdf
So here are some of my ideas:
1. Play around with static analysis checks. I want to rebuild Typescript style structural inference to Racket. I like how TS is unsound (has no runtime performance penalty for mixing untyped code), and is easily disabled via any if it's in the way. I love the focus on great error messages. Maybe one day I will contribute to Typed Racket :)
Making your own compiler error appear in Racket is just 5 lines of code. https://gist.github.com/srcreigh/a0a087adc26e15af0160e8866d4...
2. New syntax for creating structs. Racket had structs that are initialized like (point 1 2). What if you want keyword syntax ie (point #:x 1 #:y 2)? What if you want that to work with match too? Do you want a JS-style syntax such as (point #:x #:y 2) which pulls in x as an identifier? You can do all this! The rebellion library is pretty awesome in this regard [1], with some sample usage of it in a script here [2].
[1]: https://docs.racket-lang.org/rebellion/Data_Types.html [2]: https://github.com/srcreigh/shift-remapper/blob/main/generat...
This is already done. See https://github.com/racket/typed-racket/pull/952 for RFC and https://github.com/racket/typed-racket/pull/948 for the implementation.
It's exciting to think of "Deep" checking as a complement to optional checking. Use a mix of both in one code base to play their strengths. For example it'd be great to define a deep type checked module for parsing data. You get static errors and runtime validation too. But, also, use that module from an optionally type checked module, which doesn't add any extra runtime costs if some of your other code / dependencies are untyped.
Edit: Also Programming Languages: Application and Interpretation, which I haven't been through yet, so can't endorse fully: https://cs.brown.edu/~sk/Publications/Books/ProgLangs/2007-0...
The other thing worth mentioning is Racketeers often use their favourite editor, only switching to DrRacket or Racket Mode when they need specific functionality.
Everything seems to be emacs/DrRacket focussed from what I see.
Works with Clojure, Racket, Fennel and Janet.
A common pattern for Vim users is to happily code in Vim and occasionally switch DrRacket for specific tasks. And use the command line tools - https://docs.racket-lang.org/raco/index.html
Racket seems like a good choice; have never heard of it before. Anyone know the pros/cons/alternatives?
What's yours about?
Entirely declarative, low-tech, almost like pseudo-code.
You want to extend this piece of software to suit your needs, but aren't a fan of Racket, extend it in a language with Javascript like, Python like, Java like syntax etc (that ultimately compiles to Racket). An example would be a Game Engine in Racket, that has bindings to other languages a la the Godot Engine, or some other piece of standalone software.