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: How to remove verbosity from the data passing mechanism using alist or plist ? Date: Sun, 5 Dec 2010 21:09:05 -0800 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1291672173 23618 80.91.229.12 (6 Dec 2010 21:49:33 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 6 Dec 2010 21:49:33 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 06 22:49:29 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 1PPiw4-0003NZ-71 for geh-help-gnu-emacs@m.gmane.org; Mon, 06 Dec 2010 22:49:28 +0100 Original-Received: from localhost ([127.0.0.1]:50439 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPiw3-0006Hr-Lb for geh-help-gnu-emacs@m.gmane.org; Mon, 06 Dec 2010 16:49:27 -0500 Original-Received: from [140.186.70.92] (port=42881 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPTJz-0002eD-UN for help-gnu-emacs@gnu.org; Mon, 06 Dec 2010 00:09:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PPTJy-0008WG-LJ for help-gnu-emacs@gnu.org; Mon, 06 Dec 2010 00:09:07 -0500 Original-Received: from mail-iw0-f169.google.com ([209.85.214.169]:37500) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PPTJy-0008Vy-8I for help-gnu-emacs@gnu.org; Mon, 06 Dec 2010 00:09:06 -0500 Original-Received: by iwn33 with SMTP id 33so2700519iwn.0 for ; Sun, 05 Dec 2010 21:09:05 -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=8SB/BSbzRt8f7dokuiWrn934azdmhPfo9VIIT5yggZw=; b=yF0+YEK4JQEISduw8uAyjVGF/yk45Rz1r4H5Z22NDTKsEYZe7q2vTPf0wceScsoMfa FBDpD8Ryf0A+j6nwPTLbJdjDKeEBwwJFDy17CgUCNGvc0uHb3Z4lP1PG2ZHQhARU5/7a ejE8gv59MEkV5z8ewqmVPvEgJ8bqOodev8aWs= 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=GxJqv0L0ucmG6DtMnUb5+mhLKIGZrrap/NiVu9NIR6WjgIFqvOw2S3yh93yd4KohkK p/0PwgwJrntDrbJNc6K2VEKEbKE3TKjEYiRkRNHKhIQAuTxjtWWbAM1IzeVc65FGJqAl IB99PjYofmU2AFlbak7Z6RNj9TnxGlQpDiF3o= Original-Received: by 10.231.37.13 with SMTP id v13mr5302787ibd.163.1291612145866; Sun, 05 Dec 2010 21:09:05 -0800 (PST) Original-Received: by 10.231.35.195 with HTTP; Sun, 5 Dec 2010 21:09:05 -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:10 -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:75518 Archived-At: How to remove verbosity from the data passing mechanism using alist or plist ? Reading thru the various threads and replies by the luminaries of lisp, CL, elisp, scheme, functional programming etc. I have decided to write a small game of following data in a buffer. At this state I am only readyfor the following questions. Yesterday, in my questions, I explored how to get data from buffer into strings. 8<-------------------------------------------------------------------------= ---------------------------------------- GOLD=3D1000 (defun find-my-marker-GOLD () =A0"Starting from anywhere in the file, find my marker GOLD its value and location." =A0(interactive) =A0(save-excursion =A0 =A0(save-match-data =A0 =A0 =A0;; Starting from the end of the file, find GOLD =A0 =A0 =A0;; =A0 =A0 =A0(goto-char (point- max)) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 ; Go to the end of the file, and then =A0 =A0 =A0(search-backward-regexp "GOLD=3D\\([0-9]+\\)\n" nil nil nil) =A0 =A0 =A0 =A0 =A0 =A0; =A0find the GOLD, and (list =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ; as an a-list, return its =A0 =A0 =A0 (list =A0 =A0 =A0 =A0:GOLD- value =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ; value, and =A0 =A0 =A0 =A0(string-to- number =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ; =A0read and return it, with its =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 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0; location. =A0 =A0 =A0 =A0(point) ))))) ; (assoc-default :GOLD-value (find-my-marker-GOLD)) (defun test-GOLD (GOLD) =A0"for now, tests the alist passing mechanism, later more." =A0(let ((GOLD-value =A0 =A0(car (assoc-default :GOLD-value =A0 =A0GOLD ))) =A0 =A0 =A0 =A0(GOLD-location (car (assoc-default :GOLD-location GOLD )))) =A0 =A0(list GOLD-value GOLD-location) =A0 =A0) =A0) (test-GOLD (find-my-marker-GOLD)) 8<-------------------------------------------------------------------------= ---------------------------------------- [Q] Are there any defects in this method of passing struct and what improvements are possible ? =A0 =A0Specifically, are there ways to reduce verbosity without using cl or staying purely in elisp ? [Q] Is there a way to avoid lengthy calling statement like =A0 =A0 =A0(car (assoc-default :GOLD-value =A0 =A0GOLD ) =A0 =A0inside let, =A0 =A0since the first argument of let is an alist of the form =A0 =A0 =A0 =A0 ((sym1 val1) (sym2 val2)) [Q] Is there a way to using plists for return from find-my-marker-GOLD =A0 =A0and utilize in the user function test-GOLD [Q] As you can see, I am looking for several level of solutions so I can weight them. =A0 =A0The main goal is brevity, style improvement and more acceptable style. =A0(a) Solution that is pure elisp and does not use any defmacros , defclass etc. =A0(b) Solution that is clisp and un-restricted. =A0 (c) and within both of the above, solutions with plist and alist. [Q] test-GOLD will actually be a function called find-GOLD-processing- plant =A0 =A0similar to find-my-marker-GOLD in =A0 =A0that it would go using this data to the nearest GOLD processing plant with =A0 =A0the help of a suitable regexp. There was no need to split this set of actions =A0 =A0into several small functions except for the purpose of modularity. The issue =A0 =A0is what is a good style for such a problem where there is coupling ie only =A0 =A0find-GOLD-processing-plant can use the object of type GOLD, not a =A0 =A0find-SILVER-processing-plant because there are some hidden assumptions, such =A0 =A0as the nearest regexp of type PLANT=3Daddress near a GOLD=3Dvalue object =A0 =A0is a GOLD processing plant and the nearest regexp of type PLANT=3Daddress =A0 =A0near a SILVER=3Dvalue object is a SILVER processing plant. =A0 =A0Thus, in view of this hidden coupling, which I am not able to get rid of =A0 =A0without too much complication and The main goals are =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 to write main function as a readabl= e english prose and also =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 to remove the verbosity in passing = data (alist and plist) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 in and out of functions. Thanks again for your help. For a newbie please put some comments as in my function find-my-marker- GOLD since many of you try to use language constructs in clever ways ? Franz Xe