Closed ahbarnett closed 9 months ago
It broke in v1.6. The problem is that the session name needs to be a literal Symbol
, while variables of type Symbol
are no longer accepted. This is why @gp :fig1 ...
works while @gp s ...
raises an error.
The advantage is that a @gp
invocation now involves exactly one session.
Sorry for this breaking change, but I had to rationalize a bit the syntax...
If you still wish to use a Symbol
in a variable you can copy/paste the code generated by the @gp
macro, e.g.:
@macroexpand @gp :fig1 rand(10) "w l"
quote
local gp = Gnuplot.getsession(:fig1)
Gnuplot.reset(gp)
Gnuplot.append!(gp, Gnuplot.parseSpecs(rand(10), "w l", default_mid = Gnuplot.last_added_mid(gp), is3d = false))
Gnuplot.options.gpviewer && gpexec.(Ref(gp), Gnuplot.collect_commands(gp))
gp
end
and replace :fig1
with a variable containing a session name such as s
from your example, or session_names()[1]
I don't know metaprogramming, but I don't see why you couldn't allow a Symbol as well as a QuoteNode in the logic here:
That would recover the rather useful behavior from v1.5. Otherwise unpacking the macro is awkward.
Here's me checking the symbol or quotenode
julia> macro t(args...)
println(args[1]," ",isa(args[1],Symbol)," ",isa(args[1],QuoteNode))
end
@t (macro with 1 method)
julia> @t :fig1
:fig1 false true
julia> s= :fig1; @t s
s true false
Since the command Gnuplot.getsession(s)
works on symbols as well as quotenodes, this should be a 1-line change (the line above).
Thanks, Alex
Because isa(args[1],Symbol)
is a check on the name of the variable, not its content.
If you set s
to an int or a string you would obtain exactly the same results:
s= :fig1; @t s
s true false
julia> s= 1; @t s
s true false
julia> s= "ddd"; @t s
s true false
An alternative approach is to change the name of the default session being addressed when no one is specified, e.g.:
s = :fig1; Gnuplot.options.default = s; @gp rand(10) "w l"
Ok, great - this last option is very easy and natural. Thanks for a great package. It would be great if you could add it to your Advanced examples webpage under Sessions.
On Fri, Jan 12, 2024 at 4:05 AM gcalderone @.***> wrote:
An alternative approach is to change the name of the default session being addressed when no one is specified, e.g.:
s = :fig1; Gnuplot.options.default = s; @gp rand(10) "w l"
— Reply to this email directly, view it on GitHub https://github.com/gcalderone/Gnuplot.jl/issues/63#issuecomment-1888698739, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACNZRSSUFGJ677OAFSVHJ3DYOD4EZAVCNFSM6AAAAABBW5SJB6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBYGY4TQNZTHE . You are receiving this because you authored the thread.Message ID: @.***>
-- *-------------------------------------------------------------------~^`^~._.~' |\ Alex Barnett Center for Computational Mathematics, Flatiron Institute | \ http://users.flatironinstitute.org/~ahb 646-876-5942
I'm working on new examples, and I will also add this. Thank you for pointing it out!
Not exactly sure when this broke, but I used to rely on it in v1.5 something:
The error is:
Thanks for a useful package! Best, Alex