From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Fren Zeee Newsgroups: gmane.emacs.help Subject: Re: How to remove verbosity from the data passing mechanism using alist or plist ? Date: Mon, 6 Dec 2010 11:46:37 -0800 Message-ID: References: <87lj43at0i.fsf@ambire.localdomain> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1291672734 26181 80.91.229.12 (6 Dec 2010 21:58:54 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 6 Dec 2010 21:58:54 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Thien-Thi Nguyen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 06 22:58:49 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 1PPj56-0007UC-VP for geh-help-gnu-emacs@m.gmane.org; Mon, 06 Dec 2010 22:58:49 +0100 Original-Received: from localhost ([127.0.0.1]:46696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPj56-0002WK-E9 for geh-help-gnu-emacs@m.gmane.org; Mon, 06 Dec 2010 16:58:48 -0500 Original-Received: from [140.186.70.92] (port=57559 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPh1E-0001kp-0W for help-gnu-emacs@gnu.org; Mon, 06 Dec 2010 14:46:42 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PPh1C-0002PB-Ml for help-gnu-emacs@gnu.org; Mon, 06 Dec 2010 14:46:39 -0500 Original-Received: from mail-iw0-f169.google.com ([209.85.214.169]:56530) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PPh1C-0002P1-JS for help-gnu-emacs@gnu.org; Mon, 06 Dec 2010 14:46:38 -0500 Original-Received: by iwn5 with SMTP id 5so102169iwn.0 for ; Mon, 06 Dec 2010 11:46:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=clIVoQugcMSbQyoJvSHWqEBPX3HkUcJb9+nosGqIc7Y=; b=Qp0x5M3cef/tSB6dX0X4zO0ci0EI6Wr+zCkZoH3qlgedWjqMoTOpYf4RKzGaQehPYM 7raBLE1bXRPXNzF/J5Ke3hGsk/yKpeu9ULKf08QLMJUeBqZpltGFK6EiCHvNRkosO7TI /QfHvn3M1KbztBbyaJc1RR+OUE1WjC1HXbiNM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=OVCsueNvGa/ERPoHg4iid7Isdh/SdDLgHmkBrD8aDO/J0HkzXz0t54QDX5cIVEfDoK lkSz9LIyCacDLxV9OX60KH9MaOQc4Vud003ghqaDbrW0Qd2kDEiL5EtWuDk2RO6MnDAD AFCw6/yjClsX4LctQraXhZH93H+bT7UEL4im4= Original-Received: by 10.231.32.197 with SMTP id e5mr6261641ibd.188.1291664797864; Mon, 06 Dec 2010 11:46:37 -0800 (PST) Original-Received: by 10.231.35.195 with HTTP; Mon, 6 Dec 2010 11:46:37 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Mailman-Approved-At: Mon, 06 Dec 2010 16:45:23 -0500 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:75521 Archived-At: On Mon, Dec 6, 2010 at 11:45 AM, Fren Zeee wrote: > On Mon, Dec 6, 2010 at 6:13 AM, Thien-Thi Nguyen wrote: >> [cc changed to help-gnu-emacs -- this does not belong on emacs-devel] >> >> () Fren Zeee >> () Sun, 5 Dec 2010 12:15:08 -0800 >> >> =A0 [code] >> >> Here is =91find-my-marker-GOLD=92, munged a bit: >> >> (defun find-my-marker-GOLD () >> =A0"Starting from anywhere in the file, find my marker GOLD its value >> =A0 and location." >> =A0(interactive) >> =A0(save-excursion >> =A0 =A0(save-match-data >> =A0 =A0 =A0;; Starting from the end of the accessible region, find GOLD. >> =A0 =A0 =A0(goto-char (point-max)) >> =A0 =A0 =A0;; a/ This value of this expression is discarded. >> =A0 =A0 =A0;; =A0 =A0It turns out to be the same as "location" below, >> =A0 =A0 =A0;; =A0 =A0so if you save it, you can avoid a call to =91point= =92. >> =A0 =A0 =A0;; b/ The optional args default to =91nil=92, and can be drop= ped. >> =A0 =A0 =A0(search-backward-regexp "GOLD=3D\\([0-9]+\\)\n" nil nil nil) >> >> =A0 =A0 =A0;; In the following, i have deleted the eol comments, which >> =A0 =A0 =A0;; obscure more than enlighten (on my small computer screen). >> >> =A0 =A0 =A0;; You might consider using `((k0 . ,v0) >> =A0 =A0 =A0;; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(k1= . ,v1)) >> =A0 =A0 =A0;; for succinctness (note backquote and comma placement). >> =A0 =A0 =A0;; An intermediate solution is to use =91acons=92. >> =A0 =A0 =A0(list >> =A0 =A0 =A0 (list >> =A0 =A0 =A0 =A0:GOLD-value >> =A0 =A0 =A0 =A0;; The =91replace-regexp-in-string=92 is not necessary. >> =A0 =A0 =A0 =A0;; The initial regexp match (above) already sets the matc= h >> =A0 =A0 =A0 =A0;; data; you can use =91(match-string 1)=92 to retrieve i= t. >> =A0 =A0 =A0 =A0(string-to-number >> =A0 =A0 =A0 =A0 (replace-regexp-in-string "GOLD=3D\\([0-9]+\\)\n" "\\1" = =A0(match-string 0)))) >> =A0 =A0 =A0 (list >> =A0 =A0 =A0 =A0:GOLD-location >> =A0 =A0 =A0 =A0(point)))))) >> >> =A0 [Q] Are there any defects in this method of passing struct and what >> =A0 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. =A0Improvements, likewise, depend on intention and pov. >> >> =A0 =A0 =A0 Specifically, are there ways to reduce verbosity without usi= ng cl >> =A0 or staying purely in elisp ? >> >> You can use shorter variable names. =A0You can make your program >> less piecewise-constructive and more table-oriented. >> >> =A0 [Q] Is there a way to avoid lengthy calling statement like >> =A0 =A0 =A0 =A0 (car (assoc-default :GOLD-value =A0 =A0GOLD ) >> =A0 =A0 =A0 inside let, >> >> =A0 =A0 =A0 since the first argument of let is an alist of the form >> =A0 =A0 =A0 =A0 =A0 =A0((sym1 val1) (sym2 val2)) >> > > OK lets take the suggestion below and show me how it works with my case ? > >> You need the =91car=92 because you do =91(list k v)=92. >> If you use =91(cons k v)=92, then you do not need the =91car=92. > > What I have is > > (list (list k1 v1) (list k2 v2)) > > Now, kindly show me where I put the car to get both of these uniformly > communicated outside of the function to another function ? Later in > some cases I may have (k3 v3) pair !!! Here is a sexp to play with ready in hand ... so show me how to do it ? (assoc-default 'y '((w 0) (x 1) (y 2) (z 3))) >> >> =A0 [Q] Is there a way to using plists for return from find-my-marker-GO= LD >> =A0 =A0 =A0 and utilize in the user function test-GOLD >> >> Yes, but probably you will want to avoid plists. >> >