X

Sundararajan's Weblog

  • Java
    July 21, 2006

More updates to scripting.dev.java.net

Guest Author
Recent updates to scripting.dev.java.net:
  1. Updated Scheme JSR-223 script engine to use the latest version (1.15.1) of SISC (Second Interpreter of Scheme Code) intepreter. SISC supports is a complete implementation of the language. The entire R5RS Scheme standard is supported, no exceptions - including continuations!
  2. Updated OGNL (Object Graph Navigation Language) JSR-223 script engine to use the latest version (2.6.7) of the implementation. This is (lightweight) expression language for getting and setting properties of Java objects. I like the BigInteger and BigDecimal literals and direct operator support on those types.
  3. Fixed Groovy JSR-223 script engine to give an illusion of single engine level scope for functions. Previously, it was not possible to define a Groovy "global" function in one ScriptEngine.eval() call and call the same in subsequent ScriptEngine.eval() calls. This is because internally, each evaled code is compiled as a separate ScriptXXX class. i.e., all global functions in the evaled code go into a class derived from Script class. To give an illusion of single engine level scope for "global" functions, we create a map of method closures from all ScriptXXX instances created and search there for global functions (using Groovy's MetaClass mechanism). With this change, the engine behaves as if there is a single global functions scope per ScriptEngine instance. Groovy's Meta Object Protocol (MOP) is really powerful indeed.

Join the discussion

Comments ( 2 )
  • Alexis MP Saturday, July 22, 2006
    Can you have global functions/attributes with JavaScript/Rhino?
  • A. Sundararajan Saturday, July 22, 2006
    Hi Alexis MP: Yes, we can have global functions and variables with JavaScript/Rhino. It is supported by language. All top-level variables and functions are actually fields and methods of global "this" object. We can access a global variable by name "x", either as "x" or "this.x" within the toplevel scope. Also, JavaScript treats functions as function-valued properties. (i.e., first-class values). So
       function hello() { print("hello"); }

    and
       var hello = function() { print("hello"); }

    are same. Did I answer your question?
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.