Phases, Scala macros for multiphase classes
Phases, Scala macros for multiphase classes
In adopting a functional style, I've found that I'm most tempted to break discipline when representing a single conceptual object that transitions between phases (usually before and after initialization). An arbitrary state diagram can be represented with a collection of immutable objects, but usually with a lot of boilerplate code, especially if most fields stay the same and have to be copied from object to object. I've often wondered why programming languages don't have a facility for generating, e.g. "five classes that differ in these five ways, with the following transitions between them." Beamer, a LaTeX package for making presentations, has such a thing for making a sequence of slides that differ in only one new bullet point. This is a hard question to ask a search engine because if such a thing existed, I wouldn't know what it's called. So I made it: https://github.com/jpivarski/phases is a Scala implementation of the idea using compile-time macros. I'm in the process of making it more easily deployable, but it can be tested by checking it out and changing/adding to its unit tests. This is also my first HN post. Let me know what you think!
Share cardActual performance
Launch Intel predictions
Analyze your own launch →Correct prediction on native model
Similar products
Synesthesia – Optimizing brainfuck compiler implemented as Nim macros
YakshaLisp – Lisp dialect and macros for Yaksha lang
YakshaLisp – Macros for Yaksha and Lisp Dialect
Zig's defer/errdefer for c99 and gnu11 C via macros
8cc.cr – compile-time C compiler implemented as Crystal macros
Same-tbh – vim-like macros for bash
A set of dbg() macros for C
Unbug – Rust macros for programmatically invoking breakpoints
Clojure Macros – Lessons from unspoken symbols
Keysmith – Create macros for your Mac (and the web)