From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Dzhus Newsgroups: gmane.emacs.devel Subject: Re: fadr Date: Mon, 22 Jun 2009 23:56:27 +0400 Message-ID: <873a9sghzo.fsf@sphinx.net.ru> References: <87zlc0s3np.fsf@stupidchicken.com> <873a9sz1my.fsf@ambire.localdomain> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1245700845 24671 80.91.229.12 (22 Jun 2009 20:00:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 22 Jun 2009 20:00:45 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jun 22 22:00:42 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MIph4-0001Cy-4R for ged-emacs-devel@m.gmane.org; Mon, 22 Jun 2009 22:00:42 +0200 Original-Received: from localhost ([127.0.0.1]:35510 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MIph3-0002mr-As for ged-emacs-devel@m.gmane.org; Mon, 22 Jun 2009 16:00:41 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MIpgw-0002ma-NV for emacs-devel@gnu.org; Mon, 22 Jun 2009 16:00:34 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MIpgl-0002j2-9F for emacs-devel@gnu.org; Mon, 22 Jun 2009 16:00:33 -0400 Original-Received: from [199.232.76.173] (port=59549 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MIpgl-0002iw-1k for emacs-devel@gnu.org; Mon, 22 Jun 2009 16:00:23 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:42313 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MIpgk-0007t4-AA for emacs-devel@gnu.org; Mon, 22 Jun 2009 16:00:22 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1MIpga-0001aW-0o for emacs-devel@gnu.org; Mon, 22 Jun 2009 20:00:12 +0000 Original-Received: from 95-24-82-94.broadband.corbina.ru ([95.24.82.94]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 22 Jun 2009 20:00:12 +0000 Original-Received: from dima by 95-24-82-94.broadband.corbina.ru with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 22 Jun 2009 20:00:12 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 88 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 95-24-82-94.broadband.corbina.ru User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.95 (gnu/linux) Cancel-Lock: sha1:4Wu8RIbkIIvfPckq8U6njCVoTYs= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:111643 Archived-At: Thank you for your feedback, now I really want to discuss what I wrote and what I should have used instead. Thien-Thi Nguyen wrote: > I would also suggest looking at bindat.el, which is adept at wire > to tree to wire (unpacking/packing) operations for (possibly > nested) fixed-width data types. I don't need unpacking, but the lisp structure bindat maps packed data to is the same as one I use in my code — nested lists and a-lists. Actually, > If we already have a tree, I already have a tree. A lot of different trees with different structure. Like this, for example: (setq threads '((threads . (((id . "1") (target-id . "LWP18334") (frame . ((level . "0") (addr . "0x08048b9a") (func . "mult_matrices_mt") (args . (((name . "m1") (value . "0x804ba30")) ((name . "m2") (value . "0x804ba30")))) (file . "test.c") (fullname . "/home/sphinx/projects/gsoc/test.c") (line . "142"))) (state . "stopped")))) (current-thread-id . "1"))) I'm pleasantly surprised to see that `bindat-get-field` works with such tree (and others I have) like charm. > `bindat-get-field' tweaked or extended is preferable to > `fadr-member' stunted or recast. Moreover, it looks like I don't even need to tweak anything, as `bindat-get-field` is exactly what I was meant to write instead of `fadr-member`. Its docstring mentions the same C-style dotted notation I had in mind while writing fadr. The difference between these two is that `bindat-get-field` is of variable arity and accepts symbols and integers; for `fadr-member` field selectors need to be concatenated into a string. (defun bindat-get-field (struct &rest field) (let ((path)) (dolist (f field) (setq path (concat path (cond ((integerp f) (format "[%d]" f)) ((symbolp f) (format ".%s" f)))))) (fadr-member struct path))) (inverse is longer) So `fadr-member` is just a reinvented wheel at all. I'm going to drop it. > Insert Perlis quote re strings, here.... So what really makes «stark» strings non-lispy (apart from having a font-lock color which differs from that of symbols and parenthesis)? Sometimes I need to access several different leaves of my tree in the same line, so I wrote `fadr-expand` which works as follows: (fadr-expand "Thread ~.threads[0].id has name ~.threads[0].target-id" threads) => "Thread 1 has name LWP18334" A more realistic example from my code: (fadr-format "~.id (~.target-id) ~.state in ~.frame.func " thread) => "1 (LWP18334) stopped in mult_matrices_mt " I coded this function to save some typing. Now I'm in doubts about whether it follows the spirit of Lisp. -- Happy Hacking. http://sphinx.net.ru む