Skip to content

Commit

Permalink
reduce the occurrences of evalstr in docstrings
Browse files Browse the repository at this point in the history
addresses #897
  • Loading branch information
ThomasBreuer committed Jun 15, 2023
1 parent aac723c commit 99cd5e3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 39 deletions.
8 changes: 4 additions & 4 deletions src/adapter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 )
Expand Down Expand Up @@ -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
Expand Down
43 changes: 21 additions & 22 deletions src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -360,36 +360,35 @@ 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,
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);
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -531,15 +530,15 @@ 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)
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)
Expand Down
8 changes: 4 additions & 4 deletions src/gap_to_julia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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 ])
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]);
Expand Down
12 changes: 4 additions & 8 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ GAP: Z(3)
julia> typeof(x)
FFE
```
"""
primitive type FFE 64 end
Expand All @@ -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
Expand All @@ -68,7 +67,6 @@ FFE
julia> typeof( GAP.evalstr( "true" ) ) # a boolean
Bool
```
Note that this is Julia's viewpoint on GAP objects.
Expand All @@ -83,7 +81,6 @@ Base
julia> typeof( GAP.evalstr( "Julia.Base" ) ) # native Julia object
Module
```
One can use `GapObj` as a constructor,
Expand All @@ -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: [1, 2]>, <Julia: [3, 4]> ]
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

Expand Down

0 comments on commit 99cd5e3

Please sign in to comment.