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 07:41:21 -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 1291674020 32630 80.91.229.12 (6 Dec 2010 22:20:20 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 6 Dec 2010 22:20:20 +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 23:20:15 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 1PPjPq-00014V-WB for geh-help-gnu-emacs@m.gmane.org; Mon, 06 Dec 2010 23:20:15 +0100 Original-Received: from localhost ([127.0.0.1]:39785 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPj1s-00017J-BW for geh-help-gnu-emacs@m.gmane.org; Mon, 06 Dec 2010 16:55:28 -0500 Original-Received: from [140.186.70.92] (port=48509 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPdBs-0006CT-3q for help-gnu-emacs@gnu.org; Mon, 06 Dec 2010 10:41:29 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PPdBq-0001OW-Qw for help-gnu-emacs@gnu.org; Mon, 06 Dec 2010 10:41:23 -0500 Original-Received: from mail-iw0-f169.google.com ([209.85.214.169]:49382) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PPdBq-0001OR-Ma for help-gnu-emacs@gnu.org; Mon, 06 Dec 2010 10:41:22 -0500 Original-Received: by iwn4 with SMTP id 4so66267iwn.0 for ; Mon, 06 Dec 2010 07:41:22 -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=uYrTw98pEN5WzES4FgnxgLQWgBD3DS+BYef12RWHuRY=; b=VWC8QwhgMkEiDbhwxD73OZKmkJTWOzoZb3PMZnCmDxeAIJNlBroRvZAXJk+bSG23xP xtNdXy0ui6gSiXtz6DRb2CuKElORxhVQ6rTR0DbCtO8ivQ2xkPLbBEDnmIrVVJIyfxT4 bE4L6omaWZXZplopjG9Tz5AVPNiHRgJhg0kAE= 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=I/jYmX9kVEHPYBHIn0s+2ZRc5cdhoP8rKyC5rQ13vpBbrJDWhIon0QYRPGPEsQTGqF x21l3/iuUDGOVn2rD85DqTpYQM38PstvL/mZ78y8px1PvjiFfhAwHo199uqqCe7fZuHN /5+TctFkLsuG2nlUsbI+suWG+nu5Qkfu01IP0= Original-Received: by 10.231.200.134 with SMTP id ew6mr3301900ibb.13.1291650081850; Mon, 06 Dec 2010 07:41:21 -0800 (PST) Original-Received: by 10.231.35.195 with HTTP; Mon, 6 Dec 2010 07:41:21 -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:20 -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:75522 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. Excellent point. > > =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. I would certainly need a toy example or even ask for taking this example and showing me how to do it. I am not familiar with this table-oriented approach. > =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)) > > 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. Good point > > =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. >