unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Validates an input hash table to produce another  hash table
@ 2024-09-23 12:53 Heime
  2024-09-23 13:14 ` Yuri Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Heime @ 2024-09-23 12:53 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

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




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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-23 12:53 Validates an input hash table to produce another hash table Heime
2024-09-23 13:14 ` Yuri Khan
2024-09-23 19:11   ` Heime

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