* How to remove verbosity from the data passing mechanism using alist or plist ?
@ 2010-12-05 20:15 Fren Zeee
2010-12-06 14:13 ` Thien-Thi Nguyen
0 siblings, 1 reply; 39+ messages in thread
From: Fren Zeee @ 2010-12-05 20:15 UTC (permalink / raw)
To: Emacs Dev [emacs-devel]
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
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-05 20:15 How to remove verbosity from the data passing mechanism using alist or plist ? Fren Zeee
@ 2010-12-06 14:13 ` Thien-Thi Nguyen
2010-12-06 15:41 ` Fren Zeee
` (2 more replies)
0 siblings, 3 replies; 39+ messages in thread
From: Thien-Thi Nguyen @ 2010-12-06 14:13 UTC (permalink / raw)
To: Fren Zeee; +Cc: help-gnu-emacs
[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.
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-06 14:13 ` Thien-Thi Nguyen
@ 2010-12-06 15:41 ` Fren Zeee
2010-12-07 14:18 ` Thien-Thi Nguyen
2010-12-06 19:45 ` Fren Zeee
2010-12-08 1:26 ` Fren Zeee
2 siblings, 1 reply; 39+ messages in thread
From: Fren Zeee @ 2010-12-06 15:41 UTC (permalink / raw)
To: Thien-Thi Nguyen; +Cc: help-gnu-emacs
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.
Excellent point.
>
> 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.
I would certainly need a toy example or even ask for taking this
example and showing me how to do it. I am not familiar with this
table-oriented approach.
> [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’.
Good point
>
> [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.
>
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-06 15:41 ` Fren Zeee
@ 2010-12-07 14:18 ` Thien-Thi Nguyen
2010-12-07 17:10 ` Fren Zeee
0 siblings, 1 reply; 39+ messages in thread
From: Thien-Thi Nguyen @ 2010-12-07 14:18 UTC (permalink / raw)
To: Fren Zeee; +Cc: help-gnu-emacs
() Fren Zeee <frenzeee@gmail.com>
() Mon, 6 Dec 2010 07:41:21 -0800
> less piecewise-constructive and more table-oriented.
I would certainly need a toy example or even ask for taking this
example and showing me how to do it. I am not familiar with this
table-oriented approach.
I would rather help you understand those words than show you how to
apply them. (This is more work for both of us, initially, but less
work in the long run.) What do you think of when you read them?
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-07 14:18 ` Thien-Thi Nguyen
@ 2010-12-07 17:10 ` Fren Zeee
0 siblings, 0 replies; 39+ messages in thread
From: Fren Zeee @ 2010-12-07 17:10 UTC (permalink / raw)
To: Thien-Thi Nguyen; +Cc: help-gnu-emacs
On Tue, Dec 7, 2010 at 6:18 AM, Thien-Thi Nguyen <ttn@gnuvola.org> wrote:
> () Fren Zeee <frenzeee@gmail.com>
> () Mon, 6 Dec 2010 07:41:21 -0800
>
> > less piecewise-constructive and more table-oriented.
>
> I would certainly need a toy example or even ask for taking this
> example and showing me how to do it. I am not familiar with this
> table-oriented approach.
>
> I would rather help you understand those words than show you how to
> apply them. (This is more work for both of us, initially, but less
> work in the long run.) What do you think of when you read them?
>
I need an example. These are abstract concepts and can be
conceptualized erroenously easily with resulting miscommunication.
Just give a concrete example of the beast. and show what you meant by
these terms.
which table do you mean ? symbol table, call table, ?
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-06 14:13 ` Thien-Thi Nguyen
2010-12-06 15:41 ` Fren Zeee
@ 2010-12-06 19:45 ` Fren Zeee
2010-12-06 19:46 ` Fren Zeee
` (2 more replies)
2010-12-08 1:26 ` Fren Zeee
2 siblings, 3 replies; 39+ messages in thread
From: Fren Zeee @ 2010-12-06 19:45 UTC (permalink / raw)
To: Thien-Thi Nguyen; +Cc: help-gnu-emacs
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 !!!
>
> [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.
>
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-06 19:45 ` Fren Zeee
@ 2010-12-06 19:46 ` Fren Zeee
2010-12-07 6:18 ` Fwd: " Fren Zeee
2010-12-07 14:09 ` Thien-Thi Nguyen
2 siblings, 0 replies; 39+ messages in thread
From: Fren Zeee @ 2010-12-06 19:46 UTC (permalink / raw)
To: Thien-Thi Nguyen; +Cc: help-gnu-emacs
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.
>>
>
^ permalink raw reply [flat|nested] 39+ messages in thread
* Fwd: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-06 19:45 ` Fren Zeee
2010-12-06 19:46 ` Fren Zeee
@ 2010-12-07 6:18 ` Fren Zeee
2010-12-07 7:59 ` PJ Weisberg
2010-12-07 17:14 ` Fwd: " Stefan Monnier
2010-12-07 14:09 ` Thien-Thi Nguyen
2 siblings, 2 replies; 39+ messages in thread
From: Fren Zeee @ 2010-12-07 6:18 UTC (permalink / raw)
To: Emacs Dev [emacs-devel]
There was no reply from the help mailing list and this is very
confusing so I am forced to go back where the crowd is. Its a very
simple issue of cons versus list below.
---------- Forwarded message ----------
From: Fren Zeee <frenzeee@gmail.com>
Date: Mon, Dec 6, 2010 at 11:45 AM
Subject: Re: How to remove verbosity from the data passing mechanism
using alist or plist ?
To: Thien-Thi Nguyen <ttn@gnuvola.org>
Cc: help-gnu-emacs@gnu.org
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 !!!
>
> [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.
>
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-07 6:18 ` Fwd: " Fren Zeee
@ 2010-12-07 7:59 ` PJ Weisberg
2010-12-07 15:14 ` Drew Adams
2010-12-07 17:14 ` Fwd: " Stefan Monnier
1 sibling, 1 reply; 39+ messages in thread
From: PJ Weisberg @ 2010-12-07 7:59 UTC (permalink / raw)
To: help-gnu-emacs
On Mon, Dec 6, 2010 at 10:18 PM, Fren Zeee <frenzeee@gmail.com> wrote:
>> [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 !!!
Don't put the car anywhere. Change that to (list (cons k1 v1) (cons
k2 v2)) and then use use (assoc-default k1 myList), (assoc-default k2
myList), etc.
With that sexp you gave earlier,
(assoc-default 'y '((w . 0) (x . 1) (y . 2) (z . 3)))
Now it returns 2 instead of (2), so if you wanted the number you don't
need car to get it.
I think you were asking the difference between cons and list, and I
was going to write some kind of explanation, but apparently the part
of my brain that's capable of explaining things clearly has already
gone to sleep, so before I turn in I'll just say that lisp uses linked
lists with one "cons cell" for each item in the list, and those things
that look like lists but have dots in them are a result of someone
abusing "cons" to make a cons cell whose 'next' pointer points to
something other than the next cons cell in a list.
^ permalink raw reply [flat|nested] 39+ messages in thread
* RE: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-07 7:59 ` PJ Weisberg
@ 2010-12-07 15:14 ` Drew Adams
2010-12-07 16:55 ` PJ Weisberg
0 siblings, 1 reply; 39+ messages in thread
From: Drew Adams @ 2010-12-07 15:14 UTC (permalink / raw)
To: 'PJ Weisberg', 'help-gnu-emacs'
> those things that look like lists but have dots in them are
> a result of someone abusing "cons" to make a cons cell whose
> 'next' pointer points to something other than the next cons
> cell in a list.
Actually this is not an abuse of poor little `cons'. ;-)
The list `(x)' is in fact an example of such "abusive" behavior: the cdr
("next") is the symbol `nil', which is an atom, not a cons cell: `(x . nil)'.
It is correct to say that cons cells are used to build lists, and that that is
their most common use. And that a list is either `nil' or a cons cell whose cdr
is a list. But it is also correct that some cons cells are not lists, i.e., do
not have a list as their cdr.
`cons' is untyped wrt its parameters. It is not only the first parameter (the
car) that need not be a list, but also the second (the cdr).
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-07 15:14 ` Drew Adams
@ 2010-12-07 16:55 ` PJ Weisberg
0 siblings, 0 replies; 39+ messages in thread
From: PJ Weisberg @ 2010-12-07 16:55 UTC (permalink / raw)
To: help-gnu-emacs
On Tue, Dec 7, 2010 at 7:14 AM, Drew Adams <drew.adams@oracle.com> wrote:
>> those things that look like lists but have dots in them are
>> a result of someone abusing "cons" to make a cons cell whose
>> 'next' pointer points to something other than the next cons
>> cell in a list.
>
> Actually this is not an abuse of poor little `cons'. ;-)
>
> The list `(x)' is in fact an example of such "abusive" behavior: the cdr
> ("next") is the symbol `nil', which is an atom, not a cons cell: `(x . nil)'.
>
> It is correct to say that cons cells are used to build lists, and that that is
> their most common use. And that a list is either `nil' or a cons cell whose cdr
> is a list. But it is also correct that some cons cells are not lists, i.e., do
> not have a list as their cdr.
>
> `cons' is untyped wrt its parameters. It is not only the first parameter (the
> car) that need not be a list, but also the second (the cdr).
Yeah, I hesitated to use 'abuse' there, but I was tired and decided to
opt for the more colorful language. :-)
The first thing I think of when I think of cons is a trivial example
from a college class, like "(cons 1 (cons 2 (cons 3 nil)))" to make a
3-item list. So I usually think of cons as a way to add something to
the front of a list (nil being the same thing as an empty list).
Basically, 'list' and 'cons' both return a cons cell. With 'cons',
the car of the cons cell is the first argument and the cdr is the
second argument. With 'list', the car is the first argument and the
cdr is another cons cell, whose car is the second argument and whose
cdr is another cons cell, and so on until you get to a cons cell whose
car is the last argument and whose cdr is nil.
I was trying to come up with an example to show how 'list' was like a
bunch of 'cons's, but the part of my brain that can do recursion was
in sleep mode, and then the best I came up with was
(defun my-list( &rest args )
(if args
(cons (car args) (eval (cons 'my-list (cdr args))))
nil))
and I didn't think was was clarifying *anything* if I had to use eval
to while I was explaining cons. ;-)
P.S.: For the benefit of lisp beginners who don't know, if args is
'(1 2 3 4), then (cdr args) is '(2 3 4), and (cons 'my-list '(2 3 4))
is '(my-list 2 3 4). Doesn't that look like a function call? eval
treats it as such.
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Fwd: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-07 6:18 ` Fwd: " Fren Zeee
2010-12-07 7:59 ` PJ Weisberg
@ 2010-12-07 17:14 ` Stefan Monnier
2010-12-07 21:24 ` Fren Zeee
1 sibling, 1 reply; 39+ messages in thread
From: Stefan Monnier @ 2010-12-07 17:14 UTC (permalink / raw)
To: Fren Zeee; +Cc: Emacs Dev [emacs-devel]
> There was no reply from the help mailing list and this is very
That's because the question is completely incomprehensible. When you
ask a question, always assume your readers are dimwits, and explain
every detail of what you're trying to do, rather than just spitting what
you're doing and assume people will understand.
Stefan
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Fwd: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-07 17:14 ` Fwd: " Stefan Monnier
@ 2010-12-07 21:24 ` Fren Zeee
2010-12-07 21:27 ` Fwd: " Fren Zeee
` (2 more replies)
0 siblings, 3 replies; 39+ messages in thread
From: Fren Zeee @ 2010-12-07 21:24 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Emacs Dev [emacs-devel]
On Tue, Dec 7, 2010 at 9:14 AM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> There was no reply from the help mailing list and this is very
>
> That's because the question is completely incomprehensible. When you
> ask a question, always assume your readers are dimwits, and explain
> every detail of what you're trying to do, rather than just spitting what
> you're doing and assume people will understand.
>
>
> Stefan
>
flame bait ignored :))))
The question is VERY CLEAR !!! and SPECIFIC at the LAST STAGE !!!
==============================================================
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 !!!
==============================================================
^ permalink raw reply [flat|nested] 39+ messages in thread
* Fwd: Fwd: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-07 21:24 ` Fren Zeee
@ 2010-12-07 21:27 ` Fren Zeee
2010-12-07 21:48 ` Chad Brown
2010-12-09 4:31 ` Fwd: " Stefan Monnier
2 siblings, 0 replies; 39+ messages in thread
From: Fren Zeee @ 2010-12-07 21:27 UTC (permalink / raw)
To: help-gnu-emacs
also forwarded to gnu.emacs.help via the mailing list <help-gnu-emacs@gnu.org>,
---------- Forwarded message ----------
From: Fren Zeee <frenzeee@gmail.com>
Date: Tue, Dec 7, 2010 at 1:24 PM
Subject: Re: Fwd: How to remove verbosity from the data passing
mechanism using alist or plist ?
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: "Emacs Dev [emacs-devel]" <emacs-devel@gnu.org>
On Tue, Dec 7, 2010 at 9:14 AM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> There was no reply from the help mailing list and this is very
>
> That's because the question is completely incomprehensible. When you
> ask a question, always assume your readers are dimwits, and explain
> every detail of what you're trying to do, rather than just spitting what
> you're doing and assume people will understand.
>
>
> Stefan
>
flame bait ignored :))))
The question is VERY CLEAR !!! and SPECIFIC at the LAST STAGE !!!
==============================================================
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 !!!
==============================================================
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-07 21:24 ` Fren Zeee
2010-12-07 21:27 ` Fwd: " Fren Zeee
@ 2010-12-07 21:48 ` Chad Brown
2010-12-07 23:08 ` Fren Zeee
2010-12-09 4:31 ` Fwd: " Stefan Monnier
2 siblings, 1 reply; 39+ messages in thread
From: Chad Brown @ 2010-12-07 21:48 UTC (permalink / raw)
To: Fren Zeee; +Cc: Emacs Dev [emacs-devel]
On Dec 7, 2010, at 1:24 PM, Fren Zeee wrote:
> The question is VERY CLEAR !!! and SPECIFIC at the LAST STAGE !!!
Even with the CAPITAL LETTERS and the TRIPLE EXCLAMATION
POINTS!!!, I still have no idea what you're trying to accomplish.
Perhaps you would be helped by evaluating both of these in emacs:
(pp (list 1 2))
(pp (cons 1 2))
or perhaps:
(pp (list (list 1 2) (list 3 4)))
(pp (list (cons 1 2) (cons 3 4) (cons 5 6)))
I say `perhaps', because I don't really know what you're trying to
accomplish.
I hope that helps,
*Chad
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-07 21:48 ` Chad Brown
@ 2010-12-07 23:08 ` Fren Zeee
2010-12-07 23:19 ` Fren Zeee
2010-12-08 4:59 ` PJ Weisberg
0 siblings, 2 replies; 39+ messages in thread
From: Fren Zeee @ 2010-12-07 23:08 UTC (permalink / raw)
To: Chad Brown; +Cc: Emacs Dev [emacs-devel]
On Tue, Dec 7, 2010 at 1:48 PM, Chad Brown <yandros@mit.edu> wrote:
> On Dec 7, 2010, at 1:24 PM, Fren Zeee wrote:
>
>> The question is VERY CLEAR !!! and SPECIFIC at the LAST STAGE !!!
>
> Even with the CAPITAL LETTERS and the TRIPLE EXCLAMATION
> POINTS!!!, I still have no idea what you're trying to accomplish.
>
> Perhaps you would be helped by evaluating both of these in emacs:
>
> (pp (list 1 2))
> (pp (cons 1 2))
>
> or perhaps:
>
> (pp (list (list 1 2) (list 3 4)))
> (pp (list (cons 1 2) (cons 3 4) (cons 5 6)))
>
> I say `perhaps', because I don't really know what you're trying to accomplish.
Its in the title
How to remove verbosity from the data passing mechanism using alist or plist ?
> I hope that helps,
> *Chad
Yes it helped, but I cant honestly see the difference between
(a . b) <--- from cons
and
(a b) <--- from list
both seem to be dotted pair although the dot is implicit in the second.
We are getting to the heart of the thing, ie concept, although the
problem is solved in that I have the answer
(assoc-default 1 (list (list 1 2) (list 3 4) (list 5 6)))
------> (2) so I need xtra car verbose
(assoc-default 1 (list (cons 1 2) (cons 3 4) (cons 5 6))) ------>
2 so I dont need xtra car
Mercifully, the earlier flame-bait was ignored.
Thanks Chad.
P.S.
Now, lets see if you or someone can look at other points mentioned by
Thien to remove the verbosity such as below or Thien's first reply of
Dec 6.
() Fren Zeee <frenzeee@gmail.com>
() Mon, 6 Dec 2010 07:41:21 -0800
> less piecewise-constructive and more table-oriented.
I would certainly need a toy example or even ask for taking this
example and showing me how to do it. I am not familiar with this
table-oriented approach.
I would rather help you understand those words than show you how to
apply them. (This is more work for both of us, initially, but less
work in the long run.) What do you think of when you read them?
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-07 23:08 ` Fren Zeee
@ 2010-12-07 23:19 ` Fren Zeee
2010-12-08 16:39 ` Chong Yidong
2010-12-08 4:59 ` PJ Weisberg
1 sibling, 1 reply; 39+ messages in thread
From: Fren Zeee @ 2010-12-07 23:19 UTC (permalink / raw)
To: Chad Brown; +Cc: Emacs Dev [emacs-devel]
Let me sharpen my question on the conceptual issue. Note, the original
question has split into several ways and we are just on this one for
now in this reply of mine.
What's the meaning of (cons 1 2) versus (list 1 2) ?
cons expects the second argument to be a list and inserts the first into it.
Thus (cons 1 2) did not make sense to me. Perhaps, after a few years I
have forgotten or dulled in my concepts.
(list 1 2) <=> (cons 1 (cons 2 () ))
Anyway, I can move forward with this unless you or anyone has
something enlightening to add and someone does come and start telling
me I need to go and take a class in lisp.
We can move to the
-----------------> less piecewise-constructive and more
table-oriented. <-------------------
Franz Xe
>
> Yes it helped, but I cant honestly see the difference between
> (a . b) <--- from cons
> and
> (a b) <--- from list
>
> both seem to be dotted pair although the dot is implicit in the second.
>
> We are getting to the heart of the thing, ie concept, although the
> problem is solved in that I have the answer
>
>
> (assoc-default 1 (list (list 1 2) (list 3 4) (list 5 6)))
> ------> (2) so I need xtra car verbose
> (assoc-default 1 (list (cons 1 2) (cons 3 4) (cons 5 6))) ------>
> 2 so I dont need xtra car
>
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-07 23:19 ` Fren Zeee
@ 2010-12-08 16:39 ` Chong Yidong
2010-12-09 2:30 ` Fren Zeee
0 siblings, 1 reply; 39+ messages in thread
From: Chong Yidong @ 2010-12-08 16:39 UTC (permalink / raw)
To: Fren Zeee; +Cc: Chad Brown, Emacs Dev [emacs-devel]
Fren Zeee <frenzeee@gmail.com> writes:
> cons expects the second argument to be a list
No it doesn't.
Please refer to An Introduction to Programming in Emacs Lisp, Chapter 7,
"car, cdr, cons: Fundamental Functions".
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-08 16:39 ` Chong Yidong
@ 2010-12-09 2:30 ` Fren Zeee
0 siblings, 0 replies; 39+ messages in thread
From: Fren Zeee @ 2010-12-09 2:30 UTC (permalink / raw)
To: Chong Yidong; +Cc: Chad Brown, Emacs Dev [emacs-devel]
[-- Attachment #1: Type: text/plain, Size: 1717 bytes --]
On Wed, Dec 8, 2010 at 8:39 AM, Chong Yidong <cyd@stupidchicken.com> wrote:
> Fren Zeee <frenzeee@gmail.com> writes:
>
>> cons expects the second argument to be a list
>
> No it doesn't.
>
> Please refer to An Introduction to Programming in Emacs Lisp, Chapter 7,
> "car, cdr, cons: Fundamental Functions".
>
Thanks a lot !
You can now see that I have read the link and highlighting shows I have
understood the point. Now, lets get moving with the rest of the ideas of
Thien-Thi .
http://www.gnu.org/software/emacs/emacs-lisp-intro/html_mono/emacs-lisp-intro.html#cons
(cons 'pine '(fir oak maple))
After evaluating this list, you will see
(pine fir oak maple)
appear in the echo area. cons causes the creation of a new list in which the
element is followed by the elements of the original list.
We often say that `cons puts a new element at the beginning of a list; it
attaches or pushes elements onto the list', but this phrasing can be
misleading, since cons does not change an existing list, but creates a new
one.
Build a list
cons must have a list to attach to.9 You cannot start from absolutely
nothing. If you are building a list, you need to provide at least an empty
list at the beginning. Here is a series of cons expressions that build up a
list of flowers. If you are reading this in Info in GNU Emacs, you can
evaluate each of the expressions in the usual way; the value is printed in
this text after '=>', which you may read as `evaluates to'.
(cons 'buttercup ())
=> (buttercup)
(cons 'daisy '(buttercup))
=> (daisy buttercup)
The second example, (cons 'daisy '(buttercup)) constructs a new, two
element list by putting daisy in front of buttercup;
[-- Attachment #2: Type: text/html, Size: 2992 bytes --]
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-07 23:08 ` Fren Zeee
2010-12-07 23:19 ` Fren Zeee
@ 2010-12-08 4:59 ` PJ Weisberg
1 sibling, 0 replies; 39+ messages in thread
From: PJ Weisberg @ 2010-12-08 4:59 UTC (permalink / raw)
To: help-gnu-emacs
On 12/7/10, Fren Zeee <frenzeee@gmail.com> wrote:
> Yes it helped, but I cant honestly see the difference between
> (a . b) <--- from cons
> and
> (a b) <--- from list
>
> both seem to be dotted pair although the dot is implicit in the second.
No. The first is a dotted pair. The second is a list. I guess you
*could* say a dot was implicit, but the "explicit" version would be
(a . (b . nil))
-PJ
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Fwd: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-07 21:24 ` Fren Zeee
2010-12-07 21:27 ` Fwd: " Fren Zeee
2010-12-07 21:48 ` Chad Brown
@ 2010-12-09 4:31 ` Stefan Monnier
2010-12-09 20:33 ` Fren Zeee
2 siblings, 1 reply; 39+ messages in thread
From: Stefan Monnier @ 2010-12-09 4:31 UTC (permalink / raw)
To: Fren Zeee; +Cc: Emacs Dev [emacs-devel]
> The question is VERY CLEAR !!! and SPECIFIC at the LAST STAGE !!!
Great, I'm glad you're satisfied with the answers you got,
Stefan
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Fwd: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-09 4:31 ` Fwd: " Stefan Monnier
@ 2010-12-09 20:33 ` Fren Zeee
2010-12-10 6:59 ` PJ Weisberg
0 siblings, 1 reply; 39+ messages in thread
From: Fren Zeee @ 2010-12-09 20:33 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Emacs Dev [emacs-devel]
[-- Attachment #1: Type: text/plain, Size: 490 bytes --]
I am only satisfied with first part. There are more challenging questions
still there. Please read the two or three of my posts before you entered the
conversation.
I am not satisfied with the slow pace however, so kindly look at it.
Cheers :)))
Franz
On Wed, Dec 8, 2010 at 8:31 PM, Stefan Monnier <monnier@iro.umontreal.ca>wrote:
> > The question is VERY CLEAR !!! and SPECIFIC at the LAST STAGE !!!
>
> Great, I'm glad you're satisfied with the answers you got,
>
>
> Stefan
>
[-- Attachment #2: Type: text/html, Size: 889 bytes --]
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Fwd: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-09 20:33 ` Fren Zeee
@ 2010-12-10 6:59 ` PJ Weisberg
2010-12-10 7:18 ` joakim
2010-12-10 17:50 ` Fren Zeee
0 siblings, 2 replies; 39+ messages in thread
From: PJ Weisberg @ 2010-12-10 6:59 UTC (permalink / raw)
To: Emacs Dev [emacs-devel]
On Thu, Dec 9, 2010 at 12:33 PM, Fren Zeee <frenzeee@gmail.com> wrote:
> I am only satisfied with first part. There are more challenging questions
> still there. Please read the two or three of my posts before you entered the
> conversation.
I think your other question was, "What was Thien-Thi talking about
when he said 'less piecewise-constructive and more table-oriented'?
Here's my guess. Keeping in mind that I have no idea what you're
trying to accomplish, I would suggest that instead of having functions
like find-my-marker-GOLD, find-my-marker-SILVER, and the like, you
just start out the file with something like:
GOLD 1000
SILVER 5000
COPPER 28000
CHEESEBURGERS 2
END
And then read those line-by-line to construct your alist or whatever.
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Fwd: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-10 6:59 ` PJ Weisberg
@ 2010-12-10 7:18 ` joakim
2010-12-10 17:51 ` Fren Zeee
2010-12-10 17:50 ` Fren Zeee
1 sibling, 1 reply; 39+ messages in thread
From: joakim @ 2010-12-10 7:18 UTC (permalink / raw)
To: PJ Weisberg; +Cc: Emacs Dev [emacs-devel]
PJ Weisberg <pj@irregularexpressions.net> writes:
> On Thu, Dec 9, 2010 at 12:33 PM, Fren Zeee <frenzeee@gmail.com> wrote:
>> I am only satisfied with first part. There are more challenging questions
>> still there. Please read the two or three of my posts before you entered the
>> conversation.
>
> I think your other question was, "What was Thien-Thi talking about
> when he said 'less piecewise-constructive and more table-oriented'?
>
> Here's my guess. Keeping in mind that I have no idea what you're
> trying to accomplish, I would suggest that instead of having functions
> like find-my-marker-GOLD, find-my-marker-SILVER, and the like, you
> just start out the file with something like:
>
> GOLD 1000
> SILVER 5000
> COPPER 28000
> CHEESEBURGERS 2
> END
>
> And then read those line-by-line to construct your alist or whatever.
I also fail to comprehend what this thread is about, but could this
maybe prove useful?
http://en.wikipedia.org/wiki/Homoiconicity
Lisp data and code look alike. The lisp data structure is convenient at
every level of the language. Lisp as a dataformat on disk is thus also
convenient.
--
Joakim Verona
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Fwd: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-10 7:18 ` joakim
@ 2010-12-10 17:51 ` Fren Zeee
0 siblings, 0 replies; 39+ messages in thread
From: Fren Zeee @ 2010-12-10 17:51 UTC (permalink / raw)
To: joakim; +Cc: PJ Weisberg, Emacs Dev [emacs-devel]
[-- Attachment #1: Type: text/plain, Size: 1483 bytes --]
Thien-Thi was on the right track and understood the problem well as his
reply indicate as far as I understood it. He has disappeared or refusing to
show up. probably this nourishes the ego of such geeks.
On Thu, Dec 9, 2010 at 11:18 PM, <joakim@verona.se> wrote:
> PJ Weisberg <pj@irregularexpressions.net> writes:
>
> > On Thu, Dec 9, 2010 at 12:33 PM, Fren Zeee <frenzeee@gmail.com> wrote:
> >> I am only satisfied with first part. There are more challenging
> questions
> >> still there. Please read the two or three of my posts before you entered
> the
> >> conversation.
> >
> > I think your other question was, "What was Thien-Thi talking about
> > when he said 'less piecewise-constructive and more table-oriented'?
> >
> > Here's my guess. Keeping in mind that I have no idea what you're
> > trying to accomplish, I would suggest that instead of having functions
> > like find-my-marker-GOLD, find-my-marker-SILVER, and the like, you
> > just start out the file with something like:
> >
> > GOLD 1000
> > SILVER 5000
> > COPPER 28000
> > CHEESEBURGERS 2
> > END
> >
> > And then read those line-by-line to construct your alist or whatever.
>
> I also fail to comprehend what this thread is about, but could this
> maybe prove useful?
>
> http://en.wikipedia.org/wiki/Homoiconicity
>
> Lisp data and code look alike. The lisp data structure is convenient at
> every level of the language. Lisp as a dataformat on disk is thus also
> convenient.
>
> --
> Joakim Verona
>
>
[-- Attachment #2: Type: text/html, Size: 2115 bytes --]
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Fwd: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-10 6:59 ` PJ Weisberg
2010-12-10 7:18 ` joakim
@ 2010-12-10 17:50 ` Fren Zeee
[not found] ` <87lj3xrqz1.fsf@uwakimon.sk.tsukuba.ac.jp>
1 sibling, 1 reply; 39+ messages in thread
From: Fren Zeee @ 2010-12-10 17:50 UTC (permalink / raw)
To: PJ Weisberg; +Cc: Emacs Dev [emacs-devel]
[-- Attachment #1: Type: text/plain, Size: 1084 bytes --]
Thien-Thi was on the right track and understood the problem well as his
reply indicate as far as I understood it. He has disappeared or refusing to
show up. probably this nourishes the ego of such geeks.
On Thu, Dec 9, 2010 at 10:59 PM, PJ Weisberg <pj@irregularexpressions.net>wrote:
> On Thu, Dec 9, 2010 at 12:33 PM, Fren Zeee <frenzeee@gmail.com> wrote:
> > I am only satisfied with first part. There are more challenging questions
> > still there. Please read the two or three of my posts before you entered
> the
> > conversation.
>
> I think your other question was, "What was Thien-Thi talking about
> when he said 'less piecewise-constructive and more table-oriented'?
>
> Here's my guess. Keeping in mind that I have no idea what you're
> trying to accomplish, I would suggest that instead of having functions
> like find-my-marker-GOLD, find-my-marker-SILVER, and the like, you
> just start out the file with something like:
>
> GOLD 1000
> SILVER 5000
> COPPER 28000
> CHEESEBURGERS 2
> END
>
> And then read those line-by-line to construct your alist or whatever.
>
>
[-- Attachment #2: Type: text/html, Size: 1467 bytes --]
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-06 19:45 ` Fren Zeee
2010-12-06 19:46 ` Fren Zeee
2010-12-07 6:18 ` Fwd: " Fren Zeee
@ 2010-12-07 14:09 ` Thien-Thi Nguyen
2010-12-07 17:11 ` Fren Zeee
2 siblings, 1 reply; 39+ messages in thread
From: Thien-Thi Nguyen @ 2010-12-07 14:09 UTC (permalink / raw)
To: Fren Zeee; +Cc: help-gnu-emacs
() Fren Zeee <frenzeee@gmail.com>
() Mon, 6 Dec 2010 11:45:17 -0800
kindly show me where I put the car [...]
If i include an attachment in this response, you must extract it.
However, if i inline the same information, you can read it directly.
attachment -> extraction :: list -> car
inline :: cons
This is also known as "putting the ‘car’ nowhere".
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-07 14:09 ` Thien-Thi Nguyen
@ 2010-12-07 17:11 ` Fren Zeee
2010-12-07 21:10 ` PJ Weisberg
0 siblings, 1 reply; 39+ messages in thread
From: Fren Zeee @ 2010-12-07 17:11 UTC (permalink / raw)
To: Thien-Thi Nguyen; +Cc: help-gnu-emacs
On Tue, Dec 7, 2010 at 6:09 AM, Thien-Thi Nguyen <ttn@gnuvola.org> wrote:
> () Fren Zeee <frenzeee@gmail.com>
> () Mon, 6 Dec 2010 11:45:17 -0800
>
> kindly show me where I put the car [...]
>
> If i include an attachment in this response, you must extract it.
> However, if i inline the same information, you can read it directly.
>
> attachment -> extraction :: list -> car
> inline :: cons
>
> This is also known as "putting the ‘car’ nowhere".
>
Sorry, I did not understand it at all. It flew over my head. If this
is a subtle concept, I ask you to explain it with greater detail and
in smaller steps.
Franz
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-07 17:11 ` Fren Zeee
@ 2010-12-07 21:10 ` PJ Weisberg
0 siblings, 0 replies; 39+ messages in thread
From: PJ Weisberg @ 2010-12-07 21:10 UTC (permalink / raw)
Cc: help-gnu-emacs
On 12/7/10, Fren Zeee <frenzeee@gmail.com> wrote:
> Sorry, I did not understand it at all. It flew over my head. If this
> is a subtle concept, I ask you to explain it with greater detail and
> in smaller steps.
I think he said the same thing I said, except he used a metaphore.
;-) I.e., you don't need a car at all if you don't wrap the value in
a list to begin with.
-PJ
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: How to remove verbosity from the data passing mechanism using alist or plist ?
2010-12-06 14:13 ` Thien-Thi Nguyen
2010-12-06 15:41 ` Fren Zeee
2010-12-06 19:45 ` Fren Zeee
@ 2010-12-08 1:26 ` Fren Zeee
2 siblings, 0 replies; 39+ messages in thread
From: Fren Zeee @ 2010-12-08 1:26 UTC (permalink / raw)
To: Thien-Thi Nguyen; +Cc: help-gnu-emacs
> 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.
>
Thien-Thi Nguyen
You mean
less piece meal construction (step by step construction)
and
more table driven , like some kind of FSM ? from state to state ?
Franz
^ permalink raw reply [flat|nested] 39+ messages in thread
[parent not found: <dd1e2214-a914-45ea-a665-fead1ad2928b@39g2000yqa.googlegroups.com>]
* How to remove verbosity from the data passing mechanism using alist or plist ?
[not found] <dd1e2214-a914-45ea-a665-fead1ad2928b@39g2000yqa.googlegroups.com>
@ 2010-12-06 5:09 ` Fren Zeee
0 siblings, 0 replies; 39+ messages in thread
From: Fren Zeee @ 2010-12-06 5:09 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 39+ messages in thread
end of thread, other threads:[~2010-12-14 1:20 UTC | newest]
Thread overview: 39+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-05 20:15 How to remove verbosity from the data passing mechanism using alist or plist ? Fren Zeee
2010-12-06 14:13 ` Thien-Thi Nguyen
2010-12-06 15:41 ` 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
2010-12-07 6:18 ` Fwd: " Fren Zeee
2010-12-07 7:59 ` PJ Weisberg
2010-12-07 15:14 ` Drew Adams
2010-12-07 16:55 ` PJ Weisberg
2010-12-07 17:14 ` Fwd: " Stefan Monnier
2010-12-07 21:24 ` Fren Zeee
2010-12-07 21:27 ` Fwd: " Fren Zeee
2010-12-07 21:48 ` Chad Brown
2010-12-07 23:08 ` Fren Zeee
2010-12-07 23:19 ` Fren Zeee
2010-12-08 16:39 ` Chong Yidong
2010-12-09 2:30 ` Fren Zeee
2010-12-08 4:59 ` PJ Weisberg
2010-12-09 4:31 ` Fwd: " Stefan Monnier
2010-12-09 20:33 ` Fren Zeee
2010-12-10 6:59 ` PJ Weisberg
2010-12-10 7:18 ` joakim
2010-12-10 17:51 ` Fren Zeee
2010-12-10 17:50 ` Fren Zeee
[not found] ` <87lj3xrqz1.fsf@uwakimon.sk.tsukuba.ac.jp>
2010-12-12 20:55 ` 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:28 ` Jay Belanger
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
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.