Gnus development mailing list
 help / color / mirror / Atom feed
From: Daniel Pittman <daniel@rimspace.net>
Subject: Re: where does this belong?
Date: Thu, 28 Mar 2002 13:09:24 +1100	[thread overview]
Message-ID: <87zo0to33f.fsf@inanna.rimspace.net> (raw)
In-Reply-To: <m3u1r22dwl.fsf@multivac.cwru.edu> (prj@po.cwru.edu's message of "Wed, 27 Mar 2002 11:06:28 -0500")

On Wed, 27 Mar 2002, Paul Jarc wrote:
> Daniel Pittman <daniel@rimspace.net> wrote:
>> I agree with Kai -- the right place for this is the `cl' package,
>> because I can't see the difference between this and the `defstruct'
>> routine...
> 
> Well, the most significant difference is that I didn't know about cl's
> defstruct. :)  

*grin* 

> Now that I do, I see that mine is much smaller:

Probably. The Common Lisp specification is a fairly comprehensive
implementation of pretty much everything that you would want from a
structure including testing of types and the like.

[...]

> But I don't think I understand what the cl defstruct does, exactly.
> Can someone point me to an example use?

Kai already supplied a good summary of how it works. The CL HyperSpec
entry for it is a comprehensive summary of it's function and is
available online at:

<http://www.xanalys.com/software_tools/reference/HyperSpec/Body/m_defstr.htm#defstruct>

My recollection from use is that the Emacs CL `defstruct' supports all
of the features of the CL one except for the printer options.

That is, read-only slots, initial offset, renaming of the accessors,
constructors and predicates, default values and value type requirements
are all supported.

So, the generally useful features that it has above your version would
probably be the ability to have read-only fields, the ability to say:

(defstruct foo (string-field "" :type string))

The `setf' form generated for that will then refuse to set the
`string-field' slot of a `foo' with any value that is not `stringp'

This extends, incidentally, to anything that has a `type-p' or `typep'
method, allowing you to (a) use any `defstruct' type for a :type and
(b) write your own predicates for non-CL types, such as:

(defun some-random-type-p (argument)
  "Test if the argument is of the correct type."
  (and (stringp argument)
       (equal argument "foo")))

At this point you can define a slot with ":type some-random-type" and it
will use the `some-random-type-p' routine to verify that it's the
correct type...

        Daniel

-- 
Across clinical benches with nothing to talk
Breathing tea and biscuits and the Serenity Prayer
While the bones of our child crumble like chalk
Oh, where do we go now but nowhere
        -- Nick Cave, _Where Do We Go Now But Nowhere?_



      parent reply	other threads:[~2002-03-28  2:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-27  0:18 Paul Jarc
2002-03-27  8:57 ` Kai Großjohann
2002-03-27 10:17 ` Simon Josefsson
2002-03-27 10:27   ` Daniel Pittman
2002-03-27 16:06     ` Paul Jarc
2002-03-27 17:16       ` Kai Großjohann
2002-03-27 19:13         ` Paul Jarc
2002-03-28  2:09       ` Daniel Pittman [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zo0to33f.fsf@inanna.rimspace.net \
    --to=daniel@rimspace.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).