Suppose I'm using the expression Person[fn_String, ln_String]
as a data expression, and want to prohibit the creation of expressions where PersonQ[person]
is False
.
Q: Is there an "elegant" way to implement this?
Attempts:
- I can create an additional function, say,
CreatePerson[fn_String, ln_String]
that only returns thePerson
expression ifPersonQ
isTrue
. This does not prevent the creation of arbitraryPerson
expressions. Also, this feels like I'm missing something obvious. - I've tried defining
Person
to be a function and returnPerson[fn,ln]
as a deferred evaluation expression, but the head of this expression is notPerson
. That is, theFullForm
is notPerson[fn,ln]
. Not ideal... - I've created a
Person[fn,ln]
function that creates a Strings="Person[fn,ln]"
and then returnsToExpression[s]
, but this feels extremely hacky.
Am I missing something obvious?
Thanks!