Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Newbie question: testing if an object is a Struct of a certain kind
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
samppi  
View profile  
 More options Oct 29 2008, 2:29 pm
From: samppi <rbysam...@gmail.com>
Date: Wed, 29 Oct 2008 11:29:09 -0700 (PDT)
Local: Wed, Oct 29 2008 2:29 pm
Subject: Newbie question: testing if an object is a Struct of a certain kind
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

Thanks in advance.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Graham Fawcett  
View profile  
 More options Oct 29 2008, 3:01 pm
From: "Graham Fawcett" <graham.fawc...@gmail.com>
Date: Wed, 29 Oct 2008 15:01:59 -0400
Local: Wed, Oct 29 2008 3:01 pm
Subject: Re: Newbie question: testing if an object is a Struct of a certain kind

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
samppi  
View profile  
 More options Oct 29 2008, 3:27 pm
From: samppi <rbysam...@gmail.com>
Date: Wed, 29 Oct 2008 12:27:42 -0700 (PDT)
Local: Wed, Oct 29 2008 3:27 pm
Subject: Re: Newbie question: testing if an object is a Struct of a certain kind
Okay, I understand. Thanks for the answer.

On Oct 29, 12:01 pm, "Graham Fawcett" <graham.fawc...@gmail.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »