From 99cd5e3b27843f8a4b316f793b4346ffd7760d00 Mon Sep 17 00:00:00 2001 From: ThomasBreuer Date: Thu, 15 Jun 2023 14:34:35 +0200 Subject: [PATCH] reduce the occurrences of `evalstr` in docstrings addresses #897 --- src/adapter.jl | 8 ++++---- src/constructors.jl | 43 +++++++++++++++++++++---------------------- src/gap_to_julia.jl | 8 ++++---- src/macros.jl | 2 +- src/types.jl | 12 ++++-------- 5 files changed, 34 insertions(+), 39 deletions(-) diff --git a/src/adapter.jl b/src/adapter.jl index ad66133e..d8cd7a8f 100644 --- a/src/adapter.jl +++ b/src/adapter.jl @@ -196,7 +196,7 @@ Return the record component of the GAP record `x` that is described by `f`. # Examples ```jldoctest -julia> r = GAP.evalstr( "rec( a:= 1 )" ) +julia> r = GapObj(Dict(:a => 1)) GAP: rec( a := 1 ) julia> r.a @@ -217,7 +217,7 @@ to the value `v`. # Examples ```jldoctest -julia> r = GAP.evalstr( "rec( a:= 1 )" ) +julia> r = GapObj(Dict(:a => 1)) GAP: rec( a := 1 ) julia> r.b = 0 @@ -241,7 +241,7 @@ and `false` otherwise. # Examples ```jldoctest -julia> r = GAP.evalstr( "rec( a:= 1 )" ) +julia> r = GapObj(Dict(:a => 1)) GAP: rec( a := 1 ) julia> hasproperty( r, :a ) @@ -528,7 +528,7 @@ julia> res1 = GAP.Globals.Random(gap_rng1, 1, 10); julia> rng1 == rng2 # the two rngs have diverged false -julia> res1 == GAP.Globals.Random(gap_rng2, GAP.GapObj(1:10)) +julia> res1 == GAP.Globals.Random(gap_rng2, GapObj(1:10)) true julia> rng1 == rng2 # now the two rngs are again in sync diff --git a/src/constructors.jl b/src/constructors.jl index be772b5c..f16130aa 100644 --- a/src/constructors.jl +++ b/src/constructors.jl @@ -143,7 +143,7 @@ Return the character converted from the # Examples ```jldoctest -julia> val = GAP.evalstr("'x'") +julia> val = GapObj('x') GAP: 'x' julia> Char(val) @@ -164,7 +164,7 @@ Return the `UInt8` that belongs to the # Examples ```jldoctest -julia> val = GAP.evalstr("'x'") +julia> val = GapObj('x') GAP: 'x' julia> Cuchar(val) @@ -188,13 +188,13 @@ this behaviour is not intended for this `String` constructor. # Examples ```jldoctest -julia> val = GAP.evalstr("\\"abc\\"") +julia> val = GapObj("abc") GAP: "abc" julia> String(val) "abc" -julia> val = GAP.evalstr("[]") +julia> val = GapObj([]) GAP: [ ] julia> String(val) # an empty GAP list is a string @@ -217,7 +217,7 @@ Return the symbol converted from the # Examples ```jldoctest -julia> str = GAP.evalstr("\\"abc\\"") +julia> str = GapObj("abc") GAP: "abc" julia> Symbol(str) @@ -235,7 +235,7 @@ Return the bit vector converted from the # Examples ```jldoctest -julia> val = GAP.evalstr("[ true, false, true ]") +julia> val = GapObj([true, false, true]) GAP: [ true, false, true ] julia> BitVector(val) @@ -273,7 +273,7 @@ If `T` is `UInt8` then `obj` may be a # Examples ```jldoctest -julia> val = GAP.evalstr("[ [ 1 ], [ 2 ] ]") +julia> val = GapObj([[1], [2]], recursive = true) GAP: [ [ 1 ], [ 2 ] ] julia> Vector{Any}(val) @@ -295,7 +295,7 @@ julia> Vector{Int64}( val ) 2 5 -julia> val = GAP.evalstr("\\"abc\\"") +julia> val = GapObj("abc") GAP: "abc" julia> Vector{UInt8}(val) @@ -322,7 +322,7 @@ converted recursively, otherwise non-recursively. # Examples ```jldoctest -julia> val = GAP.evalstr("[ [ 1, 2 ], [ 3, 4 ] ]") +julia> val = GapObj([[1, 2], [3, 4]], recursive = true) GAP: [ [ 1, 2 ], [ 3, 4 ] ] julia> Matrix{Int64}(val) @@ -360,26 +360,25 @@ Dealing with results containing GAP objects will be inefficient. # Examples ```julia -julia> Set{Int}(GAP.evalstr("[ 1, 2, 1 ]")) +julia> Set{Int}(GapObj([1, 2, 1])) Set{Int64} with 2 elements: 2 1 -julia> Set{Vector{Int}}(GAP.evalstr("[[1], [2], [1]]")) +julia> Set{Vector{Int}}(GapObj([[1], [2], [1]], recursive = true)) Set{Vector{Int64}} with 2 elements: [1] [2] -julia> Set{String}(GAP.evalstr("[\\"a\\", \\"b\\"]")) +julia> Set{String}(GapObj(["a", "b"], recursive = true)) Set{String} with 2 elements: "b" "a" -julia> Set{Any}(GAP.evalstr("[[1], [2], [1]]")) +julia> Set{Any}(GapObj([[1], [2], [1]], recursive = true)) Set{Any} with 2 elements: Any[1] Any[2] - ``` In the following examples, @@ -387,9 +386,9 @@ the order in which the Julia output is shown may vary. # Examples ```jldoctest -julia> s = Set{Any}(GAP.evalstr("[[1], [2], [1]]"), recursive = false); +julia> s = Set{Any}(GapObj([[1], [2], [1]], recursive = true), recursive = false); -julia> s == Set{Any}([GAP.evalstr("[ 1 ]"), GAP.evalstr("[ 2 ]")]) +julia> s == Set{Any}([GapObj([1]), GapObj([2])]) true julia> s = Set{Any}(GAP.evalstr("SymmetricGroup(2)"), recursive = false); @@ -414,13 +413,13 @@ converted recursively, otherwise non-recursively. # Examples ```jldoctest -julia> val = GAP.evalstr("[ 1, 5 ]") +julia> val = GapObj([1, 5]) GAP: [ 1, 5 ] julia> Tuple{Int64,Int64}(val) (1, 5) -julia> val = GAP.evalstr("[ [ 1 ], [ 2 ] ]") +julia> val = GapObj([[1], [2]], recursive = true) GAP: [ [ 1 ], [ 2 ] ] julia> Tuple{Any,Any}(val) @@ -443,7 +442,7 @@ Return the unit range converted from the # Examples ```jldoctest -julia> val = GAP.evalstr("[ 1 .. 10 ]") +julia> val = GapObj(1:10) GAP: [ 1 .. 10 ] julia> UnitRange(val) @@ -481,7 +480,7 @@ Return the step range converted from the # Examples ```jldoctest -julia> val = GAP.evalstr("[ 1, 3 .. 11 ]") +julia> val = GapObj(1:2:11) GAP: [ 1, 3 .. 11 ] julia> StepRange(val) @@ -531,7 +530,7 @@ using [`gap_to_julia`](@ref), otherwise they are kept as they are. # Examples ```jldoctest -julia> val = GAP.evalstr("rec( a:= 1, b:= 2 )") +julia> val = GapObj(Dict(:a => 1, :b => 2)) GAP: rec( a := 1, b := 2 ) julia> Dict{Symbol,Int}(val) @@ -539,7 +538,7 @@ Dict{Symbol, Int64} with 2 entries: :a => 1 :b => 2 -julia> val = GAP.evalstr("rec( l:= [ 1, 2 ] )") +julia> val = GapObj(Dict(:l => GapObj([1, 2]))) GAP: rec( l := [ 1, 2 ] ) julia> Dict{Symbol,Any}(val, recursive = false) diff --git a/src/gap_to_julia.jl b/src/gap_to_julia.jl index ddd3a905..d3eab21f 100644 --- a/src/gap_to_julia.jl +++ b/src/gap_to_julia.jl @@ -20,7 +20,7 @@ const RecDict = IdDict{Any,Any} gap_to_julia(type, x, recursion_dict::Union{Nothing,RecDict}=nothing; recursive::Bool=true) Try to convert the object `x` to a Julia object of type `type`. -If `x` is a `GAP.GapObj` then the conversion rules are defined in the +If `x` is a `GapObj` then the conversion rules are defined in the manual of the GAP package JuliaInterface. If `x` is another `GAP.Obj` (for example a `Int64`) then the result is defined in Julia by `type`. @@ -34,10 +34,10 @@ the behaviour is controlled by `recursive`, which can be `true` or `false`. # Examples ```jldoctest -julia> GAP.gap_to_julia( GAP.evalstr( "1/3" ) ) +julia> GAP.gap_to_julia(GapObj(1//3)) 1//3 -julia> GAP.gap_to_julia( GAP.evalstr( "\\"abc\\"" ) ) +julia> GAP.gap_to_julia(GapObj("abc")) "abc" julia> val = GapObj([ 1 2 ; 3 4 ]) @@ -122,7 +122,7 @@ gap_to_julia(::Type{Any}, x::Any) = x gap_to_julia(::T, x::Nothing) where {T<:Type} = nothing gap_to_julia(::Type{Any}, x::Nothing) = nothing -## Handle "conversion" to GAP.Obj and GAP.GapObj (may occur in recursions). +## Handle "conversion" to GAP.Obj and GapObj (may occur in recursions). gap_to_julia(::Type{Obj}, x::Obj) = x gap_to_julia(::Type{GapObj}, x::GapObj) = x diff --git a/src/macros.jl b/src/macros.jl index b24bd0b1..98d28c9b 100644 --- a/src/macros.jl +++ b/src/macros.jl @@ -216,7 +216,7 @@ in whose scope the macro is called. # Examples ```jldoctest -julia> @gapattribute isstrictlysortedlist(obj::GAP.GapObj) = GAP.Globals.IsSSortedList(obj)::Bool; +julia> @gapattribute isstrictlysortedlist(obj::GapObj) = GAP.Globals.IsSSortedList(obj)::Bool; julia> l = GapObj([ 1, 3, 7 ]); diff --git a/src/types.jl b/src/types.jl index 169fef50..a9aa7ba2 100644 --- a/src/types.jl +++ b/src/types.jl @@ -34,7 +34,6 @@ GAP: Z(3) julia> typeof(x) FFE - ``` """ primitive type FFE 64 end @@ -48,10 +47,10 @@ This is the Julia type of all those GAP objects that are not # Examples ```jldoctest -julia> typeof( GAP.evalstr( "[ 1, 2 ]" ) ) # a GAP list +julia> typeof(GapObj([1, 2])) # a GAP list GapObj -julia> typeof( GAP.evalstr( "rec()" ) ) # a GAP record +julia> typeof(GapObj(Dict(:a => 1))) # a GAP record GapObj julia> typeof( GAP.evalstr( "(1,2,3)" ) ) # a GAP permutation @@ -68,7 +67,6 @@ FFE julia> typeof( GAP.evalstr( "true" ) ) # a boolean Bool - ``` Note that this is Julia's viewpoint on GAP objects. @@ -83,7 +81,6 @@ Base julia> typeof( GAP.evalstr( "Julia.Base" ) ) # native Julia object Module - ``` One can use `GapObj` as a constructor, @@ -105,15 +102,14 @@ GAP: 1/3 julia> GapObj([1 2; 3 4]) GAP: [ [ 1, 2 ], [ 3, 4 ] ] -julia> GAP.GapObj([[1, 2], [3, 4]]) +julia> GapObj([[1, 2], [3, 4]]) GAP: [ , ] -julia> GAP.GapObj([[1, 2], [3, 4]], recursive = true) +julia> GapObj([[1, 2], [3, 4]], recursive = true) GAP: [ [ 1, 2 ], [ 3, 4 ] ] julia> GapObj(42) ERROR: TypeError: in typeassert, expected GapObj, got a value of type Int64 - ``` """ GapObj