I have a function foobar[x_] that can produce 4 types of output
a
b
a or b
a and b
What's a good data structure, or better even, a good built-in function (head) that can represent this? I don't want to use And[] and Or[] as a, b aren't boolean. Is this a silly question?
The intended use of foobar[], or more precisely the expression it evaluates to, is to represent the type of some other expression.
My idea 1
is to use
foobar[x_] := Which[
<condition for "a" scenario>, {{a}},
<condition for "b" scenario>,, {{b}},
<condition for "a or b" scenario>, {{a}, {b}},
<condition for "a and b" scenario> {{a, b}},
]
a,b,either[a,b]andboth[a,b]. Oroneof[a],oneof[b],oneof[a,b],allof[a,b]. Or{1,{a}},{1,{b}},{1,{a,b}},{2,{a,b}}. The last one would also allow more complex specifications like{2,{a,b,c}}(exactly 2 ofa,bandc) or{2;;4, {a,b,c,d,e}}(2 to 4 out ofatoe). – celtschk Oct 10 '12 at 18:19AndandOrbecauseaandbaren't Boolean -- why not? If they are expressly not Boolean thena && bora || bwill not evaluate, and this format is probably easiest to read. Do you have another reason to avoid these? – Mr.Wizard♦ Oct 10 '12 at 18:43