[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Replacement for `aput' from obsolete assoc.el?
From: |
Michael Heerdegen |
Subject: |
Re: Replacement for `aput' from obsolete assoc.el? |
Date: |
Tue, 05 Jun 2012 21:31:40 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) |
Stefan Monnier <address@hidden> writes:
> Usually, for alists, you can do:
>
> (push (cons key val) alist)
>
> If you want to do it via side-effects, then it largely depends on what
> kind of "alist" this is. If you know the key is already in there, you
> can do
>
> (setcdr (assoc key alist) val)
So I think I want something like that:
(defun my-aput (alist-sym key val)
(let ((cons (assoc key (symbol-value alist-sym))))
(if cons (setcdr cons val) (push (cons key val) (symbol-value alist-sym)))))
> >> instead of `eq')? Dunno why this function does not exist yet, but it
> >> would ease handling alists e.g. if its keys are strings.
>
> Using side-effects on alists is often a bad idea.
Why? I do this very often in my .emacs. For example:
--8<---------------cut here---------------start------------->8---
(aput 'find-constituents 'readable (list 0))
(eval-after-load "linkd"
'(aput 'minor-mode-alist 'linkd-mode '(" Ld")))
(aput 'default-frame-alist 'width 104)
(aput 'warning-suppress-types 'undo '(discard-info))
(aput 'auto-mode-alist "\\.v?dired\\'" 'dired-virtual-mode)
(aput 'org-show-siblings 'org-goto t)
(aput 'w3m-search-engine-alist
"duckduckgo" '("http://duckduckgo.com/?q=%s"))
--8<---------------cut here---------------end--------------->8---
Is it a bad idea in these cases?
> - Code bundled with Emacs-24.2 is still not "allowed" to use the CL
> function you showed (i.e. `delete*'). It can require the new `cl-lib'
> and use `cl-delete' instead, tho.
Will it be ok to require cl-lib at run-time in third-party packages?
That would be great.
Thanks,
Michael.
- Replacement for `aput' from obsolete assoc.el?, Michael Heerdegen, 2012/06/04
- Re: Replacement for `aput' from obsolete assoc.el?, Christopher Schmidt, 2012/06/04
- Re: Replacement for `aput' from obsolete assoc.el?, Stefan Monnier, 2012/06/05
- Re: Replacement for `aput' from obsolete assoc.el?,
Michael Heerdegen <=
- Re: Replacement for `aput' from obsolete assoc.el?, Stefan Monnier, 2012/06/05
- Re: Replacement for `aput' from obsolete assoc.el?, Vitalie Spinu, 2012/06/08
- Re: Replacement for `aput' from obsolete assoc.el?, Stephen J. Turnbull, 2012/06/08
- Re: Replacement for `aput' from obsolete assoc.el?, Stefan Monnier, 2012/06/08
- Re: Replacement for `aput' from obsolete assoc.el?, Stephen J. Turnbull, 2012/06/09
- Re: Replacement for `aput' from obsolete assoc.el?, Andreas Schwab, 2012/06/09
- Re: Replacement for `aput' from obsolete assoc.el?, Thien-Thi Nguyen, 2012/06/09
- Re: Replacement for `aput' from obsolete assoc.el?, Stephen J. Turnbull, 2012/06/10
- RE: Replacement for `aput' from obsolete assoc.el?, Drew Adams, 2012/06/09
- RE: Replacement for `aput' from obsolete assoc.el?, Drew Adams, 2012/06/09