Motivation

The type JRef was created to support return of a Julia expression of any type beyond basic types without having to map that type to an equivalent Javascript type. The task of establishing such a mapping is still an objective, however, and will build off this start. In the mean time, this offers a simple way to connect Julia functionality that produces values of non basic types to Javascript variables and then subsequently use those variables as input.

Gain of Efficiency

As an added benefit, since JRefs are just wrappers for the corresponding Julia values, the need for introspection and subsequent instantiation of the corresponding Javascript value is avoided. Likewise the need to re-evaluate and convert back to Julia from Javascript when a JRef is used as input is also avoided.

Example

For example assuming that the Julia package RDataSets is installed using that standard package manager

julia> Pkg.add("RDatasets")

Then as per the example given in the RDataSet README, a new dataset value can be created and exported as a JRef, and then subsequently used as input to string.

var julia = require('node-julia');
var d;

julia.eval('using RDatasets');
d = julia.eval('dataset("boot","neuro")');
console.log(julia.exec('string',d));

The output of string is then printed to the console

469x6 DataFrames.DataFrame
| Row | V1     | V2     | V3     | V4   | V5    | V6    |
|-----|--------|--------|--------|------|-------|-------|
| 1   | NA     | -203.7 | -84.1  | 18.5 | NA    | NA    |
| 2   | NA     | -203.0 | -97.8  | 25.8 | 134.7 | NA    |
| 3   | NA     | -249.0 | -92.1  | 27.8 | 177.1 | NA    |
| 4   | NA     | -231.5 | -97.5  | 27.0 | 150.3 | NA    |
| 5   | NA     | NA     | -130.1 | 25.8 | 160.0 | NA    |
| 6   | NA     | -223.1 | -70.7  | 62.1 | 197.5 | NA    |
| 7   | NA     | -164.8 | -12.2  | 76.8 | 202.8 | NA    |
| 8   | NA     | -221.6 | -81.9  | 27.5 | 144.5 | NA    |
⋮
| 461 | NA     | -163.2 | -43.6  | 69.5 | 173.9 | NA    |
| 462 | NA     | -207.3 | -88.3  | 9.6  | 104.1 | 218.0 |
| 463 | -242.6 | -142.0 | -21.8  | 69.8 | 148.7 | NA    |
| 464 | -235.9 | -128.8 | -33.1  | 68.8 | 177.1 | NA    |
| 465 | NA     | -140.8 | -38.7  | 58.1 | 186.3 | NA    |
| 466 | NA     | -149.5 | -40.3  | 62.8 | 139.7 | 242.5 |
| 467 | -247.6 | -157.8 | -53.3  | 28.3 | 122.9 | 227.6 |
| 468 | NA     | -154.9 | -50.8  | 28.1 | 119.9 | 201.1 |
| 469 | NA     | -180.7 | -70.9  | 33.7 | 114.8 | 222.5 |