4 ms·
When Java gets pattern matching, it will become a more reasonable choice to write an interpreter in.
by grumpyprole 2y ago
When Java gets pattern matching, it will become a more reasonable choice to write an interpreter in.
- CraigJPerry 2y agoIt’s had pattern matching since 16, it’s been expanded since with some syntactic sugar and more recently the introduction of sum types and exhaustiveness to go along with pattern matching.
- grumpyprole 2y agoI think there should be a second edition of this book then :)
- kelnos 2y agoIMO Java's pattern matching is still fairly primitive. Not even up to the level of usefulness of Scala 2.13.
- CraigJPerry 2y agoInteresting - what specifically is missing? I’m thinking we’ve got all of scala’s pattern matching since JEP 406 (2021) but I don’t write Scala so there’s maybe a feature i don’t know. Would be interested to know. switch (thing) { case Integer i when i > 0 -> println(“Positive…”); case … }
- zengid 2y ago+1. When I was following along in the book I wrote the interpeter in C#, and pattern matching allowed me to basically skip needing the code generator and the visitor pattern. YMMV but its great. Essentials of Compilation by Siek does a similar trick with python.