unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Adding assoc-delete-all / rassoc-delete-all
@ 2014-04-17 11:39 Tassilo Horn
  2014-04-17 11:55 ` Thorsten Jolitz
  2014-04-17 15:17 ` Teemu Likonen
  0 siblings, 2 replies; 8+ messages in thread
From: Tassilo Horn @ 2014-04-17 11:39 UTC (permalink / raw)
  To: emacs-devel

Hi all,

I've just got aware of `assq-delete-all' which could be a convenient
function to get rid of some entry in an alist.  However, if the alist
entries start with a string, you need to use something awkward like

  (assq-delete-all
   (car (assoc "Biber" TeX-command-list))
   TeX-command-list)

so that the string "Biber" is not only equal but identical.

So I'm voting for adding a function `assoc-delete-all' which is just
like `assq-delete-all' except that it does the comparison with `equal'
instead of `eq'.  Then the above becomes just

  (assoc-delete-all "Biber" TeX-command-list)

For symmetry, I'd also add `rassoc-delete-all' to the existing
`rassq-delete-all'.

Would that be ok?

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding assoc-delete-all / rassoc-delete-all
  2014-04-17 11:39 Adding assoc-delete-all / rassoc-delete-all Tassilo Horn
@ 2014-04-17 11:55 ` Thorsten Jolitz
  2014-04-17 12:29   ` Stefan Monnier
  2014-04-17 12:35   ` Tassilo Horn
  2014-04-17 15:17 ` Teemu Likonen
  1 sibling, 2 replies; 8+ messages in thread
From: Thorsten Jolitz @ 2014-04-17 11:55 UTC (permalink / raw)
  To: emacs-devel

Tassilo Horn <tsdh@gnu.org> writes:

> So I'm voting for adding a function `assoc-delete-all' which is just
> like `assq-delete-all' except that it does the comparison with `equal'
> instead of `eq'.

Reminds me of the many times I wished there would be a

,--------------------------------------------------------
| case is an alias for `cl-case' in `cl.el'.
| 
| (case EXPR (KEYLIST BODY...)...)
| 
| Eval EXPR and choose among clauses on that value. [...]
| Key values are compared by `eql'.
`--------------------------------------------------------

that does comparison with `equal' too (or does it exist and I just
missed it?).

-- 
cheers,
Thorsten




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding assoc-delete-all / rassoc-delete-all
  2014-04-17 11:55 ` Thorsten Jolitz
@ 2014-04-17 12:29   ` Stefan Monnier
  2014-04-17 13:36     ` Thorsten Jolitz
  2014-04-17 12:35   ` Tassilo Horn
  1 sibling, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2014-04-17 12:29 UTC (permalink / raw)
  To: Thorsten Jolitz; +Cc: emacs-devel

> ,--------------------------------------------------------
> | case is an alias for `cl-case' in `cl.el'.
> | 
> | (case EXPR (KEYLIST BODY...)...)
> | 
> | Eval EXPR and choose among clauses on that value. [...]
> | Key values are compared by `eql'.
> `--------------------------------------------------------
> that does comparison with `equal' too (or does it exist and I just
> missed it?).

Not quite what you're asking, but `pcase' uses `equal' to compare strings.


        Stefan



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding assoc-delete-all / rassoc-delete-all
  2014-04-17 11:55 ` Thorsten Jolitz
  2014-04-17 12:29   ` Stefan Monnier
@ 2014-04-17 12:35   ` Tassilo Horn
  2014-04-17 13:15     ` Stefan Monnier
  2014-04-17 13:40     ` Thorsten Jolitz
  1 sibling, 2 replies; 8+ messages in thread
From: Tassilo Horn @ 2014-04-17 12:35 UTC (permalink / raw)
  To: Thorsten Jolitz; +Cc: emacs-devel

Thorsten Jolitz <tjolitz@gmail.com> writes:

> Reminds me of the many times I wished there would be a
>
> ,--------------------------------------------------------
> | case is an alias for `cl-case' in `cl.el'.
> | 
> | (case EXPR (KEYLIST BODY...)...)
> | 
> | Eval EXPR and choose among clauses on that value. [...]
> | Key values are compared by `eql'.
> `--------------------------------------------------------

Strange that it compares with `eql'.  Doesn't `eql' only allow comparing
floating point values in addition to what's allowed by `eq'?  And floats
don't seem to be reasonable candidates for a `case' distinction...

> that does comparison with `equal' too (or does it exist and I just
> missed it?).

No, I don't think there is.  But I think here a more versatile macro
would be better than hard-coding another version with the test fixed to
`equal' [1].  For example, Clojure has `condp' which is similar to
`case' but allows to specify the predicate.

  (condp #'equal x
    "Foo"    :foo
    1        :one
    17       :seventeen
    :neither-foo-one-or-seventeen)

Bye,
Tassilo

[1] That's a bit different for `assoc-delete-all' because the names
    `assq' and `assoc' are traditionally associated with `eq' and
    `equal'.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding assoc-delete-all / rassoc-delete-all
  2014-04-17 12:35   ` Tassilo Horn
@ 2014-04-17 13:15     ` Stefan Monnier
  2014-04-17 13:40     ` Thorsten Jolitz
  1 sibling, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2014-04-17 13:15 UTC (permalink / raw)
  To: Thorsten Jolitz; +Cc: emacs-devel

> Strange that it compares with `eql'.  Doesn't `eql' only allow comparing
> floating point values in addition to what's allowed by `eq'?

Common-Lisp simply uses `eql' by default "everywhere".  That's because
the semantics of `eq' is pretty weird, really: if it weren't for `eq'
you could never tell the difference between two identical floats.  So in
many ways, `eq' is a mistake which lets details of implementation
seep through.

Oh, and IIUC `eql' is also different from `eq' on all other immutable
objects (e.g. bignums).

> And floats don't seem to be reasonable candidates for a `case'
> distinction...

Indeed, but comparing their addresses is even less desirable.


        Stefan



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding assoc-delete-all / rassoc-delete-all
  2014-04-17 12:29   ` Stefan Monnier
@ 2014-04-17 13:36     ` Thorsten Jolitz
  0 siblings, 0 replies; 8+ messages in thread
From: Thorsten Jolitz @ 2014-04-17 13:36 UTC (permalink / raw)
  To: emacs-devel

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

>> ,--------------------------------------------------------
>> | case is an alias for `cl-case' in `cl.el'.
>> | 
>> | (case EXPR (KEYLIST BODY...)...)
>> | 
>> | Eval EXPR and choose among clauses on that value. [...]
>> | Key values are compared by `eql'.
>> `--------------------------------------------------------
>> that does comparison with `equal' too (or does it exist and I just
>> missed it?).
>
> Not quite what you're asking, but `pcase' uses `equal' to compare strings.

Did not know about that one, thanks. PicoLisp has `casq' as a special
case comparing pointer equalitiy, and `case' that compares with `equal',
so everytime I try to use `case' in Elisp I notice how restricted it
is in comparison. 

-- 
cheers,
Thorsten




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding assoc-delete-all / rassoc-delete-all
  2014-04-17 12:35   ` Tassilo Horn
  2014-04-17 13:15     ` Stefan Monnier
@ 2014-04-17 13:40     ` Thorsten Jolitz
  1 sibling, 0 replies; 8+ messages in thread
From: Thorsten Jolitz @ 2014-04-17 13:40 UTC (permalink / raw)
  To: emacs-devel

Tassilo Horn <tsdh@gnu.org> writes:

> No, I don't think there is.  But I think here a more versatile macro
> would be better than hard-coding another version with the test fixed to
> `equal'.

Indeed, default comparison with `equal' and an '&optional eqlp' argument
would be nice.

-- 
cheers,
Thorsten




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding assoc-delete-all / rassoc-delete-all
  2014-04-17 11:39 Adding assoc-delete-all / rassoc-delete-all Tassilo Horn
  2014-04-17 11:55 ` Thorsten Jolitz
@ 2014-04-17 15:17 ` Teemu Likonen
  1 sibling, 0 replies; 8+ messages in thread
From: Teemu Likonen @ 2014-04-17 15:17 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 623 bytes --]

Tassilo Horn [2014-04-17 13:39:41 +02:00] wrote:

> So I'm voting for adding a function `assoc-delete-all' which is just
> like `assq-delete-all' except that it does the comparison with `equal'
> instead of `eq'. Then the above becomes just

That would add symmetry but how about cl-delete(-if(-not))?

    (setq Tex-Command-List
          (cl-delete "Biber" TeX-command-list 
                     :key 'car :test 'equal))

> For symmetry, I'd also add `rassoc-delete-all' to the existing
> `rassq-delete-all'.

I prefer those generic higher-order Common Lisp versions which already
have all the features.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-04-17 15:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-17 11:39 Adding assoc-delete-all / rassoc-delete-all Tassilo Horn
2014-04-17 11:55 ` Thorsten Jolitz
2014-04-17 12:29   ` Stefan Monnier
2014-04-17 13:36     ` Thorsten Jolitz
2014-04-17 12:35   ` Tassilo Horn
2014-04-17 13:15     ` Stefan Monnier
2014-04-17 13:40     ` Thorsten Jolitz
2014-04-17 15:17 ` Teemu Likonen

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