* assoc-delete-all
@ 2005-07-03 0:23 Lennart Borgman
2005-07-03 0:52 ` assoc-delete-all Juanma Barranquero
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Lennart Borgman @ 2005-07-03 0:23 UTC (permalink / raw
There is an assq-delete-all, but I am missing assoc-delete-all ... or,
am I missing something (else)?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: assoc-delete-all
2005-07-03 0:23 assoc-delete-all Lennart Borgman
@ 2005-07-03 0:52 ` Juanma Barranquero
2005-07-03 7:30 ` assoc-delete-all Lennart Borgman
2005-07-03 10:24 ` assoc-delete-all Lute Kamstra
2005-07-03 20:43 ` assoc-delete-all Richard M. Stallman
2 siblings, 1 reply; 12+ messages in thread
From: Juanma Barranquero @ 2005-07-03 0:52 UTC (permalink / raw
Cc: emacs-devel
> There is an assq-delete-all, but I am missing assoc-delete-all ... or,
> am I missing something (else)?
If I had to guess, I'd say that is because `assq-delete-all' has only
one reasonable behavior, i.e., as it modifies the structure, you
usually are going to do
(setq alist (assq-delete-all 'my-key alist))
or directly construct the alist, filter it through `assq-delete-all'
and then discard it.
With `assoc-delete-all' you have to decide whether you want a shallow
or a deep copy, for example:
(defun assoc-delete-all (key alist)
(let (l)
(while alist
(unless (and (consp (car alist))
(eq key (caar alist)))
(setq l (cons (car alist) l)))
(setq alist (cdr alist)))
(nreverse l)))
will do what you want, but it will still share conses with the
original list. Other implementations can use `copy-tree' or
`copy-alist', but really, there's no one answer that is good for every
situation. Kent M. Pitman did a wonderful article about this issue (he
was speaking of copy) a long time ago: "The Best of Intentions: EQUAL
Rights--and Wrongs--in Lisp",
http://www.nhplace.com/kent/PS/EQUAL.html
--
/L/e/k/t/u
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: assoc-delete-all
2005-07-03 0:52 ` assoc-delete-all Juanma Barranquero
@ 2005-07-03 7:30 ` Lennart Borgman
0 siblings, 0 replies; 12+ messages in thread
From: Lennart Borgman @ 2005-07-03 7:30 UTC (permalink / raw
Cc: emacs-devel
Juanma Barranquero wrote:
> ...
>
>will do what you want, but it will still share conses with the
>original list. Other implementations can use `copy-tree' or
>`copy-alist', but really, there's no one answer that is good for every
>situation. Kent M. Pitman did a wonderful article about this issue (he
>was speaking of copy) a long time ago: "The Best of Intentions: EQUAL
>Rights--and Wrongs--in Lisp",
>http://www.nhplace.com/kent/PS/EQUAL.html
>
Thanks for the good lessons.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: assoc-delete-all
2005-07-03 0:23 assoc-delete-all Lennart Borgman
2005-07-03 0:52 ` assoc-delete-all Juanma Barranquero
@ 2005-07-03 10:24 ` Lute Kamstra
2005-07-03 10:51 ` assoc-delete-all Lennart Borgman
2005-07-03 10:58 ` assoc-delete-all Lennart Borgman
2005-07-03 20:43 ` assoc-delete-all Richard M. Stallman
2 siblings, 2 replies; 12+ messages in thread
From: Lute Kamstra @ 2005-07-03 10:24 UTC (permalink / raw
Cc: emacs-devel
Lennart Borgman <lennart.borgman.073@student.lu.se> writes:
> There is an assq-delete-all, but I am missing assoc-delete-all
I guess nobody needed it before. Do you want to use it?
Lute.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: assoc-delete-all
2005-07-03 10:24 ` assoc-delete-all Lute Kamstra
@ 2005-07-03 10:51 ` Lennart Borgman
2005-07-03 10:58 ` assoc-delete-all Lennart Borgman
1 sibling, 0 replies; 12+ messages in thread
From: Lennart Borgman @ 2005-07-03 10:51 UTC (permalink / raw
Cc: Juanma Barranquero, emacs-devel
Lute Kamstra wrote:
>Lennart Borgman <lennart.borgman.073@student.lu.se> writes:
>
>
>
>>There is an assq-delete-all, but I am missing assoc-delete-all
>>
>>
>
>I guess nobody needed it before. Do you want to use it?
>
>
Thanks, but after reading Juanma's answer and thinking about it I
realize that I do not need it really.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: assoc-delete-all
2005-07-03 10:24 ` assoc-delete-all Lute Kamstra
2005-07-03 10:51 ` assoc-delete-all Lennart Borgman
@ 2005-07-03 10:58 ` Lennart Borgman
1 sibling, 0 replies; 12+ messages in thread
From: Lennart Borgman @ 2005-07-03 10:58 UTC (permalink / raw
Cc: Juanma Barranquero, emacs-devel
Lute Kamstra wrote:
>Lennart Borgman <lennart.borgman.073@student.lu.se> writes:
>
>
>
>>There is an assq-delete-all, but I am missing assoc-delete-all
>>
>>
>
>I guess nobody needed it before. Do you want to use it?
>
>
Thanks, but after reading Juanma's answer and thinking about it I
realize that I do not need it really.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: assoc-delete-all
2005-07-03 0:23 assoc-delete-all Lennart Borgman
2005-07-03 0:52 ` assoc-delete-all Juanma Barranquero
2005-07-03 10:24 ` assoc-delete-all Lute Kamstra
@ 2005-07-03 20:43 ` Richard M. Stallman
2005-07-04 0:16 ` assoc-delete-all Juri Linkov
2 siblings, 1 reply; 12+ messages in thread
From: Richard M. Stallman @ 2005-07-03 20:43 UTC (permalink / raw
Cc: emacs-devel
There is an assq-delete-all, but I am missing assoc-delete-all ... or,
We don't want to add assoc-delete-all merely for symmetry.
It would have to be needed in practice.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: assoc-delete-all
2005-07-03 20:43 ` assoc-delete-all Richard M. Stallman
@ 2005-07-04 0:16 ` Juri Linkov
2005-07-04 9:00 ` assoc-delete-all Juanma Barranquero
2005-07-05 4:35 ` assoc-delete-all Richard M. Stallman
0 siblings, 2 replies; 12+ messages in thread
From: Juri Linkov @ 2005-07-04 0:16 UTC (permalink / raw
Cc: lennart.borgman.073, emacs-devel
> There is an assq-delete-all, but I am missing assoc-delete-all ... or,
>
> We don't want to add assoc-delete-all merely for symmetry.
> It would have to be needed in practice.
Well, assoc-delete-all will help to fix the bug in dired-compare-directories.
Sometimes the number of marked files it reports is wrong. That's
because it compares the file attributes of directories "." and "..",
but dired mark-functions don't mark them.
assoc-delete-all could filter out "." and ".." from the list of file
attributes returned by dired-files-attributes, which is an alist
with string keys
(("." "<full-name>" <attributes>)
(".." "<full-name>" <attributes>)
("file" "<full-name>" <attributes>))
with this function
(assoc-delete-all "." (assoc-delete-all ".." file-alist1))
Even better would be to allow a test function like in assoc-default:
(assoc-delete-all nil file-alist1 (lambda (key) (string-match "^\.\.?$" key)))
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: assoc-delete-all
2005-07-04 0:16 ` assoc-delete-all Juri Linkov
@ 2005-07-04 9:00 ` Juanma Barranquero
2005-07-05 5:33 ` assoc-delete-all Juri Linkov
2005-07-05 4:35 ` assoc-delete-all Richard M. Stallman
1 sibling, 1 reply; 12+ messages in thread
From: Juanma Barranquero @ 2005-07-04 9:00 UTC (permalink / raw
Cc: emacs-devel
On 7/4/05, Juri Linkov <juri@jurta.org> wrote:
> with this function
>
> (assoc-delete-all "." (assoc-delete-all ".." file-alist1))
>
> Even better would be to allow a test function like in assoc-default:
>
> (assoc-delete-all nil file-alist1 (lambda (key) (string-match "^\.\.?$" key)))
That's one of these things that would be much easier if we could use CL:
; Not a particularly good implementation, but...
(defun assoc-delete-all (key alist &rest keywords)
(or keywords (setq keywords (list ':test 'eq )))
(apply #'remove* key alist :key #'car keywords))
and you could do
(assoc-delete-all "^\.\.?$" file-alist1
:test #'(lambda (test item)
(string-match test item)))
<sigh> :-)
--
/L/e/k/t/u
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: assoc-delete-all
2005-07-04 0:16 ` assoc-delete-all Juri Linkov
2005-07-04 9:00 ` assoc-delete-all Juanma Barranquero
@ 2005-07-05 4:35 ` Richard M. Stallman
2005-07-05 5:27 ` assoc-delete-all Juri Linkov
1 sibling, 1 reply; 12+ messages in thread
From: Richard M. Stallman @ 2005-07-05 4:35 UTC (permalink / raw
Cc: lennart.borgman.073, emacs-devel
Well, assoc-delete-all will help to fix the bug in dired-compare-directories.
Sometimes the number of marked files it reports is wrong. That's
because it compares the file attributes of directories "." and "..",
but dired mark-functions don't mark them.
Is the following patch not right?
*** dired-aux.el 03 Jul 2005 12:12:32 -0400 1.133
--- dired-aux.el 04 Jul 2005 15:01:37 -0400
***************
*** 136,141 ****
--- 136,143 ----
(dired-file-set-difference
file-alist2 file-alist1
predicate))))
+ (setq file-list1 (delete "." (delete ".." file-list1)))
+ (setq file-list2 (delete "." (delete ".." file-list2)))
(dired-fun-in-all-buffers
dir1 nil
(lambda ()
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: assoc-delete-all
2005-07-05 4:35 ` assoc-delete-all Richard M. Stallman
@ 2005-07-05 5:27 ` Juri Linkov
0 siblings, 0 replies; 12+ messages in thread
From: Juri Linkov @ 2005-07-05 5:27 UTC (permalink / raw
Cc: lennart.borgman.073, emacs-devel
> Is the following patch not right?
>
> *** dired-aux.el 03 Jul 2005 12:12:32 -0400 1.133
> --- dired-aux.el 04 Jul 2005 15:01:37 -0400
> ***************
> *** 136,141 ****
> --- 136,143 ----
> (dired-file-set-difference
> file-alist2 file-alist1
> predicate))))
> + (setq file-list1 (delete "." (delete ".." file-list1)))
> + (setq file-list2 (delete "." (delete ".." file-list2)))
> (dired-fun-in-all-buffers
> dir1 nil
> (lambda ()
This doesn't work because file names in file-list1 and file-list2
are absolute.
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: assoc-delete-all
2005-07-04 9:00 ` assoc-delete-all Juanma Barranquero
@ 2005-07-05 5:33 ` Juri Linkov
0 siblings, 0 replies; 12+ messages in thread
From: Juri Linkov @ 2005-07-05 5:33 UTC (permalink / raw
Cc: emacs-devel
>> with this function
>>
>> (assoc-delete-all "." (assoc-delete-all ".." file-alist1))
>>
>> Even better would be to allow a test function like in assoc-default:
>>
>> (assoc-delete-all nil file-alist1 (lambda (key) (string-match "^\.\.?$" key)))
>
> That's one of these things that would be much easier if we could use CL:
Another thing that would be easier with CL is its `set-difference'
which is currently duplicated in dired-aux.el as `dired-file-set-difference'
with the specialization to work only on file attributes.
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2005-07-05 5:33 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-03 0:23 assoc-delete-all Lennart Borgman
2005-07-03 0:52 ` assoc-delete-all Juanma Barranquero
2005-07-03 7:30 ` assoc-delete-all Lennart Borgman
2005-07-03 10:24 ` assoc-delete-all Lute Kamstra
2005-07-03 10:51 ` assoc-delete-all Lennart Borgman
2005-07-03 10:58 ` assoc-delete-all Lennart Borgman
2005-07-03 20:43 ` assoc-delete-all Richard M. Stallman
2005-07-04 0:16 ` assoc-delete-all Juri Linkov
2005-07-04 9:00 ` assoc-delete-all Juanma Barranquero
2005-07-05 5:33 ` assoc-delete-all Juri Linkov
2005-07-05 4:35 ` assoc-delete-all Richard M. Stallman
2005-07-05 5:27 ` assoc-delete-all Juri Linkov
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).