Stream: helpdesk (published)

Topic: Macro changing interpretation of number literals


view this post on Zulip Adam non-jedi Beckmeyer (May 21 2021 at 13:37):

Is there a macro somewhere to treat all enclosed integer-literals as e.g. Int8 instead of Int? I know I've seen something like it before, but quick googling isn't turning anything up.

view this post on Zulip Rafael Fourquet (May 21 2021 at 14:16):

See SwapLiterals.jl (a "subdir package" of SafeREPL.jl).

view this post on Zulip Adam non-jedi Beckmeyer (May 21 2021 at 14:20):

Thanks!

view this post on Zulip Felix Kastner (May 21 2021 at 20:36):

Wow.
If you want something really simple it should be enough to do

nice(x) = x
nice(n::Number) = NiceNumber(n)
nice(ex::Expr) = Expr(ex.head, map(nice, ex.args)...)

macro nice(code)
    return esc(nice(code))
end

Last updated: Oct 02 2023 at 04:34 UTC