From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Fren Zeee Newsgroups: gmane.emacs.devel Subject: Fwd: How to remove verbosity from the data passing mechanism using alist or plist ? Date: Mon, 6 Dec 2010 22:18:07 -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 1291702705 6934 80.91.229.12 (7 Dec 2010 06:18:25 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 7 Dec 2010 06:18:25 +0000 (UTC) To: "Emacs Dev [emacs-devel]" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Dec 07 07:18:21 2010 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.69) (envelope-from ) id 1PPqsV-0001Ry-4x for ged-emacs-devel@m.gmane.org; Tue, 07 Dec 2010 07:18:19 +0100 Original-Received: from localhost ([127.0.0.1]:55025 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPqsT-0002oK-R7 for ged-emacs-devel@m.gmane.org; Tue, 07 Dec 2010 01:18:17 -0500 Original-Received: from [140.186.70.92] (port=42841 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPqsL-0002o9-Pc for emacs-devel@gnu.org; Tue, 07 Dec 2010 01:18:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PPqsK-0000ye-Eh for emacs-devel@gnu.org; Tue, 07 Dec 2010 01:18:09 -0500 Original-Received: from mail-iw0-f169.google.com ([209.85.214.169]:56019) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PPqsK-0000xb-A1 for emacs-devel@gnu.org; Tue, 07 Dec 2010 01:18:08 -0500 Original-Received: by iwn5 with SMTP id 5so718003iwn.0 for ; Mon, 06 Dec 2010 22:18:07 -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:content-type :content-transfer-encoding; bh=5KVllVfSpXx+iXyl2E8BUwyl6QuKlLinTUFvhtDEAdo=; b=WETWavjZzaeIQ74T/lEn49yz48UHvb4H4tKz7ZI/APIP2juyQS5pJMaVl+EevZrFse LROZiFOkPzkXucthWaa+BswwuPBPT7apMOWzK7i9JxJ1J36eIhCAq3sBMwssXzmnM2m+ sqe3M7cdu89RY0871QJEl6H4gxOA4m497bqD8= 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 :content-type:content-transfer-encoding; b=JCFXHON327Gm5Hgj0hPEIH/mhkGEpK//hQt2F56g4SQATKlr1DEu5eOKqC3jM+iVRM ExYX2nE0v8WoRyPiFyX3n3pSxZK06y3JctOHw9Beugb8tGb9QVLxARpVZQjk5uFte55+ uAhara7O7Vn129M8zZDVkG9Wp7UlekMz1xPi4= Original-Received: by 10.231.37.13 with SMTP id v13mr7019457ibd.163.1291702687102; Mon, 06 Dec 2010 22:18:07 -0800 (PST) Original-Received: by 10.231.35.195 with HTTP; Mon, 6 Dec 2010 22:18:07 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) 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:133487 Archived-At: There was no reply from the help mailing list and this is very confusing so I am forced to go back where the crowd is. Its a very simple issue of cons versus list below. ---------- Forwarded message ---------- From: Fren Zeee Date: Mon, Dec 6, 2010 at 11:45 AM Subject: Re: How to remove verbosity from the data passing mechanism using alist or plist ? To: Thien-Thi Nguyen Cc: help-gnu-emacs@gnu.org 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. >