I am trying to write a struct with members to manipulate symbolic variables. I am a newbie to Julia. I have programmed in python using sympy for symbolic algebra. Here is the code I have so far -
using Symbolics, SymbolicUtils
mutable struct SYMBOLS
num_vars::Int
latex_map::Dict
vars::Vector{SymbolicUtils.Sym{Real}}
add
latex
dump
end
function Symbols_add(s::String)
syms = split(s," ")
n = length(syms)
for i in 1:n
Symbols.latex_map[Symbols.vars[i]] = syms[i+Symbols.num_vars]
end
Symbols.num_vars = Symbols.num_vars+n
return Symbols.var[Symbols.num_vars:Symbols.num_vars-n]
end
function Symbols_latex(sym::SymbolicUtils.Sym{Real})
return Symbols.latex_map(sym)
end
function Symbols_dump()
for s in Symbols.var_lst
println(Symbols.latex_map[s])
end
end
Symbols = SYMBOLS(0,Dict(),@variables X[1:50],Symbols_add,Symbols_latex,Symbols_dump)
(x,y,z) = Symbols.add("x y z")
(a,b) = Symbols.add(raw"\alpha \beta")
Symbols.dump()
and this is my error message -
ERROR: LoadError: invalid redefinition of constant Symbols_add
Stacktrace:
[1] top-level scope
@ ~/MyJulia/MySymbols.jl:32
in expression starting at /home/brombo/MyJulia/MySymbols.jl:32
I feel that I must be declaring the types of the members of the SYMBOLS struct or the the types of the functions I entered into the SYMBOLS constructor incorrectly but can find no examples of how to do it correctly. Documentation of struct with members that a functions that are not one-line functions seems to be almost non-existent. Any suggestions would be appreciated.