all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Printing a hash table
@ 2014-12-18 15:45 Joost Kremers
       [not found] ` <mailman.16411.1418918006.1147.help-gnu-emacs@gnu.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Joost Kremers @ 2014-12-18 15:45 UTC (permalink / raw)
  To: help-gnu-emacs

EN:SiS(9)
Hi,

When I have a larg(ish) hash table, displaying this table (e.g., in an
ielm buffer by entering the name that points to it), can take some time.
Usually, when I do this, I'm not really interested in the values stored
in the table, just in the fact whether the variable whose value I'm
checking is actually pointing to a hash table.

Is there a way to tell Emacs to not print the data of a hash table?

TIA


Joost

-- 
Joost Kremers                                   joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht


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

* RE: Printing a hash table
       [not found] <<slrnm95tki.h18.joost.m.kremers@j.kremers4.news.arnhem.chello.nl>
@ 2014-12-18 15:53 ` Drew Adams
  0 siblings, 0 replies; 6+ messages in thread
From: Drew Adams @ 2014-12-18 15:53 UTC (permalink / raw)
  To: Joost Kremers, help-gnu-emacs

> I'm not really interested in the values stored in the table, just
> in the fact whether the variable whose value I'm checking is
> actually pointing to a hash table.

Use predicate `hash-table-p'.

M-: (hash-table-p foo-variable) RET



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

* Re: Printing a hash table
       [not found] ` <mailman.16411.1418918006.1147.help-gnu-emacs@gnu.org>
@ 2014-12-18 19:27   ` Joost Kremers
  0 siblings, 0 replies; 6+ messages in thread
From: Joost Kremers @ 2014-12-18 19:27 UTC (permalink / raw)
  To: help-gnu-emacs

Drew Adams wrote:
>> I'm not really interested in the values stored in the table, just
>> in the fact whether the variable whose value I'm checking is
>> actually pointing to a hash table.
>
> Use predicate `hash-table-p'.
>
> M-: (hash-table-p foo-variable) RET

Mmm, I hadn't thought of that... :-) 


-- 
Joost Kremers                                   joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


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

* Printing a hash table
@ 2024-09-23  2:30 Heime
  2024-09-23  6:32 ` tomas
  0 siblings, 1 reply; 6+ messages in thread
From: Heime @ 2024-09-23  2:30 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

Is this the way to fill a hash table and print the values.  

(defvar marshal-fpln (make-hash-table :test 'equal)
  "Hash table storing paths for different marshal components.")

(defun marshal-insert ()

  (puthash "MRSHL" marshal-waypt marshal-fpln)
  (puthash "NAPLN" (concat marshal-waypt "/poleon") marshal-fpln)
  (puthash "FLKTR" (concat rellana-waypt "/alkotr") marshal-fpln)
  (puthash "GLXKS" (concat rellana-waypt "/xiakos") marshal-fpln)
  (puthash "ARKTK" (concat rellana-waypt "/ritika") marshal-fpln) )

(defun torium-hash-table (hash-table &optional bfrn)
  "Print HASH-TABLE to the buffer BFRN."

  (let* ( (bfname (or bfrn "Torium Hash Table"))
          (dbuffer (get-buffer-create (concat "𒆳 " bfname))) )

    (with-current-buffer dbuffer
      (maphash (lambda (key value)
                 (let* ( (start (point)) )
                   (insert (format " ━ %-8s" key))
                   (insert (format "\n    %s\n" value))))
               hash-table))))

I am getting the following error and cannot figure out how I can get out of it.


Debugger entered--Lisp error: (wrong-type-argument hash-table-p (("MRSHL") ("NAPLN") ("FLKTR") ("GLXKS") ("ARKTK" . t)))
  maphash((closure (t) (key value) (let* ((start (point))) (insert (format " ━ %-8s" key)) (add-text-properties start (point) '(face (:foreground "green"))) (insert (format "\n    %s\n" value)))) (("MRSHL") ("NAPLN") ("FLKTR") ("GLXKS") ("ARKTK" . t)))
  (save-current-buffer (set-buffer dbuffer) (face-remap-add-relative 'default :background "blue") (insert "\n Hash Table \n\n") (maphash #'(lambda (key value) (let* ((start (point))) (insert (format " ━ %-8s" key)) (add-text-properties start (point) '(face ...)) (insert (format "\n    %s\n" value)))) hash-table))
  (let* ((bfname (or bfrn "Torium Hash Table")) (dbuffer (get-buffer-create (concat "𒆳 " bfname)))) (save-current-buffer (set-buffer dbuffer) (face-remap-add-relative 'default :background "blue") (insert "\n Hash Table \n\n") (maphash #'(lambda (key value) (let* ((start ...)) (insert (format " ━ %-8s" key)) (add-text-properties start (point) '...) (insert (format "\n    %s\n" value)))) hash-table)))
  torium-hash-table((("MRSHL") ("NAPLN") ("FLKTR") ("GLXKS") ("ARKTK" . t)))



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

* Re: Printing a hash table
  2024-09-23  2:30 Heime
@ 2024-09-23  6:32 ` tomas
  2024-09-23 12:10   ` Heime
  0 siblings, 1 reply; 6+ messages in thread
From: tomas @ 2024-09-23  6:32 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

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

On Mon, Sep 23, 2024 at 02:30:31AM +0000, Heime wrote:
> Is this the way to fill a hash table and print the values.  
> 
> (defvar marshal-fpln (make-hash-table :test 'equal)
>   "Hash table storing paths for different marshal components.")
> 
> (defun marshal-insert ()
> 
>   (puthash "MRSHL" marshal-waypt marshal-fpln)
>   (puthash "NAPLN" (concat marshal-waypt "/poleon") marshal-fpln)
>   (puthash "FLKTR" (concat rellana-waypt "/alkotr") marshal-fpln)
>   (puthash "GLXKS" (concat rellana-waypt "/xiakos") marshal-fpln)
>   (puthash "ARKTK" (concat rellana-waypt "/ritika") marshal-fpln) )
> 
> (defun torium-hash-table (hash-table &optional bfrn)
>   "Print HASH-TABLE to the buffer BFRN."
> 
>   (let* ( (bfname (or bfrn "Torium Hash Table"))
>           (dbuffer (get-buffer-create (concat "𒆳 " bfname))) )
> 
>     (with-current-buffer dbuffer
>       (maphash (lambda (key value)
>                  (let* ( (start (point)) )
>                    (insert (format " ━ %-8s" key))
>                    (insert (format "\n    %s\n" value))))
>                hash-table))))
> 
> I am getting the following error and cannot figure out how I can get out of it.
> 
> 
> Debugger entered--Lisp error: (wrong-type-argument hash-table-p (("MRSHL") ("NAPLN") ("FLKTR") ("GLXKS") ("ARKTK" . t)))
>   maphash((closure (t) (key value) (let* ((start (point))) (insert (format " ━ %-8s" key)) (add-text-properties start (point) '(face (:foreground "green"))) (insert (format "\n    %s\n" value)))) (("MRSHL") ("NAPLN") ("FLKTR") ("GLXKS") ("ARKTK" . t)))

[rest of stack trace removed]

Please, do some homework. This helps people help you (this is actually
why I, at some point, stopped trying). Moreover, your (for the rest of
us) inscrutable variable names aren't helping.

Asking for programming help involves trying to help your helpers to
understand your problem. I feel that you aren't doing this (for whatever
reason). This will impair the quality of answers you get.

And third, you really, really should try to gain some more understanding
and practice with small Lisp code snippets. I have the impression that
you only half-grasped very basic concepts and run into the same kind of
problems time and again. Every bit you invest in the basics will pay back
hundredfold (and will motivate your potential helpers).

OK, that said, let's try to decode the two first lines of the error message
(I reformat them to make them fit a civilised window width and to highlight
their structure). Notes inline, prefixed with #. They are numbered to ref
to them further down.

> Debugger entered--Lisp error:
# (1) The lisp run time has signalled an error, and the debugger is reporting that:
>  (wrong-type-argument hash-table-p
# (2) Some function expects an argument satisfying the predicate hash-table-p and
#     has got instead...
>   (("MRSHL") ("NAPLN") ("FLKTR") ("GLXKS") ("ARKTK" . t)))
# (3) ...something which looks a lot like an alist (the four first entries are associated
#     to nil, that's why they possibly look like singletons)

Ad (2): Which function could that be? Look again at your code.
The only one I see is that maphash, restated (and abbreviated)
here:

>  (maphash (lambda (key value) ...) hash-table)

It gets two args (which corresponds to the doc). The first one
is the function to be iterated. The second is hash-table, which,
according to the doc, is expected to be a hash table.

Now where is that one coming from? It is passed as a param to your
torium-hash-table: we don't see how you are calling that one. I
conclude that (unless I've missed something) the error cause is
outside the code snippet you show us.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

* Re: Printing a hash table
  2024-09-23  6:32 ` tomas
@ 2024-09-23 12:10   ` Heime
  0 siblings, 0 replies; 6+ messages in thread
From: Heime @ 2024-09-23 12:10 UTC (permalink / raw)
  To: tomas; +Cc: Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

On Monday, September 23rd, 2024 at 6:32 PM, tomas@tuxteam.de <tomas@tuxteam.de> wrote:

> On Mon, Sep 23, 2024 at 02:30:31AM +0000, Heime wrote:
> 
> > Is this the way to fill a hash table and print the values.
> > 
> > (defvar marshal-fpln (make-hash-table :test 'equal)
> > "Hash table storing paths for different marshal components.")
> > 
> > (defun marshal-insert ()
> > 
> > (puthash "MRSHL" marshal-waypt marshal-fpln)
> > (puthash "NAPLN" (concat marshal-waypt "/poleon") marshal-fpln)
> > (puthash "FLKTR" (concat rellana-waypt "/alkotr") marshal-fpln)
> > (puthash "GLXKS" (concat rellana-waypt "/xiakos") marshal-fpln)
> > (puthash "ARKTK" (concat rellana-waypt "/ritika") marshal-fpln) )
> > 
> > (defun torium-hash-table (hash-table &optional bfrn)
> > "Print HASH-TABLE to the buffer BFRN."
> > 
> > (let* ( (bfname (or bfrn "Torium Hash Table"))
> > (dbuffer (get-buffer-create (concat "𒆳 " bfname))) )
> > 
> > (with-current-buffer dbuffer
> > (maphash (lambda (key value)
> > (let* ( (start (point)) )
> > (insert (format " ━ %-8s" key))
> > (insert (format "\n %s\n" value))))
> > hash-table))))
> > 
> > I am getting the following error and cannot figure out how I can get out of it.
> > 
> > Debugger entered--Lisp error: (wrong-type-argument hash-table-p (("MRSHL") ("NAPLN") ("FLKTR") ("GLXKS") ("ARKTK" . t)))
> > maphash((closure (t) (key value) (let* ((start (point))) (insert (format " ━ %-8s" key)) (add-text-properties start (point) '(face (:foreground "green"))) (insert (format "\n %s\n" value)))) (("MRSHL") ("NAPLN") ("FLKTR") ("GLXKS") ("ARKTK" . t)))
> 
> 
> [rest of stack trace removed]
> 
> Please, do some homework. This helps people help you (this is actually
> why I, at some point, stopped trying). Moreover, your (for the rest of
> us) inscrutable variable names aren't helping.
> 
> Asking for programming help involves trying to help your helpers to
> understand your problem. I feel that you aren't doing this (for whatever
> reason). This will impair the quality of answers you get.
> 
> And third, you really, really should try to gain some more understanding
> and practice with small Lisp code snippets. I have the impression that
> you only half-grasped very basic concepts and run into the same kind of
> problems time and again. Every bit you invest in the basics will pay back
> hundredfold (and will motivate your potential helpers).
> 
> OK, that said, let's try to decode the two first lines of the error message
> (I reformat them to make them fit a civilised window width and to highlight
> their structure). Notes inline, prefixed with #. They are numbered to ref
> to them further down.
> 
> > Debugger entered--Lisp error:
> 
> # (1) The lisp run time has signalled an error, and the debugger is reporting that:
> 
> > (wrong-type-argument hash-table-p
> 
> # (2) Some function expects an argument satisfying the predicate hash-table-p and
> # has got instead...
> 
> > (("MRSHL") ("NAPLN") ("FLKTR") ("GLXKS") ("ARKTK" . t)))
> 
> # (3) ...something which looks a lot like an alist (the four first entries are associated
> # to nil, that's why they possibly look like singletons)
> 
> Ad (2): Which function could that be? Look again at your code.
> The only one I see is that maphash, restated (and abbreviated)
> here:
> 
> > (maphash (lambda (key value) ...) hash-table)
> 
> 
> It gets two args (which corresponds to the doc). The first one
> is the function to be iterated. The second is hash-table, which,
> according to the doc, is expected to be a hash table.
> 
> Now where is that one coming from? It is passed as a param to your
> torium-hash-table: we don't see how you are calling that one. I
> conclude that (unless I've missed something) the error cause is
> outside the code snippet you show us.
> 
> Cheers
> --
> t

You are right.  Have not worked with hash-tables before.  Still, when I 
post some code I shall change the names to be easier to follow through.




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

end of thread, other threads:[~2024-09-23 12:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <<slrnm95tki.h18.joost.m.kremers@j.kremers4.news.arnhem.chello.nl>
2014-12-18 15:53 ` Printing a hash table Drew Adams
2024-09-23  2:30 Heime
2024-09-23  6:32 ` tomas
2024-09-23 12:10   ` Heime
  -- strict thread matches above, loose matches on Subject: below --
2014-12-18 15:45 Joost Kremers
     [not found] ` <mailman.16411.1418918006.1147.help-gnu-emacs@gnu.org>
2014-12-18 19:27   ` Joost Kremers

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.