all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* hash strangeness
@ 2014-11-02 11:20 Tom
  2014-11-02 12:09 ` Tom
  0 siblings, 1 reply; 13+ messages in thread
From: Tom @ 2014-11-02 11:20 UTC (permalink / raw)
  To: help-gnu-emacs

Here's a code which gives me some headache. It's silly, because
it was shortened from a longer code to demonstrate the problem.

It is supposed to count something in elisp functions, though
the condition is removed, so with this code the count should be
1 for every function.

So the code checks if the function is already in the hash
and if not then it inserts new info for that function:


(let ((h (make-hash-table :test 'equal)))
  (mapatoms
   (lambda (s)
     (let* ((name (symbol-name s))
            (info (gethash name h)))

       (unless info
         (setq info '(count 0)))

       (setq info (plist-put info
                             'count (1+ (plist-get info 'count))))
                  
       (puthash name info h))))

  (pop-to-buffer "*testout*")
  (erase-buffer)
  (maphash (lambda (name info)
             (insert (format "%s %s" (plist-get info 'count) name) "\n"))
           h))


The new info is newly created in the lambda function (it is
a plist, because in the real code there are other fields too),
yet for some reason the same info structure is used for all
iterations.

I tried to debug it and at the "(unless info" part info is nil
and then it is set to the previous value, though it should be a 
new value.

Am I missing something here?

GNU Emacs 24.1.1 





^ permalink raw reply	[flat|nested] 13+ messages in thread
[parent not found: <mailman.12577.1414927271.1147.help-gnu-emacs@gnu.org>]

end of thread, other threads:[~2014-11-04  7:39 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-02 11:20 hash strangeness Tom
2014-11-02 12:09 ` Tom
2014-11-02 18:20   ` Thien-Thi Nguyen
2014-11-02 20:45     ` Tom
     [not found]     ` <mailman.12618.1414961152.1147.help-gnu-emacs@gnu.org>
2014-11-02 22:25       ` Pascal J. Bourguignon
2014-11-02 22:48       ` Barry Margolin
2014-11-03 21:29         ` Tom
2014-11-04  1:57           ` Robert Thorpe
2014-11-04  2:16           ` Michael Heerdegen
     [not found]       ` <<barmar-14233C.17480902112014@88-209-239-213.giganet.hu>
2014-11-04  3:04         ` Drew Adams
2014-11-04  7:39           ` Marcin Borkowski
     [not found] <mailman.12577.1414927271.1147.help-gnu-emacs@gnu.org>
2014-11-02 18:43 ` Pascal J. Bourguignon
2014-11-02 20:48   ` Tom

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.