My first experiments:
str = "cos(3*t)"
str = "t->" * str
f = @callable_str "t->cos(3*t)" # works!!
f(3)
f = @callable_str str # Generates an error
f(3)
Why does @callable_str
generate an error when using a non-literal string?
Here is the error:
ERROR: LoadError: MethodError: no method matching parse(::Symbol)
Closest candidates are:
parse(::AbstractString; raise, depwarn)
@ Base meta.jl:266
parse(::AbstractString, ::Integer; greedy, raise, depwarn)
@ Base meta.jl:232
Stacktrace:
[1] var"@callable_str"(__source__::LineNumberNode, __module__::Module, ex::Any)
@ Main ~/src/2022/rude/giesekus/GE_rude.jl/alex_report_code_2023-03-24/julia19/optimized/macros.jl:18
[2] eval
@ ./boot.jl:370 [inlined]
[3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1864
[4] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Base ./essentials.jl:816
[5] invokelatest(::Any, ::Any, ::Vararg{Any})
@ Base ./essentials.jl:813
[6] inlineeval(m::Module, code::String, code_line::Int64, code_column::Int64, file::String; softscope::Bool)
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.47.2/scripts/packages/VSCodeServer/src/eval.jl:233
[7] (::VSCodeServer.var"#66#70"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.47.2/scripts/packages/VSCodeServer/src/eval.jl:157
[8] withpath(f::VSCodeServer.var"#66#70"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.47.2/scripts/packages/VSCodeServer/src/repl.jl:249
[9] (::VSCodeServer.var"#65#69"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.47.2/scripts/packages/VSCodeServer/src/eval.jl:155
[10] hideprompt(f::VSCodeServer.var"#65#69"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.47.2/scripts/packages/VSCodeServer/src/repl.jl:38
[11] (::VSCodeServer.var"#64#68"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.47.2/scripts/packages/VSCodeServer/src/eval.jl:126
[12] with_logstate(f::Function, logstate::Any)
@ Base.CoreLogging ./logging.jl:514
[13] with_logger
@ ./logging.jl:626 [inlined]
[14] (::VSCodeServer.var"#63#67"{VSCodeServer.ReplRunCodeRequestParams})()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.47.2/scripts/packages/VSCodeServer/src/eval.jl:225
[15] #invokelatest#2
@ ./essentials.jl:816 [inlined]
[16] invokelatest(::Any)
@ Base ./essentials.jl:813
[17] macro expansion
@ ~/.vscode/extensions/julialang.language-julia-1.47.2/scripts/packages/VSCodeServer/src/eval.jl:34 [inlined]
[18] (::VSCodeServer.var"#61#62")()
@ VSCodeServer ./task.jl:514
in expression starting at /Users/erlebach/src/2022/rude/giesekus/GE_rude.jl/alex_report_code_2023-03-24/julia19/optimized/macros.jl:34
"""