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:45:17 -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 1291672647 25814 80.91.229.12 (6 Dec 2010 21:57:27 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 6 Dec 2010 21:57:27 +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:57:23 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 1PPj3i-0006qv-Gj for geh-help-gnu-emacs@m.gmane.org; Mon, 06 Dec 2010 22:57:23 +0100 Original-Received: from localhost ([127.0.0.1]:40951 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPj3h-0001qn-PM for geh-help-gnu-emacs@m.gmane.org; Mon, 06 Dec 2010 16:57:22 -0500 Original-Received: from [140.186.70.92] (port=56506 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPgzx-0007kB-HY for help-gnu-emacs@gnu.org; Mon, 06 Dec 2010 14:45:22 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PPgzv-0001wi-Hx for help-gnu-emacs@gnu.org; Mon, 06 Dec 2010 14:45:21 -0500 Original-Received: from mail-iw0-f169.google.com ([209.85.214.169]:40822) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PPgzv-0001wO-El for help-gnu-emacs@gnu.org; Mon, 06 Dec 2010 14:45:19 -0500 Original-Received: by iwn5 with SMTP id 5so101028iwn.0 for ; Mon, 06 Dec 2010 11:45:18 -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=16Gdk2t2HugOatdKZJh0GSi6YhhMjAnws/kV9RtWCDs=; b=TymjzgXH2uw5so7rbZoJfPvM2I0V8BpS/zgG6pUmzJA8E/r5yoIZpdK+9N8ZX/b7MA e7d6I5eHD+zEhBgaLzxQMqdWrkCne8g9gWlcN3RYG/eP9teo26ZpWIuCknv0I1MeNZLZ rbugtExgiGAY7xVxx8OmTRxrJu8uhCcz9TwiM= 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=nMAkzx2JBjj/7eZY+7xVj5cbvHHV+xP9hVRz74pnNCkjeVnfAUxM6imb8TamfQYW/7 z/kNJDyAbIoFmuGkWdZzZJYo1b42cZn3vXH28DeLpaCASUzHslVcut5umnkuegDl4Hk+ OhjKY2lcyG2oQHelZLKNGheD5+FOIoeWWjkzA= Original-Received: by 10.231.183.136 with SMTP id cg8mr6359423ibb.63.1291664717974; Mon, 06 Dec 2010 11:45:17 -0800 (PST) Original-Received: by 10.231.35.195 with HTTP; Mon, 6 Dec 2010 11:45:17 -0800 (PST) In-Reply-To: <87lj43at0i.fsf@ambire.localdomain> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Mailman-Approved-At: Mon, 06 Dec 2010 16:45:21 -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:75520 Archived-At: 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 dropp= ed. > =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 match > =A0 =A0 =A0 =A0;; data; you can use =91(match-string 1)=92 to retrieve it= . > =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 usin= g 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 !!! > > =A0 [Q] Is there a way to using plists for return from find-my-marker-GOL= D > =A0 =A0 =A0 and utilize in the user function test-GOLD > > Yes, but probably you will want to avoid plists. >