Skip to content

Commit

Permalink
support gap_to_julia(::AbstractVector) (#989)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ThomasBreuer authored May 15, 2024
1 parent 3e99a25 commit c53585e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/julia_to_gap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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},
Expand Down
10 changes: 10 additions & 0 deletions test/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c53585e

Please sign in to comment.