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)

(define tbl (make-hash-table))

(hash-table-set! tbl 'abc "commercial network")
(hash-table-set! tbl "abc" "commercial network")
(hash-table-set! tbl 'cbs "commercial network")
(hash-table-set! tbl "cbs" "commercial network")

(hash-let tbl ((abc)
               (cbs "cbs")
               (pbs (string-append "p" "bs") #t)
  (print 'abc " is a " abc) (print "cbs" " is a " cbs)
  (print (string-append "p" "bs") " is a " pbs)
  (print 'tbs " is a " tbs) )

This prints the following:

abc is a commercial network
cbs is a commercial network
pbs is a #t
tbs is a #f