From: Thien-Thi Nguyen <ttn@gnuvola.org>
To: Fren Zeee <frenzeee@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How to remove verbosity from the data passing mechanism using alist or plist ?
Date: Mon, 06 Dec 2010 15:13:49 +0100 [thread overview]
Message-ID: <87lj43at0i.fsf@ambire.localdomain> (raw)
In-Reply-To: <AANLkTinwFG_MNXaY5GYXLMtjPEWWH2Y_8yUY8raj4Hoq@mail.gmail.com> (Fren Zeee's message of "Sun, 5 Dec 2010 12:15:08 -0800")
[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))
You need the ‘car’ because you do ‘(list k v)’.
If you use ‘(cons k v)’, then you do not need the ‘car’.
[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.
next parent reply other threads:[~2010-12-06 14:13 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <AANLkTinwFG_MNXaY5GYXLMtjPEWWH2Y_8yUY8raj4Hoq@mail.gmail.com>
2010-12-06 14:13 ` Thien-Thi Nguyen [this message]
2010-12-06 15:41 ` How to remove verbosity from the data passing mechanism using alist or plist ? Fren Zeee
2010-12-07 14:18 ` Thien-Thi Nguyen
2010-12-07 17:10 ` Fren Zeee
2010-12-06 19:45 ` Fren Zeee
2010-12-06 19:46 ` Fren Zeee
[not found] ` <AANLkTikMQzfqkw9i08aptR2v+4nGRh9ZQSODQunLrEXR@mail.gmail.com>
2010-12-07 7:59 ` PJ Weisberg
2010-12-07 15:14 ` Drew Adams
2010-12-07 16:55 ` PJ Weisberg
[not found] ` <jwvr5dtfqvh.fsf-monnier+emacs@gnu.org>
[not found] ` <AANLkTinYGcW+qEW+b_jXOexu+O=um1C+MdVn6n5wp8+Q@mail.gmail.com>
2010-12-07 21:27 ` Fwd: Fwd: " Fren Zeee
[not found] ` <CEDF15DC-09E2-4983-8526-9E3A8924B71C@mit.edu>
[not found] ` <AANLkTinMVpNJCmNL66YUBKqKQQyAkmR0fRDVuZS5KPzn@mail.gmail.com>
2010-12-08 4:59 ` PJ Weisberg
[not found] ` <jwvpqtbbm8u.fsf-monnier+emacs@gnu.org>
[not found] ` <AANLkTimC-m-hvqTwmOfmyya3janBQfEm2w4WA-U55Gn9@mail.gmail.com>
[not found] ` <AANLkTin_QtE=UBQ+R4fFZUYk1EGOkBnF3Wxchn-7DHV8@mail.gmail.com>
[not found] ` <AANLkTim7v1_++2TLmfA=y6K+ocvQgtJKO3DMHbH_L=pQ@mail.gmail.com>
[not found] ` <87lj3xrqz1.fsf@uwakimon.sk.tsukuba.ac.jp>
2010-12-12 20:55 ` Fwd: " Fren Zeee
2010-12-13 4:39 ` Miles Bader
2010-12-13 19:57 ` Fren Zeee
2010-12-13 19:58 ` Fren Zeee
2010-12-13 20:45 ` David Kastrup
2010-12-14 0:13 ` Fren Zeee
2010-12-14 1:20 ` Fren Zeee
2010-12-07 14:09 ` Thien-Thi Nguyen
2010-12-07 17:11 ` Fren Zeee
2010-12-07 21:10 ` PJ Weisberg
2010-12-08 1:26 ` Fren Zeee
[not found] <dd1e2214-a914-45ea-a665-fead1ad2928b@39g2000yqa.googlegroups.com>
2010-12-06 5:09 ` Fren Zeee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lj43at0i.fsf@ambire.localdomain \
--to=ttn@gnuvola.org \
--cc=frenzeee@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).