Did you know ... Search Documentation:
Pack pljulia -- prolog/dcg/julia.pl
PublicShow source


@ for macros? ; for keyword arguments

REVIEW \\ for lambda

Julia expression syntax

The expression syntax adopted by this module allows Prolog terms to represent or denote Julia expressions. Let T be the domain of recognised Prolog terms (denoted by type expr), and M be the domain of Julia expressions written in Julia syntax. Then V : T->M is the valuation function which maps Prolog term X to Julia expression V[X]. These are some of the constructs it recognises:

X:>:Y           % |--> V[X]; V[Y]  (sequential evaluation returning second value)
X=Y             % |--> V[X]=V[Y] (assignment, X must denote a valid left-value)
if(X,Y)         % |--> if V[X] then V[Y] end
if(X,Y,Z)       % |--> if V[X] then V[Y] else V[Z] end

+X              % |--> +(V[X])
-X              % |--> -(V[X])
X+Y             % |--> +(V[X],V[Y])
X-Y             % |--> -(V[X],V[Y])
X^Y             % |--> ^(V[X],V[Y])
X*Y             % |--> *(V[X],V[Y])
X/Y             % |--> /(V[X],V[Y])
X\Y             % |--> \(V[X],V[Y])
X.^Y            % |--> .^(V[X],V[Y])
X.*Y            % |--> .*(V[X],V[Y])
X./Y            % |--> ./(V[X],V[Y])
X.\Y            % |--> .\(V[X],V[Y])
X rdiv Y        % |--> //(V[X],V[Y])
X:Y:Z           % |--> colon(V[X],V[Y],V[Z])
X:Z             % |--> colon(V[X],V[Z])
X>Z             % |--> >(V[X],V[Y])
X>=Z            % |--> >=(V[X],V[Y])
X<Z             % |--> <(V[X],V[Y])
X=<Z            % |--> <=(V[X],V[Y])
X==Z            % |--> ==(V[X],V[Y])
[X1,X2,...]     % |--> [ V[X1], V[X2], ... ]

:X              % |--> :V[X] (symbol or abstract syntax tree)
'Inf'           % |--> Inf (positive infinity)
'NaN'           % |--> NaN (not a number)
X`              % |--> ctranpose(V[X]) (conjugate transpose, V[X]')
X`Y             % |--> V[X].V[q(Y)]
X\\Y            % |--> (V[X]) -> V[Y])
q(X)            % wrap V[X] in single quotes (escaping internal quotes)
qq(X)           % wrap V[X] in double quotes (escaping internal double quotes)
arr(Lists)         % multidimensional array from nested lists.
arr(Dims,Lists)    % multidimensional array from nested lists.
int64(Dims,Lists)  % multidimensional array of Int64
float64(Dims,Lists)% multidimensional array of Int64

Things to bypass default formatting

noeval(_)          % triggers a failure when processed
\(P)               % escape and call phrase P directly to generate string
$(X)               % calls pl2jl_hook/2, denotes V[Y] where pljl_hook(X,Y).
'$VAR'(N)          % gets formatted as p_N where N is assumed to be atomic.

All other Prolog atoms are written using write/1. Prolog dictionaries are written as Julia dictionaries. Dictionary keys can be atoms (written as Julia symbols) or small integers (written as Julia integers). Other Prolog terms are assumed to be calls to functions named according to the head functor. Thus V[ <head>( <arg1>, <arg2>, ...) ] = <head>(V[<arg1>, V[<arg2>], ...).

To be done
- Expression language: arr(Vals,Shape,InnerFunctor) - allows efficient representation of arrays of arbitrary things. Will require more strict nested list form.
 term_jlstring(+X:expr, -Y:list(code)) is det
Convert term representing Julia expression to a list of character codes.