Last active
July 6, 2020 11:14
-
-
Save mbauman/d0c27f40e25393ef050b87b4bb6a69dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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