all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Wilfred Hughes <me@wilfred.me.uk>
To: emacs-devel@gnu.org
Subject: RFC: make maphash return a list
Date: Fri, 3 May 2013 18:59:10 +0100	[thread overview]
Message-ID: <CAFXAjY72zDAGLnZro9MkqgRDa_eyEu9fvufu_rc9=8HGcocNmg@mail.gmail.com> (raw)

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

I've been using Emacs hash tables a lot recently, and I would find
several operations much easier if maphash returned a list. For
example, I'd like to be able to do:

(maphash (lambda (key value) key) some-table)

to obtain the list of keys present in some-table. I would guess elisp
is influenced by Common Lisp here, where maphash returns nil
unconditionally. However, unlike elisp, Common Lisp's loop macro
supports iterating over keys directly with (loop for key being
hash-key of some-table ...) which helps considerably.

I can't see any obvious way this would break backwards compatibility,
so I threw together a trivial patch that makes maphash return a list
of the results. I've attached the patch.

Is there interest in this?

Wilfred

[-- Attachment #2: fns.c.diff --]
[-- Type: text/x-patch, Size: 423 bytes --]

4513c4513
<        doc: /* Call FUNCTION for all entries in hash table TABLE.
---
>        doc: /* Call FUNCTION for all entries in hash table TABLE, and make a list of the results.
4519a4520,4521
>   Lisp_Object ret = Qnil;
>   Lisp_Object current_result;
4527c4529,4530
< 	Ffuncall (3, args);
---
> 	current_result = Ffuncall (3, args);
> 	ret = Fcons(current_result, ret);
4530c4533
<   return Qnil;
---
>   return ret;

             reply	other threads:[~2013-05-03 17:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-03 17:59 Wilfred Hughes [this message]
2013-05-03 23:12 ` RFC: make maphash return a list Pascal J. Bourguignon
2013-05-04  5:29 ` Stephen J. Turnbull
2013-05-05  0:06   ` Wilfred Hughes
2013-06-18  8:17     ` Klaus-Dieter Bauer
2013-06-18 15:11       ` Davis Herring
2013-06-18 20:06         ` Klaus-Dieter Bauer

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFXAjY72zDAGLnZro9MkqgRDa_eyEu9fvufu_rc9=8HGcocNmg@mail.gmail.com' \
    --to=me@wilfred.me.uk \
    --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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.