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: How to remove verbosity from the data passing mechanism using alist or plist ? Date: Sun, 5 Dec 2010 12:15:08 -0800 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: dough.gmane.org 1291580123 3570 80.91.229.12 (5 Dec 2010 20:15:23 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 5 Dec 2010 20:15:23 +0000 (UTC) To: "Emacs Dev [emacs-devel]" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Dec 05 21:15:18 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 1PPKzM-0002BJ-8d for ged-emacs-devel@m.gmane.org; Sun, 05 Dec 2010 21:15:17 +0100 Original-Received: from localhost ([127.0.0.1]:45770 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPKzL-0004Wu-HT for ged-emacs-devel@m.gmane.org; Sun, 05 Dec 2010 15:15:15 -0500 Original-Received: from [140.186.70.92] (port=44613 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPKzH-0004Wf-1O for emacs-devel@gnu.org; Sun, 05 Dec 2010 15:15:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PPKzF-0008Vo-O1 for emacs-devel@gnu.org; Sun, 05 Dec 2010 15:15:10 -0500 Original-Received: from mail-iw0-f169.google.com ([209.85.214.169]:45630) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PPKzF-0008Vi-Ka for emacs-devel@gnu.org; Sun, 05 Dec 2010 15:15:09 -0500 Original-Received: by iwn33 with SMTP id 33so2233344iwn.0 for ; Sun, 05 Dec 2010 12:15:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=faL+CzFMpudYa2Bei+SIU6S8weqtrNUG2kr/bko9C1I=; b=UmOeUYM/rcfFhA0CZFPh96anFqa33U8R+H4yqUCT0Lv8jkC0evRDvVp2EbpxoVZQeJ vPejsoPnY0NMCjpbRrfs6/gh3GH5UlL3E7qznAhLgxvUo6wYCQ4Ftuj0mayp6K5kPFkO C/x7TtMSa6QlJTioO7E2IlCy+/dITDKtJ16rs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=XKzse4FAIG+t4ukKfHlts4dNEDgNFDeQFO+CaBkaZtTwGFHGCY+rAROJUCLwgeHT+G A+HAe+T18tyirplR//wT6kx7+BHy5oU4isZS0dZ+1wg7qiNgwN++KyUXra+9P1aHuyav 5HiGcfp4U0tozZS8OrHSKWM+LStxLmtb54obg= Original-Received: by 10.231.200.134 with SMTP id ew6mr2102468ibb.13.1291580108528; Sun, 05 Dec 2010 12:15:08 -0800 (PST) Original-Received: by 10.231.35.195 with HTTP; Sun, 5 Dec 2010 12:15:08 -0800 (PST) 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:133437 Archived-At: 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=1000 (defun find-my-marker-GOLD () "Starting from anywhere in the file, find my marker GOLD its value and location." (interactive) (save-excursion (save-match-data ;; Starting from the end of the file, find GOLD ;; (goto-char (point-max)) ; Go to the end of the file, and then (search-backward-regexp "GOLD=\\([0-9]+\\)\n" nil nil nil) ; find the GOLD, and (list ; as an a-list, return its (list :GOLD-value ; value, and (string-to-number ; read and return it, with its (replace-regexp-in-string "GOLD=\\([0-9]+\\)\n" "\\1" (match-string 0)))) (list :GOLD-location ; location. (point) ))))) ; (assoc-default :GOLD-value (find-my-marker-GOLD)) (defun test-GOLD (GOLD) "for now, tests the alist passing mechanism, later more." (let ((GOLD-value (car (assoc-default :GOLD-value GOLD ))) (GOLD-location (car (assoc-default :GOLD-location GOLD )))) (list GOLD-value GOLD-location) ) ) (test-GOLD (find-my-marker-GOLD)) 8<----------------------------------------------------------------------------------------------------------------- [Q] Are there any defects in this method of passing struct and what improvements are possible ? Specifically, 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 (car (assoc-default :GOLD-value GOLD ) inside let, since the first argument of let is an alist of the form ((sym1 val1) (sym2 val2)) [Q] Is there a way to using plists for return from find-my-marker-GOLD and 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. The main goal is brevity, style improvement and more acceptable style. (a) Solution that is pure elisp and does not use any defmacros , defclass etc. (b) Solution that is clisp and un-restricted. (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 similar to find-my-marker-GOLD in that it would go using this data to the nearest GOLD processing plant with the help of a suitable regexp. There was no need to split this set of actions into several small functions except for the purpose of modularity. The issue is what is a good style for such a problem where there is coupling ie only find-GOLD-processing-plant can use the object of type GOLD, not a find-SILVER-processing-plant because there are some hidden assumptions, such as the nearest regexp of type PLANT=address near a GOLD=value object is a GOLD processing plant and the nearest regexp of type PLANT=address near a SILVER=value object is a SILVER processing plant. Thus, in view of this hidden coupling, which I am not able to get rid of without too much complication and The main goals are to write main function as a readable english prose and also to remove the verbosity in passing data (alist and plist) 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