On Wed, Oct 29, 2008 at 2:29 PM, samppi <rbysam
...@gmail.com> wrote:
> Is there a way to test an object if it's a certain kind of struct?
> (defstruct person :name :age)
> (def president (struct person "Sam" 30))
> (struct? person president) ; true
Hi,
Defstruct doesn't define a new type in the OO sense. You can test for
presence of keys, e.g.
(every? #{:name :age} (keys president))
will return true, because 'president' has both :name and :age keys.
But other structures might also have these keys, so this is "duck
typing" at best.
Others have suggested using metadata to "tag" struct values with type
information -- that might be an option you prefer over
key-comparision.
Best,
Graham