a small step forward(?). If you illustrate the typical cases of formulas used, perhaps something can be added
I realize that the idea and above all the implementation is really naive and, I fear, not very efficient.
But let’s play with Julia’s expressions and while waiting for ideas for improvement, I’ll give you a small step forward(?).
If you illustrate the typical cases of formulas used, perhaps something can be added
julia> function str2func(str)
lff=findfirst('(', str)
op=df[str[1:lff-1]]
if !occursin('(',str[lff+1:end])
par=split(str[lff+1:end-1],',')
tp=tryparse.(Int,par)
opxy=(x,y)->(b->(c->op(c,b)))(x)(y)
if all(isnothing,tp)
return opxy
else
n=only(filter(!isnothing,tp))
return z->opxy(n,z)
end
else
par=split(str[lff+1:end-1],"),")
par[1:end-1] .*=')'
return (x...)->op([str2func(p)(var) for (p,var) in zip(par,x)]...)
end
end
str2func (generic function with 1 method)
julia> str= "+(*(3,x),*(2,y))"
"+(*(3,x),*(2,y))"
julia> str2func(str)(3,3)
15
julia> str= "*(+(3,x),+(2,y))"
"*(+(3,x),+(2,y))"
julia> str2func(str)(2,3)
25
julia> str= "+(3,x)"
"+(3,x)"
julia> str2func(str)(-3)
0
I posted an updated version of the script here