Stream: helpdesk (published)

Topic: ✔ Pushing to a `quote`-block


view this post on Zulip Mosè Giordano (Apr 24 2023 at 16:44):

is there an easy way to push to a quote-block without adding nested begin-blocks? for example, currently I have

julia> code = quote end
quote
    #= REPL[27]:1 =#
end

julia> push!(code.args, quote a + b; c + d end);

julia> code
quote
    #= REPL[27]:1 =#
    begin
        #= REPL[28]:1 =#
        a + b
        #= REPL[28]:1 =#
        c + d
    end
end

but I'd like to have

julia> quote
           a + b
           c + d
       end
quote
    #= REPL[30]:2 =#
    a + b
    #= REPL[30]:3 =#
    c + d
end

view this post on Zulip Sukera (Apr 24 2023 at 17:04):

the begin comes from the quote you're pushing being a begin

view this post on Zulip Sukera (Apr 24 2023 at 17:05):

I think you want append!(code.args, (quote a + b; c + d end).args)

view this post on Zulip Mosè Giordano (Apr 24 2023 at 17:07):

aaaah, append!! I did try that, but with push!, and got garbage, because push! iterates over the elements to push. thanks!

view this post on Zulip Notification Bot (Apr 24 2023 at 17:08):

Mosè Giordano has marked this topic as resolved.


Last updated: Nov 06 2024 at 04:40 UTC