help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How to remove verbosity from the data passing mechanism using alist


From: Fren Zeee
Subject: Re: How to remove verbosity from the data passing mechanism using alist or plist ?
Date: Mon, 6 Dec 2010 11:46:37 -0800

On Mon, Dec 6, 2010 at 11:45 AM, Fren Zeee <frenzeee@gmail.com> wrote:
> On Mon, Dec 6, 2010 at 6:13 AM, Thien-Thi Nguyen <ttn@gnuvola.org> wrote:
>> [cc changed to help-gnu-emacs -- this does not belong on emacs-devel]
>>
>> () Fren Zeee <frenzeee@gmail.com>
>> () Sun, 5 Dec 2010 12:15:08 -0800
>>
>>   [code]
>>
>> Here is ‘find-my-marker-GOLD’, munged a bit:
>>
>> (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 accessible region, find GOLD.
>>      (goto-char (point-max))
>>      ;; a/ This value of this expression is discarded.
>>      ;;    It turns out to be the same as "location" below,
>>      ;;    so if you save it, you can avoid a call to ‘point’.
>>      ;; b/ The optional args default to ‘nil’, and can be dropped.
>>      (search-backward-regexp "GOLD=\\([0-9]+\\)\n" nil nil nil)
>>
>>      ;; In the following, i have deleted the eol comments, which
>>      ;; obscure more than enlighten (on my small computer screen).
>>
>>      ;; You might consider using `((k0 . ,v0)
>>      ;;                            (k1 . ,v1))
>>      ;; for succinctness (note backquote and comma placement).
>>      ;; An intermediate solution is to use ‘acons’.
>>      (list
>>       (list
>>        :GOLD-value
>>        ;; The ‘replace-regexp-in-string’ is not necessary.
>>        ;; The initial regexp match (above) already sets the match
>>        ;; data; you can use ‘(match-string 1)’ to retrieve it.
>>        (string-to-number
>>         (replace-regexp-in-string "GOLD=\\([0-9]+\\)\n" "\\1"  (match-string 
>> 0))))
>>       (list
>>        :GOLD-location
>>        (point))))))
>>
>>   [Q] Are there any defects in this method of passing struct and what
>>   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.  Improvements, likewise, depend on intention and pov.
>>
>>       Specifically, are there ways to reduce verbosity without using cl
>>   or staying purely in elisp ?
>>
>> You can use shorter variable names.  You can make your program
>> less piecewise-constructive and more table-oriented.
>>
>>   [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))
>>
>
> OK lets take the suggestion below and show me how it works with my case ?
>
>> You need the ‘car’ because you do ‘(list k v)’.
>> If you use ‘(cons k v)’, then you do not need the ‘car’.
>
> 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 !!!

Here is a sexp to play with ready in hand ... so show me how to do it ?

(assoc-default 'y '((w 0) (x 1) (y 2) (z 3)))


>>
>>   [Q] Is there a way to using plists for return from find-my-marker-GOLD
>>       and utilize in the user function test-GOLD
>>
>> Yes, but probably you will want to avoid plists.
>>
>



reply via email to

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