Topic: APLX Help : Help on APL language : System Functions & Variables : ⎕EVAL Evaluate external expression
[ Previous | Next | Contents | Index | APL Home ]

www.microapl.co.uk

⎕EVAL Evaluate external expression


The dyadic system function ⎕EVAL allows you to evaluate an arbitrary expression in an external object-oriented environment, provided the architecture supports it.

The left argument is a character vector which specifies the external environment in which you want to evaluate the expression, in the same format as for ⎕NEW. The right argument is a character vector containing an expression which is valid in the target environment.

The main use for ⎕EVAL is for running code is an interpreted language such as Ruby or R, and for setting up variables in the Ruby environment:

      'ruby' ⎕EVAL 's=String.new "Hello there"'
Hello there
      'ruby' ⎕EVAL 's.length'
11
      'ruby' ⎕EVAL 'Math.sqrt(9)'
3

This example shows in the R environment:

      r←'r' ⎕new 'r'
      r.x←2 3⍴⍳6         ⍝ x is an R variable
      r.x
1 2 3
4 5 6

      'r' ⎕eval 'x[2,]'
4 5 6
      'r' ⎕eval 'mean(x[2,])'  
5

Note that the last line could be executed using the alternative syntax:

      r.⎕eval 'mean(x[2,])'
5

⎕EVAL is not supported for .Net or Java:

      '.net' ⎕EVAL '2+2'
Library for architecture '.net' does not support direct evaluation
DOMAIN ERROR
      '.net' ⎕EVAL '2+2'
      ^

See also ⎕CALL, which allows you to call arbitrary 'static' methods in external environments, and the system-method form of ⎕EVAL for R.


Topic: APLX Help : Help on APL language : System Functions & Variables : ⎕EVAL Evaluate external expression
[ Previous | Next | Contents | Index | APL Home ]