From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.help Subject: Re: How to remove verbosity from the data passing mechanism using alist or plist ? Date: Mon, 06 Dec 2010 15:13:49 +0100 Message-ID: <87lj43at0i.fsf@ambire.localdomain> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1291646076 16208 80.91.229.12 (6 Dec 2010 14:34:36 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 6 Dec 2010 14:34:36 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Fren Zeee Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 06 15:34:32 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PPc99-0006xz-No for geh-help-gnu-emacs@m.gmane.org; Mon, 06 Dec 2010 15:34:31 +0100 Original-Received: from localhost ([127.0.0.1]:60535 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPc99-0006nO-Dh for geh-help-gnu-emacs@m.gmane.org; Mon, 06 Dec 2010 09:34:31 -0500 Original-Received: from [140.186.70.92] (port=56982 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPbtt-0007Xq-2q for help-gnu-emacs@gnu.org; Mon, 06 Dec 2010 09:18:46 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PPbtq-0007BN-GA for help-gnu-emacs@gnu.org; Mon, 06 Dec 2010 09:18:44 -0500 Original-Received: from smtp208.alice.it ([82.57.200.104]:58887) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PPbtq-0007Ab-1F for help-gnu-emacs@gnu.org; Mon, 06 Dec 2010 09:18:42 -0500 Original-Received: from ambire.localdomain (95.244.64.105) by smtp208.alice.it (8.5.124.08) id 4C1A27160BF26642; Mon, 6 Dec 2010 15:18:38 +0100 Original-Received: from ttn by ambire.localdomain with local (Exim 4.69) (envelope-from ) id 1PPbp7-0002ps-EN; Mon, 06 Dec 2010 15:13:49 +0100 In-Reply-To: (Fren Zeee's message of "Sun, 5 Dec 2010 12:15:08 -0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:75515 Archived-At: [cc changed to help-gnu-emacs -- this does not belong on emacs-devel] () Fren Zeee () Sun, 5 Dec 2010 12:15:08 -0800 [code] Here is =E2=80=98find-my-marker-GOLD=E2=80=99, munged a bit: (defun find-my-marker-GOLD () "Starting from anywhere in the file, find my marker GOLD its value and location." (interactive) (save-excursion (save-match-data ;; Starting from the end of the accessible region, find GOLD. (goto-char (point-max)) ;; a/ This value of this expression is discarded. ;; It turns out to be the same as "location" below, ;; so if you save it, you can avoid a call to =E2=80=98point=E2=80= =99. ;; b/ The optional args default to =E2=80=98nil=E2=80=99, and can be = dropped. (search-backward-regexp "GOLD=3D\\([0-9]+\\)\n" nil nil nil) ;; In the following, i have deleted the eol comments, which ;; obscure more than enlighten (on my small computer screen). ;; You might consider using `((k0 . ,v0) ;; (k1 . ,v1)) ;; for succinctness (note backquote and comma placement). ;; An intermediate solution is to use =E2=80=98acons=E2=80=99. (list (list :GOLD-value ;; The =E2=80=98replace-regexp-in-string=E2=80=99 is not necessary. ;; The initial regexp match (above) already sets the match ;; data; you can use =E2=80=98(match-string 1)=E2=80=99 to retrieve= it. (string-to-number (replace-regexp-in-string "GOLD=3D\\([0-9]+\\)\n" "\\1" (match-st= ring 0)))) (list :GOLD-location (point)))))) [Q] Are there any defects in this method of passing struct and what improvements are possible ? All defects are misalignments of intention and implementation. If you don't know your intention clearly, it's easy for a defect to creep in. Improvements, likewise, depend on intention and pov. Specifically, are there ways to reduce verbosity without using cl or staying purely in elisp ? You can use shorter variable names. You can make your program less piecewise-constructive and more table-oriented. [Q] Is there a way to avoid lengthy calling statement like (car (assoc-default :GOLD-value GOLD ) inside let, since the first argument of let is an alist of the form ((sym1 val1) (sym2 val2)) You need the =E2=80=98car=E2=80=99 because you do =E2=80=98(list k v)=E2=80= =99. If you use =E2=80=98(cons k v)=E2=80=99, then you do not need the =E2=80=98= car=E2=80=99. [Q] Is there a way to using plists for return from find-my-marker-GOLD and utilize in the user function test-GOLD Yes, but probably you will want to avoid plists.