Thomas Leyshon
Thomas Leyshon

Reputation: 107

Parse and evaluating a string locally?

For languages that allow for meta-programming is it possible to parse and evaluate a string locally? For example within a function? I'm trying to do this in Julia currently but also curious about the ability of other languages?

Upvotes: 0

Views: 520

Answers (1)

Bebotron
Bebotron

Reputation: 443

Is this what you mean?

function foo()
    println("Calling foo")
end

function main(functionName)
    functionCall = @eval $(Symbol(functionName))
    functionCall()
end

Calling main with the function name "foo" string passed evaluates foo

julia> main("foo")
Calling foo

Upvotes: 2

Related Questions