Basics
Here we show how to wrap Julia arrays and create an Impero expression.
Numbers
using Impero, Plots, GraphRecipes
@wrapper a=1 b=2;
We can even plot it
c = a+b
plot(c)
and compute values with it
compute(c)
3
Arrays
We can also wrap Arrays or Matrices
using Impero, Plots, GraphRecipes
array_1 = ones(3)
array_2 = ones(3)
@wrapper a=array_1 b=array_2;
b
and compute values with it
c = a+b
compute(c)
3-element Array{Float64,1}: 2.0 2.0 2.0
Note that Impero does not provide an error check for improperly defined Julia objects on this level since
c = a*b
(a*b)
is fine, but compute(c)
will yield an error.
User Defined Structs
As long as a user has the operations
unary_operators
7-element Array{Any,1}: ["Negative", "-"] ["SquareRoot", "√"] ["Tanh", "tanh"] ["Sin", "sin"] ["Cos", "cos"] ["Tan", "tan"] ["Exp", "exp"]
and
binary_operators
3-element Array{Any,1}: ["Add", "+"] ["Multiply", "*"] ["Exponentiation", "^"]
defined then one can use Impero exactly as before
Converting to Julia Expressions
Any Impero object can be converted to a Julia expression through the to_expr function
@wrapper a=1 b=2
impero_expr = a+b
(a+b)
julia_expr = to_expr(impero_expr)
:((+)(a, b))