unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Hash tables
@ 2003-09-11 22:12 Nick Roberts
  2003-09-11 22:42 ` Miles Bader
  2003-09-11 22:50 ` Stefan Monnier
  0 siblings, 2 replies; 3+ messages in thread
From: Nick Roberts @ 2003-09-11 22:12 UTC (permalink / raw)



I am trying to using alists to store information (to display watched expressions
under gdb with the speedbar). I have expressions like:

(dolist (var gdb-var-list)
     (let ((var-list))
       some operation on var...
     (push var var-list))
(setq gdb-var-list (nreverse var-list)))

where var is a list like (varnum a b c d)

Update of the speedbar for arrays and structures is too slow, so I thought
hash tables might speed things up. I want to replace the above with something
like:

(maphash gdb-var-operation gdb-var-table)

The manual says that gdb-var-operation, should accept two arguments KEY and
VALUE.

but I want to pass some arguments to gdb-var-operation. I plan to change
maphash to:

(maphash FUNCTION TABLE &optional ARGS)

so that FUNCTION gets called with KEY, VALUE and ARGS.

This won't be an easy task for me so I'd like some reassurance that its
a) desirable and b) do-able.


Nick

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

* Re: Hash tables
  2003-09-11 22:12 Hash tables Nick Roberts
@ 2003-09-11 22:42 ` Miles Bader
  2003-09-11 22:50 ` Stefan Monnier
  1 sibling, 0 replies; 3+ messages in thread
From: Miles Bader @ 2003-09-11 22:42 UTC (permalink / raw)
  Cc: emacs-devel

On Thu, Sep 11, 2003 at 11:12:38PM +0100, Nick Roberts wrote:
> but I want to pass some arguments to gdb-var-operation. I plan to change
> maphash to:
> 
> (maphash FUNCTION TABLE &optional ARGS)
> 
> so that FUNCTION gets called with KEY, VALUE and ARGS.
> 
> This won't be an easy task for me so I'd like some reassurance that its
> a) desirable and b) do-able.

The traditional way of doing this sort of thing in lisp is to bind variables
around the call to maphash, which your function can read (or write), e.g.:

   (let ((extra-info ...)
	 (total sum 0))
     (maphash
      (lambda (key val) 
	(setq total (+ total (calculate-stuff key val extra-info))))
      some-hash-table))

-Miles
-- 
We have met the enemy, and he is us.  -- Pogo

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

* Re: Hash tables
  2003-09-11 22:12 Hash tables Nick Roberts
  2003-09-11 22:42 ` Miles Bader
@ 2003-09-11 22:50 ` Stefan Monnier
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2003-09-11 22:50 UTC (permalink / raw)
  Cc: emacs-devel

> but I want to pass some arguments to gdb-var-operation. I plan to change
> maphash to:
> (maphash FUNCTION TABLE &optional ARGS)
> so that FUNCTION gets called with KEY, VALUE and ARGS.

That is not necessary.  You can just use

  (maphash `(lambda (key value) (fun key value ',arg)) table)

instead.  And in most cases the above can even be simplified to

  (maphash (lambda (key value) (fun key value arg)) table)


        Stefan

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

end of thread, other threads:[~2003-09-11 22:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-11 22:12 Hash tables Nick Roberts
2003-09-11 22:42 ` Miles Bader
2003-09-11 22:50 ` Stefan Monnier

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