Skip to content

Commit 1339885

Browse files
fix: add getname(::Symbol) method
1 parent f4b1bc3 commit 1339885

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/trait.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ symbolic_type(::Type{Expr}) = ScalarSymbolic()
4747
"""
4848
hasname(x)
4949
50-
Check whether the given symbolic variable (for which `symbolic_type(x) != NotSymbolic()`) has a valid name as per `getname`.
50+
Check whether the given symbolic variable (for which `symbolic_type(x) != NotSymbolic()`) has a valid name as per `getname`. Defaults to `true` for `x::Symbol`.
5151
"""
5252
function hasname end
5353

@@ -57,9 +57,11 @@ hasname(::Any) = false
5757
"""
5858
getname(x)::Symbol
5959
60-
Get the name of a symbolic variable as a `Symbol`
60+
Get the name of a symbolic variable as a `Symbol`. Acts as the identity function for
61+
`x::Symbol`.
6162
"""
6263
function getname end
64+
getname(x::Symbol) = x
6365

6466
"""
6567
symbolic_evaluate(expr, syms::Dict; kwargs...)

test/trait_test.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ using Test
44
@test all(symbolic_type.([Int, Float64, String, Bool, UInt, Complex{Float64}]) .==
55
(NotSymbolic(),))
66
@test symbolic_type(Symbol) == ScalarSymbolic()
7+
@test hasname(:x)
8+
@test getname(:x) == :x
9+
@test !hasname(1)
10+
@test !hasname(1.0)
11+
@test !hasname("x")

0 commit comments

Comments
 (0)