Skip to content

Instantly share code, notes, and snippets.

@mbauman
Last active July 6, 2020 11:14
Show Gist options
  • Save mbauman/d0c27f40e25393ef050b87b4bb6a69dc to your computer and use it in GitHub Desktop.
Save mbauman/d0c27f40e25393ef050b87b4bb6a69dc to your computer and use it in GitHub Desktop.
using Cassette, ReplMaker
Cassette.@context NoNaN
nonnan(s, x::Number) = (@assert(!isnan(x), string(s, " returned NaN")); x)
nonnan(s, A::AbstractArray) = (foreach(x->nonnan(s, x), A); A)
nonnan(s, x) = x
Cassette.overdub(::NoNaN, f, args...) = nonnan("$f$args", f(args...))
function parse_to_expr(s)
p = Meta.parse(s)
isa(p, Expr) && p.head in (:using, :import) && return p
quote $Cassette.@overdub($(NoNaN()), $p) end
end
initrepl(parse_to_expr,
prompt_text="NoNaN> ",
prompt_color = :blue,
start_key=')',
mode_name="no_nan_mode")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment