Skip to content

Instantly share code, notes, and snippets.

@mbauman

mbauman/find_first_nan.jl

Last active Jul 6, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.