3 ms·
I wanted to share this little project I found. The author has been writing Java re-implementations of the same Scala interpreter over the years as newer JDK ver
by gavinray 5y ago
I wanted to share this little project I found. The author has been writing Java re-implementations of the same Scala interpreter over the years as newer JDK versions & features are released.
With JDK17 and the introduction of Record types, sealed classes/interfaces, and pattern-matching the implementation can come close to ver-batim mirroring the Scala 2 one:
https://github.com/Randgalt/expressive-java/blob/master/java-17/src/main/java/examples/SimpleInterpreter.java#L17 https://github.com/Randgalt/expressive-java/blob/master/java...
> NOTE: Pattern-matching for switch is in second preview for JDK17, so not all features used are stable
Unfortunately, the Scala org website is down right now, so the original/target code can be viewed here for the moment:
https://web.archive.org/web/20200103022853/https://www.scala-lang.org/old/node/56.html https://web.archive.org/web/20200103022853/https://www.scala...
The final feature that is needed to really seal the deal, is part of JEP 405 for destructuring + binding to values in patterns ("Deconstruction patterns"):
https://github.com/Randgalt/expressive-java/issues/3 https://github.com/Randgalt/expressive-java/issues/3
https://openjdk.java.net/jeps/405 https://openjdk.java.net/jeps/405