Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for backward compatibility, reintroduce julia_to_gap #1056

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/julia_to_gap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,11 @@ function GapObj_internal(
end

GAP.@install GapObj(func::Function) = WrapJuliaFunc(func)

# For backwards compatibility,
# provide the generic methods for `julia_to_gap`.
# (Installing other methods for `julia_to_gap` will not work in recursive
# situations, only `GapObj_internal` methods can be used for that.)
julia_to_gap(obj::Any) = GapObj_internal(obj, nothing, Val(false))
julia_to_gap(obj::Any; recursive::Bool) = julia_to_gap(obj)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Julia doesn't use kwargs for dispatch. The dispatcher can therefore not distinguish these two.
Solution: unify into one method with a default kwarg value

Suggested change
julia_to_gap(obj::Any) = GapObj_internal(obj, nothing, Val(false))
julia_to_gap(obj::Any; recursive::Bool) = julia_to_gap(obj)
julia_to_gap(obj::Any; recursive::Bool=false) = GapObj_internal(obj, nothing, Val(false))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we not honor recursive ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.
We do not just want to have the generic methods but also the "old" behaviour for vectors, matrices, etc.
I will update the pull request.

julia_to_gap(obj::Any, recursion_dict::IdDict{Any,Any}; recursive::Bool = true) = julia_to_gap(obj)
19 changes: 17 additions & 2 deletions test/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,10 @@
yy = GAP.gap_to_julia(Vector{Tuple{Int64}}, xx)
@test [(1,)] == yy
@test typeof(yy) == Vector{Tuple{Int64}}

end
end

@testset "conversion to GAP" begin
end

@testset "Defaults" begin
@test GapObj(true)
Expand Down Expand Up @@ -555,6 +554,22 @@ end
@test GAP.Globals.List(list, return_first_gap) == list
end

@testset "Test julia_to_gap (backwards compatibility)" begin
@test GAP.julia_to_gap(27) == 27
@test GAP.julia_to_gap([1, 2, 3, 4]) == GAP.evalstr("[ 1, 2, 3, 4 ]")
l = GAP.julia_to_gap([[1, 2], [3, 4]])
@test l isa GapObj
@test l[1] == [1, 2]
l = GAP.julia_to_gap([[1, 2], [3, 4]], recursive = true)
@test l isa GapObj
@test l[1] isa GapObj
v = [1, 2]
l = GAP.julia_to_gap([v, v])
@test l[1] === l[2]
l = GAP.julia_to_gap([v, v], recursive = true)
@test l[1] === l[2]
@test GAP.julia_to_gap([v, v], IdDict(), recursive = true) isa GapObj
end
end

@testset "(Un)WrapJuliaFunc" begin
Expand Down
Loading