diff --git a/docs/src/api.md b/docs/src/api.md index ff7855e..a222a68 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -22,6 +22,7 @@ ScalarSymbolic ArraySymbolic NotSymbolic symbolic_type +hasname getname ``` diff --git a/src/SymbolicIndexingInterface.jl b/src/SymbolicIndexingInterface.jl index 57d0ba6..cff0e06 100644 --- a/src/SymbolicIndexingInterface.jl +++ b/src/SymbolicIndexingInterface.jl @@ -2,7 +2,7 @@ module SymbolicIndexingInterface using Requires -export ScalarSymbolic, ArraySymbolic, NotSymbolic, symbolic_type , getname +export ScalarSymbolic, ArraySymbolic, NotSymbolic, symbolic_type, hasname, getname include("trait.jl") export is_variable, variable_index, variable_symbols, is_parameter, parameter_index, diff --git a/src/trait.jl b/src/trait.jl index ea4df5b..bb53ac3 100644 --- a/src/trait.jl +++ b/src/trait.jl @@ -40,6 +40,15 @@ symbolic_type(x) = symbolic_type(typeof(x)) symbolic_type(::Type) = NotSymbolic() symbolic_type(::Type{Symbol}) = ScalarSymbolic() +""" + hasname(x) + +Check whether the given symbolic variable (for which `symbolic_type(x) != NotSymbolic()`) has a valid name as per `getname`. +""" +function hasname end + +hasname(::Symbol) = true +hasname(::Any) = false """ getname(x)::Symbol