[I was trying to prove to myself that left side of && is always run (unnecessarily, when right one hard-coded to return false).]
slow(n) = begin for i in 1:n end; return true end # Gets optimized away, Julia scores points.
[In theory, functions without side-effects, always returning same, should ALWAYS be dead-code eliminated; good for Julia if guaranteed.]
sleep(n) doesn’t work (for me), as it has side-effects.
julia> slow(n) = begin rand(n); return true end # This actually has side-effects.. could have used /dev/random .. julia> if slow(1000000000) && false println("Dummy hello") end ERROR: OutOfMemoryError() in rand at ./random.jl:300 [inlined] in rand at ./random.jl:297 [inlined] in rand at ./random.jl:229 [inlined] in rand at ./random.jl:230 [inlined] in slow(::Int64) at ./REPL:1 julia> if sleep(1) && false println("Preferably wouldn't happen..; nor should it run sleep that doesn't return bool before finding out.") end ERROR: TypeError: non-boolean (Void) used in boolean context julia> fib(10) # I thought in Base.. ERROR: UndefVarError: fib not defined julia> fibonacci(10) ERROR: UndefVarError: fibonacci not defined help?> ⊊ # just noticed, what is it, doc doesn't explain; diff from ⊈ that I know what is..