Suppose I'm using the expression
Person[fn_String, ln_String] as a data expression, and want to prohibit the creation of expressions where
Q: Is there an "elegant" way to implement this?
- I can create an additional function, say,
CreatePerson[fn_String, ln_String]that only returns the
True. This does not prevent the creation of arbitrary
Personexpressions. Also, this feels like I'm missing something obvious.
- I've tried defining
Personto be a function and return
Person[fn,ln]as a deferred evaluation expression, but the head of this expression is not
Person. That is, the
Person[fn,ln]. Not ideal...
- I've created a
Person[fn,ln]function that creates a String
s="Person[fn,ln]"and then returns
ToExpression[s], but this feels extremely hacky.
Am I missing something obvious?