To be able to edit code and run cells, you need to run the notebook yourself. Where would you like to run the notebook?

This notebook takes about 20 seconds to run.

In the cloud (experimental)

Binder is a free, open source service that runs scientific notebooks in the cloud! It will take a while, usually 2-7 minutes to get a session.

On your computer

(Recommended if you want to store your changes.)

  1. Copy the notebook URL:
  2. Run Pluto

    (Also see: How to install Julia and Pluto)

  3. Paste URL in the Open box

Frontmatter

If you are publishing this notebook on the web, you can set the parameters below to provide HTML metadata. This is useful for search engines and social media.

Author 1
jlon (generic function with 1 method)
👀 Reading hidden code
jlon(x) = string(x)
359 μs
parse (generic function with 1 method)
👀 Reading hidden code
function parse(s::String)
e = Meta.parse(s)
eval(e)
end
500 μs
👀 Reading hidden code
70.0 μs
check_isclean (generic function with 1 method)
👀 Reading hidden code
check_isclean(x::ValueType) = true
350 μs
testy (generic function with 1 method)
👀 Reading hidden code
testy(x) = parse(jlon(x)) == x
408 μs
true
👀 Reading hidden code
testy([1,2,[3,4]])
120 ms
true
👀 Reading hidden code
testy([1,2,(5,6)])
54.6 ms
true
👀 Reading hidden code
testy(Dict(1=>2, 4=>5))
30.0 ms
true
👀 Reading hidden code
testy((1,2,"three"))
6.8 ms
true
👀 Reading hidden code
testy((a=1,b=2,c="three"))
9.8 ms
true
testy((a=1.2,b=2,c="three"))
👀 Reading hidden code
10.3 ms
clean_type (generic function with 1 method)
clean_type(x) = false
👀 Reading hidden code
356 μs
Union{Bool, Char, Float32, Float64, Int32, Int64, String}
const ValueType = Union{String,Int64,Int32,Char,Float64,Float32,Bool}
👀 Reading hidden code
159 μs
const CleanTypes = (:Any, :String, :Int64, :Int32, :Int16, :Int8, :UInt64, :UInt32, :UInt16, :UInt8, :Float64, :Float32, :Float128, :BigInt)
👀 Reading hidden code
174 μs
clean_type (generic function with 2 methods)
clean_type(x::Symbol) = x ∈ CleanTypes
👀 Reading hidden code
426 μs
check_isclean (generic function with 2 methods)
function check_isclean(e::Expr)
h = e.head

if h === :vect
foreach(check_isclean, e.args)
elseif h === :ref && clean_type(e.args[1])
foreach(check_isclean, @view e.args[2:end])
elseif h === :call && e.args[1] === :Dict
for a in e.args[2:end]
@assert Meta.isexpr(a, :call, 3)
@assert a.args[1] === :(=>)
check_isclean(a.args[2])
check_isclean(a.args[3])
end
elseif h === :tuple
if all(a -> Meta.isexpr(a, :(=), 2), e.args)
for a in e.args
@assert a.args[1] isa Symbol
check_isclean(a.args[2])
end
else
foreach(check_isclean, e.args)
end
else
throw(ArgumentError("Invalid expression: $(sprint(dump, e))"))
end
end
👀 Reading hidden code
28.3 ms
using PlutoTest
👀 Reading hidden code
12.4 ms

👀 Reading hidden code
67.2 μs

👀 Reading hidden code
66.5 μs