[plt-scheme] safe for space idiom

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Sun Mar 30 21:19:08 EDT 2008

Doug Orleans wrote:
> I often find myself in the situation where I want to write code that
> has roughly this shape:
>
> (let loop ()
>   (cond ((and a? b?)
>          b)
>         ((and a? c?)
>          c
>          (loop))
>         (else
>          d
>          (loop))))
>
> The repeated a? test seems ugly, though, and I want to factor it out:
>
>   

If a? takes time, I will have

(let ((a-result a?))
  ...)

otherwise I will just repeat the a? test. The readability of code is 
also very important.

Chongkai


Posted on the users mailing list.