I have a use-case where I have lists of predefined "special" points: usually, thes

I have a use-case where I have lists of predefined “special” points: usually, these points are ordinary vectors of floats, but occasionally, they depend on some external variables via some simple algebraic expression, e.g. [0.0, a*b/c, 0.5] (with external variables a, b and c). I’m wondering how best to represent such “sometimes-fixed-sometimes-variable” points in Julia?

Naively, I was thinking of something like

struct VariablePoint
    cnst::Vector{Float64}
    expr::Expr
    is_cnst_or_expr::Bool
end

and then defining an overload on VariablePoint for input parameters that goes either to cnst or eval(expr) depending on is_cnst_or_expr. That feels wrong though because it needs eval.

Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing the appropriate answer back to Slack, or pinging the poster here on Discourse so they can follow this thread.
(Original message :slack:) (More Info)

Try a function instead of an expression

1 Like