Skip to content

Instantly share code, notes, and snippets.

@b-fg
Created August 14, 2022 20:49
Show Gist options
  • Save b-fg/e834a6c7e3cf895edba0fd496d7c4ae2 to your computer and use it in GitHub Desktop.
Save b-fg/e834a6c7e3cf895edba0fd496d7c4ae2 to your computer and use it in GitHub Desktop.
Julia @out macro
macro out(exs...)
blk = Expr(:block)
for ex in exs
push!(blk.args, :(print($(sprint(Base.show_unquoted, ex) * " = "))))
push!(blk.args, :(show(stdout, "text/plain", begin value=$(esc(ex)) end)))
push!(blk.args, :(println()))
end
isempty(exs) || push!(blk.args, :value)
return blk
end
@b-fg
Copy link
Author

b-fg commented Aug 14, 2022

Julia macro to output variables using @show but in a nicer output format.
Usage

@out a
@out(a, b, c)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment