From c53585e9e8f26e8ac784ebf68daa7711da9dc2db Mon Sep 17 00:00:00 2001 From: Thomas Breuer Date: Wed, 15 May 2024 13:52:39 +0200 Subject: [PATCH] support `gap_to_julia(::AbstractVector)` (#989) * support `gap_to_julia(::BitVector)` This had been claimed already before the change, but it was not tested. * adjust the conversion of ranges After generalizing the three-argument method of `julia_to_gap` from `Vector` to `AbstractVector`, the default method that discards the last two arguments is no longer applicable to `AbstractRange{<:Integer}`, hence the special one-argument method does not get called. For the moment, install a three-argument method for `AbstractRange{<:Integer}`. (And add tests that check whether we really get a GAP `IsRange` object in the end.) * polish - do not show `C_NULL` but just its type (since printing has changed in Julia) - fix a typo --- src/julia_to_gap.jl | 12 ++++++++++-- test/conversion.jl | 10 ++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/julia_to_gap.jl b/src/julia_to_gap.jl index 59214046a..d9d3e0b12 100644 --- a/src/julia_to_gap.jl +++ b/src/julia_to_gap.jl @@ -116,7 +116,7 @@ julia_to_gap(obj::Any, recursion_dict::IdDict{Any,Any}; recursive::Bool = true) ## Arrays (including BitVector) function julia_to_gap( - obj::Vector{T}, + obj::AbstractVector{T}, recursion_dict::IdDict{Any,Any} = IdDict(); recursive::Bool = false, ) where {T} @@ -172,12 +172,20 @@ function julia_to_gap( end ## Ranges -function julia_to_gap(r::AbstractRange{<:Integer}) +function julia_to_gap(r::AbstractRange{<:Integer}, recursive::Bool = false) res = NewRange(length(r), first(r), step(r)) Wrappers.IsRange(res) || throw(ConversionError(r, GapObj)) return res end +function julia_to_gap( + r::AbstractRange{<:Integer}, + recursion_dict::IdDict{Any,Any}; + recursive::Bool = false) + + return julia_to_gap(r) +end + ## Dictionaries function julia_to_gap( obj::Dict{T,S}, diff --git a/test/conversion.jl b/test/conversion.jl index e48b63a05..a1706ba46 100644 --- a/test/conversion.jl +++ b/test/conversion.jl @@ -387,6 +387,11 @@ end y = GAP.julia_to_gap([true, false]) @test y == x @test GAP.gap_to_julia(GAP.Globals.TNAM_OBJ(y)) == "list (boolean)" + + v = BitVector([true, false]) + gap_v = GAP.julia_to_gap(v) + @test gap_v == x + @test GAP.gap_to_julia(GAP.Globals.TNAM_OBJ(gap_v)) == "list (boolean)" end @testset "Tuples" begin @@ -409,6 +414,11 @@ end r = GAP.evalstr("[ 1, 4 .. 10 ]") @test GAP.julia_to_gap(1:3:10) == r @test_throws GAP.ConversionError GAP.julia_to_gap(1:2^62) + + r = GAP.julia_to_gap(1:2:11, IdDict(), recursive = false) + @test GAP.gap_to_julia(GAP.Globals.TNAM_OBJ(r)) == "list (range,ssort)" + r = GAP.Obj(1:10) + @test GAP.gap_to_julia(GAP.Globals.TNAM_OBJ(r)) == "list (range,ssort)" end @testset "Dictionaries" begin