In keeping with Field's goal of being a truly experimental platform for writing code, it's always been a given that we're interested in programing languages as a first-class concern (you can see this in our Python-based wriggling around). This is part of what drove us to make the block transforms elements in the text editor in the first place. These elements allow you to make "local languages" because when they are executed they are actually passed off to a (Python) function of your choosing. It's simple to then pass the code to a network socket (for example for Maya integration) or to AppleScript to poke and prod applications across the operating system.
Recently we've been hacking away on supporting a different programming language altogether: Scala. Like Field's use of Jython, Scala is a programming language that's built on-top of the Java VM and that is integrated into it. But there the similarities end: Scala is really an altogether different kind of language from Python. It's strongly typed but with type inference and a very interesting type system, together with a real sense of it's functional programming influence — Scala wants to be a better Java than Java.
This contrast with Python arguably makes it a more interesting thing to include in Field than, say, some other JVM scripting language that's compatible with JSR-223. It also makes it much harder — the Scala community simply isn't that interested in "scripting" per-se.
So, we get to the punchline: the ongoing research project of including Scala support inside Field (using the ScalaPlugin, of course) lets you do this:
The code really sums it all up — there's a new predefined block transform type called scala
that sends anything that's inside it to Scala-land rather than Python.
ScalaPlugin is careful to share the namespace between the Scala world and the Python world, so you can define things (things = vars, objects and classes) in Scala and manipulate them freely in Python and do the same the other way. Specifically classes written in Scala can be instantiated from Python (even subclassed). We're still tweaking many thiings how the variables passed from Python to Scala are typed.
But the most important point is that while the Python namespace is bound to names visible from Scala, the Scala code remains, of course, statically compiled and statically bound. This means that if you reassign values to references in Python these reassignments are invisible to previously compiled Scala code (obviously, values that are just mutated are visible). Should you want to access things from the Python namespace dynamically, Scala knows about a function fromPython[T](name : String) : T
that dynamically grabs things from Python (and makes a "cast" to type T
). Perhaps there's something wonderful with implicit conversions that might make this go away.
There are also some error reporting issues (you'll get a good error message in the output window, but no "red mark" like you do in Python).
But already many things work quite well. Note that functions can be called directly in Python (the apply-sugar from Scala is carried over) and that, while Field has no Scala aware syntax highlighter, Field's Python highlighter doesn't do that bad a job. The view from Scala of Python (unfortunately) is just the view that any other piece of Java has of Jython, which is to say that it's all about PyObjects
's and so on. But we're convinced that there's some good scala library based sugar to make this bridge more seamless, and we'll check it in as soon as we've written it.