#1562 Fantom Scripting and facet generating code

DanielFath Thu 23 Jun 2011

  • Is there a way to use Fantom as a scripting language?

For example (filename and file content below):

echo.fan
=======================
echo("Hello World")

running this echo.fan will create a console with Hello world.

  • Is it possible to create a facet that would automatically generate, toStr, hash and equals for a class? How would the code generation work - would I have to inject the appropriate code at runtime or would I need to change the compiler itself?

brian Thu 23 Jun 2011

Is there a way to use Fantom as a scripting language?

Well you can just create a text file and run it as a script. For example all the build scripts work that way. If you are asking if you can omit the class/main method declaration, then no (each source file must be a valid compilation unit).

Is it possible to create a facet that would automatically generate

Not today, facets can't inject compile-time code. Something I've considered as a nice future. But you can do this fairly easily just creating a base class that uses reflection. I know there are concerns about performance, but in most cases it isn't going to matter. Plus when we can switch to use method handles, I expect the reflection solution will be pretty much as fast as the native code solution.

Login or Signup to reply.