emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fadr


From: Dmitry Dzhus
Subject: Re: fadr
Date: Tue, 23 Jun 2009 01:38:46 +0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.95 (gnu/linux)

Chong Yidong wrote:

> If you need a way to interface easily with nested structures, I
> suggest using Common Lisp structures, i.e. the `defstruct' macro which
> has been in cl-macs.el for a long time.

As long as I understand, with `defstruct` and friends I'll need to
declare structure types for each level of my tree-like structure so that
I can nest structure slot accessor calls, e.g.:

    (defstruct threads-response threads current-thread-id)
    (defstruct thread id target-id state frame)
    (defstruct frame level addr func args file fullname line)
    (defstruct arg name value)
    (setq threads
          (make-threads-response
           :threads
           (list
            (make-thread :id "1"
                         :target-id "LWP18334"
                         :frame (make-frame :level "0"
                                            :addr "0x08048b9a"
                                            :func "mult_matrices_mt"
                                            :args (list (make-arg :name "m1"
                                                                  :value 
"0x08048b9a")
                                                        (make-arg :name "m2"
                                                                  :value 
"0x0804ba30"))
                                            :file "test.c"
                                            :fullname 
"/home/sphinx/projects/gsoc/test.c"
                                            :line "142")
                         :state "stopped"))
           :current-thread-id "1"))
                       
    (frame-func (thread-frame (first (threads-response-threads threads))))

I'll also need to convert my list-alist trees (I've provided a real
example of trees I deal with in my previous mail in this thread) to such
structures, though it doesn't seem complex to me. What's good in
`defstruct` is that it provides simple type and schema checking, so if
my structures get spoiled (which is unlikely, but may happen if GDB's MI
changes output format), it will be easier to debug related bugs. I don't
think if this is worth investing effort right now, though, probably
`binopt.el` code will be sufficient.

I believe `defstruct` doesn't impose any performance overhead? Given
that I need to handle much less then a hundred trees per one short
timeframe.

I've grepped through Emacs sources, looking for examples of using
`defstruct`, but I haven't found anything resembling my case.

I've also found the following notice (mh-loaddefs.el:70):

> The `defstruct' in the "cl" library produces compiler warnings, and
> generates code that uses functions present in "cl" at run-time.

— is this true?

The following sentence from cl package info manual is a bit unclear to me:

> Also, the `:type' slot option is ignored.

Does this mean that `defstruct` procedures are unable to check if slot
values provided to structure constructor are of some certain types?

So :type slot options used around erc-backend.el:109 are merely harmless
annotations for developer?
-- 
Happy Hacking.

http://sphinx.net.ru

reply via email to

[Prev in Thread] Current Thread [Next in Thread]