ANN: ArgCheck.jl

package
announcement

#1

ArgCheck.jl is a very small package that allows to replace

function f(A, B, k, n)
    (k > 0) && (n > 0) || throw(ArgumentError("k and n must be positive".))
    k > n || throw(ArgumentError("k > n must hold."))
    size(A) == size(B) || throw(DimensionMismatch("size(A) == size(B) must hold."))
    # doit    
end

by

function f(A, B, k, n)
    @argcheck k > 0 && n > 0
    @argcheck k > n
    @argcheck size(A) == size(B) DimensionMismatch
    # doit
end

#2

Simple and useful! Good work.


#3

Nice. For reference, there’s been a discussion about including a similar feature in Julia itself, possibly with support for conditions on the returned value too:


#4

Interesting. I think it would be good to have some standard macro for argument checking in Base.


#5

Looks useful. Will you register it?


#6

Nice!

I’ve been looking for this “design by contract” concept from Eiffel language (its only(?) major contribution) before.

I had a feeling macros would work, so didn’t complain it wasn’t built-in to the language.

In theory (and your implmentation, shouldn’t preclude) this could be an optimization opportunity for the compiler. Maybe it already helps it…?

The full idea is also invariants within loops and after loops. Then “argcheck” isn’t the best name…


#7

It is registered maybe you need to run Pkg.update()?


#8

@jw3126 I think @assert is well suited to check for invariants before/after loops.


#9

Had to run Pkg.update(), now I installed it. Thanks!