all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Heime <heimeborgia@protonmail.com>
To: Heime via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Validates an input hash table to produce another  hash table
Date: Mon, 23 Sep 2024 12:53:48 +0000	[thread overview]
Message-ID: <045vsV4zba-aOiZxE1FZZ6CgM0lFu4rDfdmlnILd0l8jqCDRVO56p8l_Vy8yBJ_6bTFZtVjAIYJ5QCS9sLIJxZozEdMA890ngVpCNqcYBbk=@protonmail.com> (raw)

I am writing that validates an input hash table to produce another 
hash table with the result (replacing the directory path with the 
validation value).

(defun path-validation (input-table)

  (cond

      ((hash-table-p input-table)

      ;; Make hash-table for output
      (let ( (output-table (make-hash-table :test 'equal)) )
        (maphash (lambda (key dirpath)
                   (puthash key (not (file-directory-p dirpath)) output-table))
                 input-table)
        output-table))

      (t
         (mapcar (lambda (entry)
              (let ( (key  (car entry))
                     (dirpath  (cdr entry)) )
                (cons key (not (file-directory-p dirpath)))) )
            input-table)) ))


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

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

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


(let ( (input-table (make-hash-table :test 'equal)) )

  (puthash "home-dir" "/home/user" input-table)
  (puthash "docs-dir" "/home/user/Documents" input-table)
  (puthash "fake-dir" "/non/existing/path" input-table)

  (print-hash-table input-table "Input Table")

  (let ( validation-table (path-validation input-table) )
    (print-hash-table validation-table "Output Table")  ; <== Problem Here
    (message "Done"))

  (message "Done"))




             reply	other threads:[~2024-09-23 12:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-23 12:53 Heime [this message]
2024-09-23 13:14 ` Validates an input hash table to produce another hash table Yuri Khan
2024-09-23 19:11   ` Heime

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='045vsV4zba-aOiZxE1FZZ6CgM0lFu4rDfdmlnILd0l8jqCDRVO56p8l_Vy8yBJ_6bTFZtVjAIYJ5QCS9sLIJxZozEdMA890ngVpCNqcYBbk=@protonmail.com' \
    --to=heimeborgia@protonmail.com \
    --cc=help-gnu-emacs@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.