all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Output hash-table from a function
@ 2024-09-21 22:34 Heime
  2024-09-22 11:47 ` Heime
  0 siblings, 1 reply; 10+ messages in thread
From: Heime @ 2024-09-21 22:34 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

I want to have the function output a hash-table.  This is how I do it.

(defun torium-anctr (fpln)

  (if (hash-table-p fpln)
      (let ( (anctr (make-hash-table :test 'equal)) )
        (maphash (lambda (waypt dirpath)
                   (puthash waypt (not (file-directory-p dirpath)) anctr))
                 fpln)) ))

But when I run the next function I get "[Anctr] alist" instead of "[Anctr] hash-table".
It seems that the output torium-anctr is not a hash-table as I had hoped.

(defun torium-chart (fpln anctr &optional bfrn)

  (let* ( (bfname (or bfrn "torium F-Pln"))
          (dbuffer (get-buffer-create bfname)) )

    (with-current-buffer dbuffer
      (erase-buffer)

      (insert (format "[Fpln]  %s\n"
        (if (hash-table-p fpln) "hash-table" "alist")))
      (insert (format "[Anctr] %s\n"
        (if (hash-table-p anctr) "hash-table" "alist"))) )))




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

* Output hash-table from a function
  2024-09-21 22:34 Output hash-table from a function Heime
@ 2024-09-22 11:47 ` Heime
  2024-09-22 14:46   ` Yuri Khan
  0 siblings, 1 reply; 10+ messages in thread
From: Heime @ 2024-09-22 11:47 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

I have a hash table composed of a set of keys and an associated directory path

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

(defun xiakos-insert ()
  (puthash "GLXKS" xiakos-path xiakos-fpln) )

I want to write a function xiakos-anctr that taking the hash table xiakos, 
produces another hash-table, with the same keys but the associated value
would be 1 (if directory path does not exist) or 0 (if the directory path exists).

(defun xiakos-anctr (fpln)

  (if (hash-table-p fpln)

      (let ( (anctr (make-hash-table :test 'equal)) )
        (maphash (lambda (waypt dirpath)
                   (puthash
                     waypt (not (file-directory-p dirpath))
                     anctr))
                 fpln)) ))
  






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

* Re: Output hash-table from a function
  2024-09-22 11:47 ` Heime
@ 2024-09-22 14:46   ` Yuri Khan
  2024-09-22 15:16     ` Heime
  0 siblings, 1 reply; 10+ messages in thread
From: Yuri Khan @ 2024-09-22 14:46 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

On Sun, 22 Sept 2024 at 18:48, Heime <heimeborgia@protonmail.com> wrote:

> I want to write a function xiakos-anctr that taking the hash table xiakos,

You should really start naming your functions, arguments and variables
using words rather than random sequences.

> produces another hash-table, with the same keys but the associated value
> would be 1 (if directory path does not exist) or 0 (if the directory path exists).
>
> (defun xiakos-anctr (fpln)
>
>   (if (hash-table-p fpln)
>
>       (let ( (anctr (make-hash-table :test 'equal)) )
>         (maphash (lambda (waypt dirpath)
>                    (puthash
>                      waypt (not (file-directory-p dirpath))
>                      anctr))
>                  fpln)) ))

Hint 1: What does your function to return right now?

Hint 2: You’ve created a hash table, bound it to a local variable,
then did a bunch of mutations to that hash table, and then what?



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

* Re: Output hash-table from a function
  2024-09-22 14:46   ` Yuri Khan
@ 2024-09-22 15:16     ` Heime
  2024-09-22 15:54       ` Yuri Khan
  0 siblings, 1 reply; 10+ messages in thread
From: Heime @ 2024-09-22 15:16 UTC (permalink / raw)
  To: Yuri Khan; +Cc: Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

On Monday, September 23rd, 2024 at 2:46 AM, Yuri Khan <yuri.v.khan@gmail.com> wrote:

> On Sun, 22 Sept 2024 at 18:48, Heime heimeborgia@protonmail.com wrote:
> 
> > I want to write a function xiakos-anctr that taking the hash table xiakos,
> 
> 
> You should really start naming your functions, arguments and variables
> using words rather than random sequences.

They are not random sequences as you say, but that's fine.
 
> > produces another hash-table, with the same keys but the associated value
> > would be 1 (if directory path does not exist) or 0 (if the directory path exists).
> > 
> > (defun xiakos-anctr (fpln)
> > 
> > (if (hash-table-p fpln)
> > 
> > (let ( (anctr (make-hash-table :test 'equal)) )
> > (maphash (lambda (waypt dirpath)
> > (puthash
> > waypt (not (file-directory-p dirpath))
> > anctr))
> > fpln)) ))
> 
> 
> Hint 1: What does your function to return right now?

xiakos-anctr is certainly not returning a hash table, as I wanted
 
> Hint 2: You’ve created a hash table, bound it to a local variable,
> then did a bunch of mutations to that hash table, and then what?

I want to call the function and store the hash table result in a let statement

(let ( (anctr (xiakos-anctr flpn)) )
  (do-this flpn anctr)
  (do-that flpn anctr))



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

* Re: Output hash-table from a function
  2024-09-22 15:16     ` Heime
@ 2024-09-22 15:54       ` Yuri Khan
  2024-09-22 15:59         ` Heime
  0 siblings, 1 reply; 10+ messages in thread
From: Yuri Khan @ 2024-09-22 15:54 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

On Sun, 22 Sept 2024 at 22:16, Heime <heimeborgia@protonmail.com> wrote:

> > > (defun xiakos-anctr (fpln)
> > >
> > > (if (hash-table-p fpln)
> > >
> > > (let ( (anctr (make-hash-table :test 'equal)) )
> > > (maphash (lambda (waypt dirpath)
> > > (puthash
> > > waypt (not (file-directory-p dirpath))
> > > anctr))
> > > fpln)) ))
> >
> > Hint 1: What does your function to return right now?
>
> xiakos-anctr is certainly not returning a hash table, as I wanted

You are not answering the question. I am asking it because by
answering it you will get closer to understanding the root of your
issue. So, what *is* it returning?

> > Hint 2: You’ve created a hash table, bound it to a local variable,
> > then did a bunch of mutations to that hash table, and then what?
>
> I want to call the function and store the hash table result in a let statement
>
> (let ( (anctr (xiakos-anctr flpn)) )

This assumes xiakos-anctr returns the hash table. But, as you have
seen, it does not return it. So what *happens* to the hash table you
created in xiakos-anctr?



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

* Re: Output hash-table from a function
  2024-09-22 15:54       ` Yuri Khan
@ 2024-09-22 15:59         ` Heime
  2024-09-22 16:03           ` Heime
  2024-09-23  5:57           ` tomas
  0 siblings, 2 replies; 10+ messages in thread
From: Heime @ 2024-09-22 15:59 UTC (permalink / raw)
  To: Yuri Khan; +Cc: Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

On Monday, September 23rd, 2024 at 3:54 AM, Yuri Khan <yuri.v.khan@gmail.com> wrote:

> On Sun, 22 Sept 2024 at 22:16, Heime heimeborgia@protonmail.com wrote:
> 
> > > > (defun xiakos-anctr (fpln)
> > > > 
> > > > (if (hash-table-p fpln)
> > > > 
> > > > (let ( (anctr (make-hash-table :test 'equal)) )
> > > > (maphash (lambda (waypt dirpath)
> > > > (puthash
> > > > waypt (not (file-directory-p dirpath))
> > > > anctr))
> > > > fpln)) ))
> > > 
> > > Hint 1: What does your function to return right now?
> > 
> > xiakos-anctr is certainly not returning a hash table, as I wanted
> 
> 
> You are not answering the question. I am asking it because by
> answering it you will get closer to understanding the root of your
> issue. So, what is it returning?

I have made a check with (hash-table-p (xiakos-anctr flpn)) which returns
false.
 
> > > Hint 2: You’ve created a hash table, bound it to a local variable,
> > > then did a bunch of mutations to that hash table, and then what?
> > 
> > I want to call the function and store the hash table result in a let statement
> > 
> > (let ( (anctr (xiakos-anctr flpn)) )
> 
> 
> This assumes xiakos-anctr returns the hash table. But, as you have
> seen, it does not return it. So what happens to the hash table you
> created in xiakos-anctr ?

From what I could conclude, the hash table gets lost.



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

* Re: Output hash-table from a function
  2024-09-22 15:59         ` Heime
@ 2024-09-22 16:03           ` Heime
  2024-09-22 16:56             ` Yuri Khan
  2024-09-23  5:57           ` tomas
  1 sibling, 1 reply; 10+ messages in thread
From: Heime @ 2024-09-22 16:03 UTC (permalink / raw)
  To: Yuri Khan; +Cc: Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

On Monday, September 23rd, 2024 at 3:59 AM, Heime <heimeborgia@protonmail.com> wrote:

> 
> 
> 
> 
> 
> Sent with Proton Mail secure email.
> 
> 
> On Monday, September 23rd, 2024 at 3:54 AM, Yuri Khan yuri.v.khan@gmail.com wrote:
> 
> > On Sun, 22 Sept 2024 at 22:16, Heime heimeborgia@protonmail.com wrote:
> > 
> > > > > (defun xiakos-anctr (fpln)
> > > > > 
> > > > > (if (hash-table-p fpln)
> > > > > 
> > > > > (let ( (anctr (make-hash-table :test 'equal)) )
> > > > > (maphash (lambda (waypt dirpath)
> > > > > (puthash
> > > > > waypt (not (file-directory-p dirpath))
> > > > > anctr))
> > > > > fpln)) ))
> > > > 
> > > > Hint 1: What does your function to return right now?
> > > 
> > > xiakos-anctr is certainly not returning a hash table, as I wanted
> > 
> > You are not answering the question. I am asking it because by
> > answering it you will get closer to understanding the root of your
> > issue. So, what is it returning?
 
I have made a check with (hash-table-p (xiakos-anctr flpn)) which returns
false.

What gets returned is the return from maphash, which is always nil.
 
> > > > Hint 2: You’ve created a hash table, bound it to a local variable,
> > > > then did a bunch of mutations to that hash table, and then what?
> > > 
> > > I want to call the function and store the hash table result in a let statement
> > > 
> > > (let ( (anctr (xiakos-anctr flpn)) )
> > 
> > This assumes xiakos-anctr returns the hash table. But, as you have
> > seen, it does not return it. So what happens to the hash table you
> > created in xiakos-anctr ?
 
From what I could conclude, the hash table gets lost.



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

* Re: Output hash-table from a function
  2024-09-22 16:03           ` Heime
@ 2024-09-22 16:56             ` Yuri Khan
  2024-09-22 17:02               ` Heime
  0 siblings, 1 reply; 10+ messages in thread
From: Yuri Khan @ 2024-09-22 16:56 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

On Sun, 22 Sept 2024 at 23:03, Heime <heimeborgia@protonmail.com> wrote:

> > > > > > (defun xiakos-anctr (fpln)
> > > > > >
> > > > > > (if (hash-table-p fpln)
> > > > > >
> > > > > > (let ( (anctr (make-hash-table :test 'equal)) )
> > > > > > (maphash (lambda (waypt dirpath)
> > > > > > (puthash
> > > > > > waypt (not (file-directory-p dirpath))
> > > > > > anctr))
> > > > > > fpln)) ))
> > > > >
> > > > > Hint 1: What does your function to return right now?
> > > >
> > > > xiakos-anctr is certainly not returning a hash table, as I wanted
> > >
> I have made a check with (hash-table-p (xiakos-anctr flpn)) which returns
> false.
>
> What gets returned is the return from maphash, which is always nil.

Correct.

> > > > > Hint 2: You’ve created a hash table, bound it to a local variable,
> > > > > then did a bunch of mutations to that hash table, and then what?
>
> From what I could conclude, the hash table gets lost.

Also correct.

So what change do you need to fix your xiakos-anctr function?



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

* Re: Output hash-table from a function
  2024-09-22 16:56             ` Yuri Khan
@ 2024-09-22 17:02               ` Heime
  0 siblings, 0 replies; 10+ messages in thread
From: Heime @ 2024-09-22 17:02 UTC (permalink / raw)
  To: Yuri Khan; +Cc: Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

On Monday, September 23rd, 2024 at 4:56 AM, Yuri Khan <yuri.v.khan@gmail.com> wrote:

> On Sun, 22 Sept 2024 at 23:03, Heime heimeborgia@protonmail.com wrote:
> 
> > > > > > > (defun xiakos-anctr (fpln)
> > > > > > > 
> > > > > > > (if (hash-table-p fpln)
> > > > > > > 
> > > > > > > (let ( (anctr (make-hash-table :test 'equal)) )
> > > > > > > (maphash (lambda (waypt dirpath)
> > > > > > > (puthash
> > > > > > > waypt (not (file-directory-p dirpath))
> > > > > > > anctr))
> > > > > > > fpln)) ))
> > > > > > 
> > > > > > Hint 1: What does your function to return right now?
> > > > > 
> > > > > xiakos-anctr is certainly not returning a hash table, as I wanted
> > 
> > I have made a check with (hash-table-p (xiakos-anctr flpn)) which returns
> > false.
> > 
> > What gets returned is the return from maphash, which is always nil.
> 
> 
> Correct.
> 
> > > > > > Hint 2: You’ve created a hash table, bound it to a local variable,
> > > > > > then did a bunch of mutations to that hash table, and then what?
> > 
> > From what I could conclude, the hash table gets lost.
> 
> 
> Also correct.
> 
> So what change do you need to fix your xiakos-anctr function ?

I need to invoke anctr after calling maphash



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

* Re: Output hash-table from a function
  2024-09-22 15:59         ` Heime
  2024-09-22 16:03           ` Heime
@ 2024-09-23  5:57           ` tomas
  1 sibling, 0 replies; 10+ messages in thread
From: tomas @ 2024-09-23  5:57 UTC (permalink / raw)
  To: Heime; +Cc: Yuri Khan, Heime via Users list for the GNU Emacs text editor

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

On Sun, Sep 22, 2024 at 03:59:56PM +0000, Heime wrote:

[...]

> > You are not answering the question. I am asking it because by
> > answering it you will get closer to understanding the root of your
> > issue. So, what is it returning?
> 
> I have made a check with (hash-table-p (xiakos-anctr flpn)) which returns
> false.

Don't run it: read your code and try to answer from that. I'm sure that
was Yuri's intention with his request.

Cheers
-- 
t

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

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

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

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-21 22:34 Output hash-table from a function Heime
2024-09-22 11:47 ` Heime
2024-09-22 14:46   ` Yuri Khan
2024-09-22 15:16     ` Heime
2024-09-22 15:54       ` Yuri Khan
2024-09-22 15:59         ` Heime
2024-09-22 16:03           ` Heime
2024-09-22 16:56             ` Yuri Khan
2024-09-22 17:02               ` Heime
2024-09-23  5:57           ` tomas

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.