I have a function with more than two possible return values.
A simplified example is the following function that classifies vertices of a graph according to their degrees:
VertexRole[g_, v_] := Which[
VertexDegree[g, v] == 1, BadVertex,
VertexDegree[g, v] == 2, MediocreVertex,
VertexDegree[g, v] == 3, GoodVertex
]
However, defining the function in this way would be bad practice since the symbols BadVertex
etc. are undefined. Furthermore, I want to evaluate expressions such as
VertexRole[graph, vertex] == BadVertex
Defining BadVertex
to be a number (e.g. 42) would also be bad since I actually want
BadVertex == x
to evaluate to False
for all x
other than BadVertex
.
Therefore BadVertex
etc. should be symbols similar to True
, False
, Automatic
, All
, None
. How can I implement that?
[One could use a string as the return value (e.g. "BadVertex"
), but that kind of misses the syntactical point I am trying to make. I am rather looking for something that resembles the enum type in C.]
Protected
. $\endgroup$VertexDegree[g, v]
you might want to consider using Switch $\endgroup$