chickadee » moremacros » hash-let

(hash-let HASH-TABLE (VAR | (VAR) | (VAR KEY [DEFAULT]) ...) BODY ...)syntax

Decompose HASH-TABLE entries into variable bindings. Should the KEY not be a symbol, or the desired variable name VAR is not the key, the (VAR KEY [DEFAULT]) form can be used.

The default value for a missing hash-table entry is #f but can be specified with the (VAR KEY DEFAULT) form.

The BODY... is evaluated with the specified bindings.

(import hash-let (srfi 69))

(let ((tbl (make-hash-table)))
  (hash-table-set! tbl 'abc "commercial network")
  (hash-table-set! tbl "nbc" "commercial network")
  (hash-let tbl
    ((abc)                              ;key symbol 'abc
     (cbs "nbc")                        ;supplied string key
     (pbs (string-append "p" "bs") #t)  ;default value for missing "pbs"
     tbs)                               ;missing key symbol 'tbs
    (print 'abc " is a " abc)
    (print "cbs" " is a " cbs)
    (print (string-append "p" "bs") " is a " pbs)
    (print 'tbs " is a " tbs) ) )
abc is a commercial network
cbs is a commercial network
pbs is a #t
tbs is a #f