diff --git a/src/FixFunctionArgument.jl b/src/FixFunctionArgument.jl index 2444939..c6283c1 100644 --- a/src/FixFunctionArgument.jl +++ b/src/FixFunctionArgument.jl @@ -85,7 +85,7 @@ module FixFunctionArgument end end function get_n(::Fix{N}) where {N} - check_positive(N) - 1 + check_positive(N) end # Properties for compatility with `Base.Fix` const property_name_f = :f @@ -104,7 +104,7 @@ module FixFunctionArgument end # Make `Fix` callable function (fix::Fix)(args::Vararg{Any, TupleLength}; kwargs...) where {TupleLength} - n = get_n(fix) + n = get_n(fix) - 1 if length(args) < n throw_too_few_args() end @@ -124,6 +124,18 @@ module FixFunctionArgument fixed_argument = fix.x callable(arg, fixed_argument; kwargs...) end + function Base.show(io::IO, fix::Fix) + n = get_n(fix) + callable = fix.f + fixed_argument = fix.x + show(io, Fix{n}) + print(io, '(') + show(io, callable) + print(io, ',') + print(io, ' ') + show(io, fixed_argument) + print(io, ')') + end """ Fix1 diff --git a/test/runtests.jl b/test/runtests.jl index 43feac3..48047a0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -35,6 +35,16 @@ using Test @test_throws Exception fixed.z end end + @testset "two-argument `show` roundtripping" begin + for N ∈ (1, 2, 3, 999) + for x ∈ (Fix{N}(convert, Float32), Fix{N}(Int, 7)) + @test x === (eval ∘ Meta.parse ∘ repr)(x) + end + let x = Fix{N}(Int, big(7)) + @test repr(x) == (repr ∘ eval ∘ Meta.parse ∘ repr)(x) + end + end + end end using Aqua: Aqua