Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

5 views
Skip to first unread message

Fren Zeee

unread,
Dec 5, 2010, 3:22:34 PM12/5/10
to Fren Zeee
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

Fren Zeee

unread,
Dec 5, 2010, 3:28:43 PM12/5/10
to
On Dec 5, 12:22 pm, Fren Zeee <frenz...@gmail.com> wrote:

I have done some homework by taking a look at one code of game.

It uses lots of globals, perhaps all globals on which various
functions operate.

It certainly saves code. However, for other type of problems that I
might want to take up when I start using Common Lisp, I would want to
learn this style without globals.

Pascal J. Bourguignon

unread,
Dec 5, 2010, 4:14:20 PM12/5/10
to
Fren Zeee <fren...@gmail.com> writes:

Indeed. emacs lisp code is of various styles and quality.
IMO, you will find better style in Common Lisp code (apart from really
old CL code), than in emacs lisp, in general.


--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.

Katalin Sinkov

unread,
Dec 5, 2010, 4:25:15 PM12/5/10
to
On Dec 5, 1:14 pm, "Pascal J. Bourguignon" <p...@informatimago.com>
wrote:

> Fren Zeee <frenz...@gmail.com> writes:
> > On Dec 5, 12:22 pm, Fren Zeee <frenz...@gmail.com> wrote:

>
> Indeed.  emacs lisp code is of various styles and quality.
> IMO, you will find better style in Common Lisp code (apart from really
> old CL code), than in emacs lisp, in general.
>

now hopefully proceed with some well cooked and illustrative and
comparative examples for newbies.

cheers

Pascal J. Bourguignon

unread,
Dec 5, 2010, 5:25:13 PM12/5/10
to
Fren Zeee <fren...@gmail.com> writes:

> [Q] Are there any defects in this method of passing struct and what
> improvements are possible ?

You didn't use a structure, you used lists.


> Specifically, are there ways to reduce verbosity without using cl
> or staying purely in elisp ?

There is no such thing as pure elisp, or pure CL.

For elisp, it would be hard to define a core of primitives, since emacs
lisp is rather defined by its implementation, and there are various
versions of it.

For CL you could say that the set of special operators defined by the
standard (and a few mechanisms and primitive functions) are pure CL.

In both cases, most of the language is defined by library functions and
macros. There is no difference in status between a macro or a function
specified in the CL standard (or documented in the emacs lisp reference
manual), and the macros and functions you write yourself, or you get
from a library.


Therefore I would advise you to put (require 'cl) in your ~/.emacs and
don't try to discriminate the added features.


On the other hand, you may want to be aware of the things that are
specific to emacs, such as the buffer, windows, regexp and text
processing operators, which are not available in other lisps.


First, I remark that find-my-marker-GOLD doesn't return either an a-list
or a p-list, but a list of list of two elements. You can of course do
that.

(list
(list :GOLD-value (string-to-number (replace-regexp-in-string "GOLD=\\([0-9]+\\)\n" "\\1" (match-string 0))))
(list :GOLD-location (point)))

However, a-list and p-list are known and benefit from predefined
functional abstraction, which will lead to shorter code:


;; a-list:
(acons :gold-value (treasure-marker-value gold-marker)
(acons :gold-location (treasure-marker-point gold-marker)
'()))

;; p-list:
(list :gold-value (treasure-marker-value gold-marker)
:gold-location (treasure-marker-point gold-marker))

Otherwise, the point is to define and use abstractions. This is the
secret to concise, readable and maintainble code.

- data abstraction, with data structures. (vectors, arrays,
lists, structures, objects, etc).

- functional abstraction, defining functions and anonymous functions,

- syntactic abstraction, using macros to define new control structures,
and to abstract away boilerplate code.

- meta-linguistic abstraction, defining domain-specific languages.


In your case, using data astraction and functional abstraction would be
enough to make it much clearer.


So instead of calling functions such as string-to-number or
replace-regexp-in-string that have nothing to do with gold, we call
(treasure-marker-value gold-marker)
and (treasure-marker-location gold-marker).

Notice that we don't call gold-marker-value, because there's no point in
abstracting away things that are too specific either. It doesn't matter
if our treasure is gold, silver or diamonds!

Of course, we also need a function to create the gold-marker:
(find-treasure "GOLD")

(defstruct treasure-marker ; data abstraction
what location value)

(defun make-treasure-regexp (what)
"Make a regexp to find a WHAT treasure."
(format "%s=\\([0-9]+\\)\n" what))

(defun find-treasure (what)
(save-excursion
(save-match-data
(goto-char (point-min)) ; my bet is that it will be faster
; to search from the start.
(if (re-search-forward (make-treasure-regexp what) nil t)
(make-treasure-marker :what what
:location (match-beginning 0)
:value (string-to-number (match-string 1)))
(error "No %s treasure found." what)))))

So now you can write simply:

(defun find-my-gold-treasure ()


"Starting from anywhere in the file, find my marker GOLD its value and location."
(interactive)

(let ((treasure (find-treasure "GOLD")))
(make-gold-treasure :value (treasure-marker-value treasure)
:location (treasure-marker-location treasure))))


and later use:

(gold-treasure-value treasure)
(gold-treasure-location treasure)


Of course you have to define these functions, make-gold-treasure,
gold-treasure-value, gold-treasure-location. This is what is called
functional abstraction.

> [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))

If you had a real a-list, you wouldn't have to use car.

(assoc-default :key (acons :key 1 '())) --> 1

The usual data types in lisp are not abstract data types, and can be
used at various level of abstraction depending on the functions you
apply to them. You can build a list of list, and then treat them as an
a-list (using assoc or assoc-default). But of course, you have to deal
with the differences yourself. If you want to avoid these difficulties,
you should learn the set of functions working at the same "abstraction"
level, treating the data as the same abstract data type.

So, if you want an a-list, you will use acons, assoc, assoc-default.

If you want a p-list, you will use getf.

If you want a list, you will use endp, list, first, rest, second, third, etc.

If you want a cons cell, (eg. to build a tree, or a structure or
whatever you want), you will use null, cons, car, cdr.

In all cases, we are dealing with cons cells and the symbol nil. But we
don't consider them as the same abstract data type, depending on the
functions with use.

> [Q] Is there a way to using plists for return from find-my-marker-GOLD
> and utilize in the user function test-GOLD

Yes. See above.


> [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.

If you have a look at the sources of emacs, bytecode.c IIRC, you will
find the source for the emacs lisp virtual machine, with the set of
primitive emacs lisp function. Perhaps this is what one could call
"pure elisp".

Of course, the first thing you would do if you had to write "pure
elisp", is to implement a macro system, and implement a library like cl,
so that you can write code easily and productively. That is, given a
bare machine, the first thing you do is give you the abstraction tools
required to be able to climb the abstraction ladder. See above.


> (b) Solution that is clisp and un-restricted.

clisp is a specific implementation of Common Lisp. If you mean Common
Lisp, the correct abreviation is CL.


> (c) and within both of the above, solutions with plist and alist.


Again, I won't do your own learning, I already did it myself!

And in any case, why should we repeat here what is explained perfectly
well in tens of books and tutorials? If you need pointers, you may have
aa look at http://cliki.net/Online%20Tutorial
and http://www.cliki.net/Lisp%20books

> [Q] test-GOLD will actually be a function called find-GOLD-processing-
> plant

Again, what about platinum processing plants and diamond processing
plants? Functions take parameters for a reason...

You may also have fun reading:

http://git.informatimago.com/viewgit/index.php?a=viewblob&p=public/lisp&h=da5a65c9d6f0934d6312ef540b1b79de6be31407&hb=70763ed2f4ea63b2e4c742236aeddac83c911ff7&f=common-lisp/cesarum/dictionary.lisp

Download instructions: http://www.informatimago.com/develop/lisp

Thien-Thi Nguyen

unread,
Dec 6, 2010, 9:13:49 AM12/6/10
to Fren Zeee, help-gn...@gnu.org
[cc changed to help-gnu-emacs -- this does not belong on emacs-devel]

() Fren Zeee <fren...@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.

Fren Zeee

unread,
Dec 6, 2010, 12:09:05 AM12/6/10
to help-gn...@gnu.org

Fren Zeee

unread,
Dec 6, 2010, 10:41:21 AM12/6/10
to Thien-Thi Nguyen, help-gn...@gnu.org
On Mon, Dec 6, 2010 at 6:13 AM, Thien-Thi Nguyen <t...@gnuvola.org> wrote:
> [cc changed to help-gnu-emacs -- this does not belong on emacs-devel]
>
> () Fren Zeee <fren...@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
>

Fren Zeee

unread,
Dec 6, 2010, 2:45:17 PM12/6/10
to Thien-Thi Nguyen, help-gn...@gnu.org
>       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 !!!

Fren Zeee

unread,
Dec 6, 2010, 2:46:37 PM12/6/10
to Thien-Thi Nguyen, help-gn...@gnu.org

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

PJ Weisberg

unread,
Dec 7, 2010, 2:59:31 AM12/7/10
to help-gnu-emacs
On Mon, Dec 6, 2010 at 10:18 PM, Fren Zeee <fren...@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.

Thien-Thi Nguyen

unread,
Dec 7, 2010, 9:09:40 AM12/7/10
to Fren Zeee, help-gn...@gnu.org
() Fren Zeee <fren...@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".

Thien-Thi Nguyen

unread,
Dec 7, 2010, 9:18:27 AM12/7/10
to Fren Zeee, help-gn...@gnu.org
() Fren Zeee <fren...@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?

Drew Adams

unread,
Dec 7, 2010, 10:14:18 AM12/7/10
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).


PJ Weisberg

unread,
Dec 7, 2010, 11:55:41 AM12/7/10
to help-gnu-emacs

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.

Fren Zeee

unread,
Dec 7, 2010, 12:10:30 PM12/7/10
to Thien-Thi Nguyen, help-gn...@gnu.org

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, ?

Fren Zeee

unread,
Dec 7, 2010, 12:11:11 PM12/7/10
to Thien-Thi Nguyen, help-gn...@gnu.org
On Tue, Dec 7, 2010 at 6:09 AM, Thien-Thi Nguyen <t...@gnuvola.org> wrote:
> () Fren Zeee <fren...@gmail.com>

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

PJ Weisberg

unread,
Dec 7, 2010, 4:10:48 PM12/7/10
to help-gn...@gnu.org
On 12/7/10, Fren Zeee <fren...@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

Fren Zeee

unread,
Dec 7, 2010, 4:27:35 PM12/7/10
to help-gn...@gnu.org
also forwarded to gnu.emacs.help via the mailing list <help-gn...@gnu.org>,


---------- Forwarded message ----------
From: Fren Zeee <fren...@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 <mon...@iro.umontreal.ca>
Cc: "Emacs Dev [emacs-devel]" <emacs...@gnu.org>


On Tue, Dec 7, 2010 at 9:14 AM, Stefan Monnier <mon...@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 !!!


==============================================================

Fren Zeee

unread,
Dec 7, 2010, 8:26:47 PM12/7/10
to Thien-Thi Nguyen, help-gn...@gnu.org
>       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

Pascal J. Bourguignon

unread,
Dec 7, 2010, 10:49:05 PM12/7/10
to
PJ Weisberg <p...@irregularexpressions.net> writes:

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

This is completely wrong:

(my-list '(+ 1 1) '(* 2 2) '(- 3 3))
--> ((+ 1 1) 4 0)

(list '(+ 1 1) '(* 2 2) '(- 3 3))
--> ((+ 1 1) (* 2 2) (- 3 3))


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


First, &rest gives a list to the parameter, therefore you should use
list processing functions such as endp, first and rest, not symbol or cons
processing functions such as null, car and cdr, when applying them on
the parameter.

Then, instead if using eval, you should use apply in this case:

(defun my-list (&rest args)
(if (endp args)
'()
(cons (first args) (apply (function my-list) (rest args)))))

or just build a copy of the parameter:

(defun my-list (&rest args)
(let* ((result (cons '() '()))
(tail result))
(dolist (item args (cdr result))
(setf (cdr tail) (cons item nil)
tail (cdr tail)))))

or just:

(defun my-list (&rest args)
(copy-list args))


(my-list '(+ 1 1) '(* 2 2) '(- 3 3))
--> ((+ 1 1) (* 2 2) (- 3 3))

PJ Weisberg

unread,
Dec 7, 2010, 11:59:54 PM12/7/10
to help-gnu-emacs
On 12/7/10, Fren Zeee <fren...@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

Pascal J. Bourguignon

unread,
Dec 8, 2010, 1:20:06 AM12/8/10
to
PJ Weisberg <p...@irregularexpressions.net> writes:

> On 12/7/10, Fren Zeee <fren...@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.


CL-USER> (COM.INFORMATIMAGO.COMMON-LISP.PICTURE.CONS-TO-ASCII:DRAW-LIST '(a . b) :title "(a . b)")
+-------------------+
| (a . b) |
| |
| +---+---+ +---+ |
| | * | * |-->| B | |
| +---+---+ +---+ |
| | |
| v |
| +---+ |
| | A | |
| +---+ |
+-------------------+

CL-USER> (COM.INFORMATIMAGO.COMMON-LISP.PICTURE.CONS-TO-ASCII:DRAW-LIST '(a b) :title "(a b)")
+-----------------------+
| (a b) |
| |
| +---+---+ +---+---+ |
| | * | * |-->| * |NIL| |
| +---+---+ +---+---+ |
| | | |
| v v |
| +---+ +---+ |
| | A | | B | |
| +---+ +---+ |
+-----------------------+

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

Fren Zeee

unread,
Dec 12, 2010, 3:55:12 PM12/12/10
to Stephen J. Turnbull, help-gn...@gnu.org, Emacs Dev [emacs-devel]


On Fri, Dec 10, 2010 at 6:19 PM, Stephen J. Turnbull <ste...@xemacs.org> wrote:
Fren Zeee writes:
 > 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.

You would be best advised to stop trolling.  Everybody on this list
knows how to use a killfile; by now you're in many.

"troll" is a prejudicial terminology, worse than anti-semitism, anti-gypsies ...  and reserved for hating those who need help by those who got some chance via university or company courses --- all ultimately from tax payer money to learn ...

Ask Robert Stallman if emacs is based on lisp and if McCarthy invented it from tax payer funded government grants to MIT or if it rained from moon ?

Be clear, precise and objective in your replies. I challenge you to rebut me on this point of funding !!! Your phd is most likely funded from tax payer money and even if you did TA ship, the infra-structure is public funding ...

Troll is a hate terminology. Dont ever use it ...

just get it.

Franz Xe

Miles Bader

unread,
Dec 12, 2010, 11:39:44 PM12/12/10
to Fren Zeee, Stephen J. Turnbull, help-gn...@gnu.org, Emacs Dev [emacs-devel]
Fren Zeee <fren...@gmail.com> writes:
> Troll is a hate terminology. Dont ever use it ...

How about "netkook"?

Sometimes that's the most accurate term.

-Miles

--
Dictionary, n. A malevolent literary device for cramping the growth of
a language and making it hard and inelastic. This dictionary, however,
is a most useful work.

Fren Zeee

unread,
Dec 13, 2010, 2:57:38 PM12/13/10
to Miles Bader, Stephen J. Turnbull, help-gn...@gnu.org, Emacs Dev [emacs-devel]
On Sun, Dec 12, 2010 at 8:39 PM, Miles Bader <mi...@gnu.org> wrote:
>
> Fren Zeee <fren...@gmail.com> writes:
> > Troll is a hate terminology. Dont ever use it ...
>
> How about "netkook"?
>
> Sometimes that's the most accurate term.
>
> -Miles
 
Regardless, of your prejudice, its a hate term and you are MALICIOUS because you wasted bandwidth on useless destructive flaming than constructive reply to the issue of the thread.
 
It has no relevance to the thread.
 
Turnbull is a victim of bad tutoring from the internet at the hands of netkooks themselves who have ingrained this prejudice in him.
 
I was trying to analytically correct him and you too.
 
It is well known that those who learnt with difficulty or some other causes of malicious psychology, practice the same meanness to impede the path of others and use various tactics to derail the thread by diversionary tactics of flaming etc.
 
But dispassionate analysis can defeat it or exhibit the lack of information when its presence is actually claimed.
 
Lets get moving with the issue of this thread from where this diversion started.
Re: How to remove verbosity from the data passing mechanism using alist or plist ?

Fren Zeee

unread,
Dec 13, 2010, 2:58:18 PM12/13/10
to Miles Bader, Stephen J. Turnbull, help-gn...@gnu.org, Emacs Dev [emacs-devel]
Lets get moving with the issue of this thread from _BEFORE_ where this diversion started.

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

David Kastrup

unread,
Dec 13, 2010, 3:45:30 PM12/13/10
to help-gn...@gnu.org, emacs...@gnu.org
Fren Zeee <fren...@gmail.com> writes:

> On Sun, Dec 12, 2010 at 8:39 PM, Miles Bader <mi...@gnu.org> wrote:
>>
>> Fren Zeee <fren...@gmail.com> writes:
>> > Troll is a hate terminology. Dont ever use it ...
>>
>> How about "netkook"?
>

> Regardless, of your prejudice, its a hate term and you are MALICIOUS
> because you wasted bandwidth on useless destructive flaming than
> constructive reply to the issue of the thread.
>
> It has no relevance to the thread.
>
> Turnbull is a victim of bad tutoring from the internet at the hands of
> netkooks themselves who have ingrained this prejudice in him.

Calling somebody only by his last name (without either title or given
name) when he is participating in the conversation, is considered quite
rude in the English-speaking world.

> I was trying to analytically correct him and you too.

Now you are insulting Freud as well.

I consider both Miles Bader as well as Stephen Turnbull perfectly
capable of forming their own opinion when somebody spouts nonsense. One
does not need any "netkooks" or other outside agents to form a qualified
opinion about the things you consider fit for writing.

They speak for themselves. And are the only things speaking for you in
a written medium.

--
David Kastrup


Fren Zeee

unread,
Dec 13, 2010, 7:13:20 PM12/13/10
to David Kastrup, help-gn...@gnu.org, emacs...@gnu.org
On Mon, Dec 13, 2010 at 12:45 PM, David Kastrup <d...@gnu.org> wrote:
>
> Fren Zeee <fren...@gmail.com> writes:
>
> > On Sun, Dec 12, 2010 at 8:39 PM, Miles Bader <mi...@gnu.org> wrote:
> >>
> >> Fren Zeee <fren...@gmail.com> writes:
> >> > Troll is a hate terminology. Dont ever use it ...
> >>
> >> How about "netkook"?
> >
> > Regardless, of your prejudice, its a hate term and you are MALICIOUS
> > because you wasted bandwidth on useless destructive flaming than
> > constructive reply to the issue of the thread.
> >
> > It has no relevance to the thread.
> >
> > Turnbull is a victim of bad tutoring from the internet at the hands of
> > netkooks themselves who have ingrained this prejudice in him.
>
> Calling somebody only by his last name (without either title or given
> name) when he is participating in the conversation, is considered quite
> rude in the English-speaking world.

well thats not a universal convention and quite a contrived argument.
I would not stoop to his level and call him a troll which is a hate
terminology.

I think your assessment is based more on his utility to contribute and
the small network where richard stallman has shared summarized
knowledge.

we know that the original model was to give code but keep the
documentation emaciated. Its written in a machiavellian style, where
you have to already know it to understand it. Thats why it takes a
long learning curve.

You are a prime writer on comp.text.tex where donald knuth has also
given a certain tex manual as a tex file which has to be understood to
be able to latex it ... i am just trying to explain what certain
"fathers" have propagated a disease in the community by example and
others imitating it.

> > I was trying to analytically correct him and you too.
>
> Now you are insulting Freud as well.

lol

> I consider both Miles Bader as well as Stephen Turnbull perfectly
> capable of forming their own opinion when somebody spouts nonsense.  One
> does not need any "netkooks" or other outside agents to form a qualified
> opinion about the things you consider fit for writing.
>
> They speak for themselves.  And are the only things speaking for you in
> a written medium.
>

Your refusal to turn this into constructive and focus on the subject
of the thread says more. Besides, your past record of giving cynical
replies on various groups is long and people know it.

Again, i challenge you to revert to the original topic of the thread.

Fren Zeee

unread,
Dec 13, 2010, 8:20:50 PM12/13/10
to David Kastrup, help-gn...@gnu.org, emacs...@gnu.org

Get reading help.

I did not introduce the term "netkook" in this thread. Its Miles Bader.

Infact, every single derogatory label that has been introduced in this
thread is by someone other than myself.

All I am asking for the resumption of and completion of the ideas
advanced by Thien-Thi towards the subject of discussion in this
thread.

Good usage of the language would help us become a contributor which I
earnestly aspire to be.

Remember, gnu software movement was about sharing source code and
comments (and explanations and good programming ideas) are part of the
same. Its not tutoring service. Those withholding the simple reply are
the ones dragging this unnecessarily. I have seen development threads
where there is a question like this. Someone wanted a code review
which begs the question of checking and giving ideas.

Cheers,
Franz Xe

0 new messages