Suppose I create a Module
that is expected to return a graphic that I will later use in a plotting procedure (e.g., with Show[]
). One of my inputs is an optional input that I want to test (to prevent breaking etc.) inside the Module
. This optional input is supposed to be a color (e.g., Red
). I am running into several issues that I think should not be issues. Suppose the name of the optional input is lcolor
for the discussion below. Here is a very simple analogous example to what I refer.
test[lcolor_: Red] := Module[{}, Red == lcolor]
test[RGBColor[1, 0, 0]]
test[Red]
test[Blue]
- I can perform a boolean test
Red == RGBColor[1,0,0]
which results inTrue
. However, if I tryRed == RGBColor[0,0,1]
, Mathematica just returns the input rather thanFalse
. Can anyone explain why this is? I tried usingEvaluate
to force it to compare the two, but received the same result. - Is there an equivalent/parallel to something like
NumberQ
for colors in Mathematica? I want to test this input to make sure it is a color that will be accepted byDirective
orGraphics3D
.- To try and test the input, I first tried the following example (which worked on the command line):
(Context[lcolor] == Context[Red]) && (Attributes[lcolor] == Attributes[Red])
. However, if I definelcolor
asRed
it turns intoRGBColor[1,0,0]
inside theModule
, which causes bothContext
andAttributes
to return errors. However, simple checks like that discussed in (1) do not work, so I am left confused. I even tried to wrap the inputs forContext
andAttributes
inToExpression[ToBoxes[], StandardForm]
andMakeExpression[ToBoxes[], StandardForm]
, but neither method worked. - Then I tried just forcing
lcolor
to be an integer and compared it to a list of possible integers, but this is very restrictive. I do not want to explicitly write out (nor can I) every possible color that Mathematica can handle.
- To try and test the input, I first tried the following example (which worked on the command line):
Does anyone have any suggestions?
ColorQ
in v8? $\endgroup$