Gnus development mailing list
 help / color / mirror / Atom feed
* where does this belong?
@ 2002-03-27  0:18 Paul Jarc
  2002-03-27  8:57 ` Kai Großjohann
  2002-03-27 10:17 ` Simon Josefsson
  0 siblings, 2 replies; 8+ messages in thread
From: Paul Jarc @ 2002-03-27  0:18 UTC (permalink / raw)


I came up with a meta-macro called nnmaildir--defstruct for defining
data structures.  Sample use:

(nnmaildir--defstruct nnmaildir--srv
  [address    ;; the server address string
   method     ;; the select method
   ...
   ])

This defines macros such as nnmaildir--srv-get-address and
nnmaildir--srv-set-address which expand to aref and aset forms, much
like the gnus-info-* macros, complete with automatic docstrings.  This
makes for less typing and prevents me from accidentally using a
different index in the -get- and -set- macros for the same member of a
data structure.

After I wrote this, I realized its usefulness really isn't limited to
nnmaildir.  E.g., the gnus-info-* macros could maybe be reimplemented
with this.  So where would be a good place for it?  gnus-util.el?
gnus.el?


paul



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: where does this belong?
  2002-03-27  0:18 where does this belong? Paul Jarc
@ 2002-03-27  8:57 ` Kai Großjohann
  2002-03-27 10:17 ` Simon Josefsson
  1 sibling, 0 replies; 8+ messages in thread
From: Kai Großjohann @ 2002-03-27  8:57 UTC (permalink / raw)


prj@po.cwru.edu (Paul Jarc) writes:

> I came up with a meta-macro called nnmaildir--defstruct for defining
> data structures.

I wonder, how does this differ from defstruct?  I think you can even
use it without requiring CL at run time...

I'm sure there is a reason why you didn't want to use plain defstruct.

kai
-- 
Silence is foo!



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: where does this belong?
  2002-03-27  0:18 where does this belong? Paul Jarc
  2002-03-27  8:57 ` Kai Großjohann
@ 2002-03-27 10:17 ` Simon Josefsson
  2002-03-27 10:27   ` Daniel Pittman
  1 sibling, 1 reply; 8+ messages in thread
From: Simon Josefsson @ 2002-03-27 10:17 UTC (permalink / raw)
  Cc: ding

On Tue, 26 Mar 2002, Paul Jarc wrote:

> I came up with a meta-macro called nnmaildir--defstruct for defining
> data structures.  Sample use:
> 
> (nnmaildir--defstruct nnmaildir--srv
>   [address    ;; the server address string
>    method     ;; the select method
>    ...
>    ])
> 
> This defines macros such as nnmaildir--srv-get-address and
> nnmaildir--srv-set-address which expand to aref and aset forms, much
> like the gnus-info-* macros, complete with automatic docstrings.  This
> makes for less typing and prevents me from accidentally using a
> different index in the -get- and -set- macros for the same member of a
> data structure.
> 
> After I wrote this, I realized its usefulness really isn't limited to
> nnmaildir.  E.g., the gnus-info-* macros could maybe be reimplemented
> with this.  So where would be a good place for it?  gnus-util.el?
> gnus.el?

Perhaps it can be ripped out and put into a .el file of it's own?  It 
seems that maybe there are non-gnus uses for it as well.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: where does this belong?
  2002-03-27 10:17 ` Simon Josefsson
@ 2002-03-27 10:27   ` Daniel Pittman
  2002-03-27 16:06     ` Paul Jarc
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Pittman @ 2002-03-27 10:27 UTC (permalink / raw)


On Wed, 27 Mar 2002, Simon Josefsson wrote:
> On Tue, 26 Mar 2002, Paul Jarc wrote:
> 
>> I came up with a meta-macro called nnmaildir--defstruct for defining
>> data structures.  Sample use:

[...]

>> After I wrote this, I realized its usefulness really isn't limited to
>> nnmaildir.  E.g., the gnus-info-* macros could maybe be reimplemented
>> with this.  So where would be a good place for it?  gnus-util.el?
>> gnus.el?
> 
> Perhaps it can be ripped out and put into a .el file of it's own?  It 
> seems that maybe there are non-gnus uses for it as well.

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, OK, the `defstruct' routine emits `setf' expansions for the
structure, not `xxx-set-yyy' routines but, frankly, I can't really see
the difference.

Is this another poorly-specified reinvention of the code in the cl
package in an effort to avoid irritating RMS?

        Daniel

-- 
Han Solo:      Afraid I was gonna leave without giving you a goodbye kiss?
Princess Leia: I'd just as soon kiss a Wookiee!
Han Solo:      I can arrange that! You could use a good kiss!
        -- _The Empire Strikes Back_



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: where does this belong?
  2002-03-27 10:27   ` Daniel Pittman
@ 2002-03-27 16:06     ` Paul Jarc
  2002-03-27 17:16       ` Kai Großjohann
  2002-03-28  2:09       ` Daniel Pittman
  0 siblings, 2 replies; 8+ messages in thread
From: Paul Jarc @ 2002-03-27 16:06 UTC (permalink / raw)


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. :)  Now that I do, I see that mine is much smaller:

(defmacro nnmaildir--defstruct (name members)
  "Defines NAME-new, NAME-get-MEMBER, and NAME-set-MEMBER macros."
  (let ((index 0)
        (namesym name)
        member)
    (setq name (symbol-name namesym))
    (eval `(defmacro ,(intern (concat name "-new")) ()
             ,(concat "Creates a new \"" name "\" structure.")
             '(make-vector ,(length members) nil)))
    (mapcar
      (lambda (membersym)
        (setq member (symbol-name membersym))
        (eval `(defmacro ,(intern (concat name "-get-" member)) (,namesym)
                 ,(concat "Returns the \"" member "\" member of a \"" name
                          "\" structure.")
                 (list 'aref ,namesym ,index)))
        (eval `(defmacro ,(intern (concat name "-set-" member))
                 (,namesym ,membersym)
                 ,(concat "Sets the \"" member "\" member of a \"" name
                          "\" structure.")
                 (list 'aset ,namesym ,index ,membersym)))
        (setq index (1+ index)))
      members)
    nil))

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


paul



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: where does this belong?
  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
  1 sibling, 1 reply; 8+ messages in thread
From: Kai Großjohann @ 2002-03-27 17:16 UTC (permalink / raw)


prj@po.cwru.edu (Paul Jarc) writes:

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

Here is what I use in Tramp:

(defstruct tramp-file-name multi-method method user host path)

After this, there is a constructor make-tramp-file-name which can be
called like this:

(make-tramp-file-name :multi-method x
                      :method y
                      :user u
                      :host h
                      :path p)

And there are functions tramp-file-name-multi-method through
tramp-file-name-path which get the corresponding items.

And then you can do 

    (setf (tramp-file-name-host x) "new-host")

to change the "host" component of a structure.

Does this help?

kai
-- 
Silence is foo!



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: where does this belong?
  2002-03-27 17:16       ` Kai Großjohann
@ 2002-03-27 19:13         ` Paul Jarc
  0 siblings, 0 replies; 8+ messages in thread
From: Paul Jarc @ 2002-03-27 19:13 UTC (permalink / raw)


Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Großjohann) wrote:
> (defstruct tramp-file-name multi-method method user host path)
...
> And then you can do
>
>     (setf (tramp-file-name-host x) "new-host")
>
> to change the "host" component of a structure.
>
> Does this help?

Yes, thanks.  It looks like that will work for me.


paul



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: where does this belong?
  2002-03-27 16:06     ` Paul Jarc
  2002-03-27 17:16       ` Kai Großjohann
@ 2002-03-28  2:09       ` Daniel Pittman
  1 sibling, 0 replies; 8+ messages in thread
From: Daniel Pittman @ 2002-03-28  2:09 UTC (permalink / raw)


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?_



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2002-03-28  2:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-27  0:18 where does this belong? 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 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).