From 5b6e191e5b1219191a21cbf63ed5dfaea6cf5876 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Tue, 21 Nov 2023 10:53:04 +0530 Subject: [PATCH] feat: add `hasname` function --- docs/src/api.md | 1 + src/SymbolicIndexingInterface.jl | 2 +- src/trait.jl | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) 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