Concatenative-dsl as rust macros?


EDIT: changed “Forth” to “ConcatenativeLangauge”

  1. I am a big fan of Rust’s type system (struct, enum traits, borrow checker)

  2. There are times I also like the succintness of ConcatenativeLanguage’s stack based system.

  3. Has anyone managed to implement a ConcatenativeLanguage-dsl as Rust macros?/////

Note: I am not asking for ConcatenativeLanguage interpreter in Rust or ConcatenativeLanguage VM in Rust. I want the “ConcatenativeLanguage” to be operating directly on Rust primitives and to go through Rust’s type checker.

I an mentally thinking that we can abuse Rust’s tuple support as a “typed stack” (since most ConcatenativeLanguage words tend to not use too many stack elements anyway).

Ideas / thoughts? :slight_smile:

Please no comments of “why the $&@( would you want to do that” – those are not particularly useful. What I am interested in is – if we tried to do this, what can we achieve by abusing Rust’s macros and what interesting DSLs can we get?



You can get a compile time heterogeneous type safe stack like so,
(lots of buzz words)

If you want more control or privacy than what tuples offer, you can swap over to using your own types instead of tuples.



Where can I learn more about this? Is this code from something larger, or did you just write it from scratch?

It reminds me of the “Add” from typenum:<PInt<Ur>>

The way it defines Push/Pop as traits and then allows typesafe heterogeneous stacks is quite clever.



From scratch, I played around with stuff like this while trying to understand the madness that is type-num

1 Like