gnu-misc-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to remove verbosity from the data passing mechanism using alist or p


From: Fren Zeee
Subject: How to remove verbosity from the data passing mechanism using alist or plist ?
Date: Sun, 5 Dec 2010 12:22:34 -0800 (PST)
User-agent: G2/1.0

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=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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]