[plt-scheme] Okay, this is ugly

From: Gregory Woodhouse (gregory.woodhouse at sbcglobal.net)
Date: Sat Feb 18 03:13:12 EST 2006

The idea here is that env is a list of hash tables (created, for  
example, by let), and when looking up a symbol, I want to start with  
the car of env and return the binding I find there (if there is one).  
Otherwise, I want to keep looking by repeating the process using the  
cdr of env, until it's empty.

The following code seems to work, but it's ugly because it uses the  
failure thunk of hash-table-get to return #<void> if no binding is  
found, and then uses this as a kind of sentinel value to indicate  
that the code should recur on the list.

(define (env-get-binding s env)
   (call/cc
    (lambda (k)
      (if (null? env) k (void))
      (let ((t (hash-table-get (car env) s (lambda () (void)))))
        (unless (void? t) (k t)
          (env-get-binding s (cdr env)))))))

Using sentinel values like this seems unidiomatic and rather awkward.  
Surely, there is a cleaner (clearer?) way to do this.

==
Gregory Woodhouse
gregory.woodhouse at sbcglobal.net

"If you give someone Fortran, he has Fortran.
If you give someone Lisp, he has any language he pleases."
--Guy L. Steele, Jr.






Posted on the users mailing list.