Skip to content

Not escaping in macro definition gives confusing error #1112

@ericphanson

Description

@ericphanson

If I define a show-like macro,

macro test_show(obj)
    prnt = :(println("Consider ", $(sprint(Base.show_unquoted, obj))))
	return quote
		with_terminal() do
			$prnt
			println($obj)
		end
	end
end

then it runs into reactivity issues if I use it like

f(x) = 2x

@test_show f(1)

then redefine f. I'm not sure how to describe it clearly, so I've attached a video:

Screen.Recording.2021-04-21.at.18.58.18.mov

You can see that everything gets fixed by re-evaluating the macro definition. By the way, if I actually borrow the full implementation of show,

macro test_show2(exs...)
	blk = Expr(:block)
    for ex in exs
        push!(blk.args, :(println($(sprint(Base.show_unquoted,ex)*" = "),
                                  repr(begin local value = $(esc(ex)) end))))
    end
    isempty(exs) || push!(blk.args, :value)
	
	return quote
		with_terminal() do
			$blk
		end
	end
end

then it works fine even if I use it with functions that I redefine. I'm not really sure what's different in the two-cases.

I'm using Pluto v0.14.2.

Metadata

Metadata

Assignees

Labels

expression explorerFiguring out assignments and references in a cell

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions