title: Constructing a procedural DSL based on extensible Java methods
body: <p><strong>The question</strong></p>
  
  <p>How does one create a procedural DSL based on an extensible suite of Java methods that are invoked during the runtime?</p>
  
  <p><strong>More context</strong></p>
  
  <p><em>Example script</em></p>
  
  <p>The following script is a contrived example, but one that I hope captures the point.</p>
  
  <pre><code>result = $add($vector3(1, 2, 3), $vector3(1, 0, 1))
  result.normalize()
  $log(result)
  return result
  </code></pre>
  
  <p>The key is that the DSL is essentially built out of an extensible suite of Java methods that are invoked during interpretation of the script. Ideally this set of allowed methods would be dictated by the engine.</p>
  
  <p>Built-in support for conditionals, loops, primitives, and comments would be helpful.</p>
  
  <p><em>Languages that accomplish something similar</em></p>
  
  <ol>
  <li><p><strong>Apache Velocity</strong> provides extension capabilities through the addition of user-defined objects to the template context. These objects, and the methods scoped to them, are accessible from the Velocity templates by their user-defined name. For related information, see <a href="http://velocity.apache.org/engine/2.0/user-guide.html" rel="nofollow noreferrer">http://velocity.apache.org/engine/2.0/user-guide.html</a> and the discussion of methods. However, Velocity is a templating engine, not meant for procedural scripts.</p></li>
  <li><p><strong>Clojure</strong> also provides similar functionality (<a href="https://clojure.org/reference/java_interop" rel="nofollow noreferrer">https://clojure.org/reference/java_interop</a>.) However, the Clojure syntax is less than intuitive.</p></li>
  <li><p><strong>Groovy</strong> is a very powerful Java-based scripting language. In fact, it seems too powerful for my needs. I specifically do not want the full power of Java at the hands of these scripts. There seem to be extensions as in Groovy Sandbox discussed here (<a href="https://stackoverflow.com/questions/26017584/how-to-block-access-to-some-classes-when-executing-groovy-scripts-from-java">How to block access to some classes, when executing groovy scripts from java?</a>) but it seems like there must be a language in which this simplicity is a first-class feature.</p></li>
  </ol>