From: Michael Heerdegen <michael_heerdegen@web.de>
To: emacs-devel@gnu.org
Subject: Re: Replacement for `aput' from obsolete assoc.el?
Date: Tue, 05 Jun 2012 21:31:40 +0200 [thread overview]
Message-ID: <87haupwo6b.fsf@web.de> (raw)
In-Reply-To: <jwvfwa9y83n.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Tue, 05 Jun 2012 13:43:20 -0400")
Stefan Monnier <monnier@iro.umontreal.ca> 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.
next prev parent reply other threads:[~2012-06-05 19:31 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-04 16:46 Replacement for `aput' from obsolete assoc.el? Michael Heerdegen
2012-06-05 3:27 ` Christopher Schmidt
2012-06-05 17:43 ` Stefan Monnier
2012-06-05 19:31 ` Michael Heerdegen [this message]
2012-06-05 22:52 ` Stefan Monnier
2012-06-08 7:57 ` Vitalie Spinu
2012-06-08 12:39 ` Stephen J. Turnbull
2012-06-08 19:50 ` Stefan Monnier
2012-06-09 8:59 ` Stephen J. Turnbull
2012-06-09 9:46 ` Andreas Schwab
2012-06-09 10:13 ` Thien-Thi Nguyen
2012-06-10 12:11 ` Stephen J. Turnbull
2012-06-09 16:11 ` Drew Adams
2012-06-09 16:17 ` Drew Adams
2012-06-09 11:32 ` Vitalie Spinu
2012-06-10 12:53 ` Stephen J. Turnbull
2012-06-09 16:10 ` Drew Adams
2012-06-10 0:52 ` Stefan Monnier
2012-06-10 13:48 ` Stephen J. Turnbull
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87haupwo6b.fsf@web.de \
--to=michael_heerdegen@web.de \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).