whereas


Erik Naggum came up with this as a generalisation of cond's send-to (=>) operator. See the below thread for details:

http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/5bf62986690dff81/bc7772aa5ab1f3e4?lnk=st&rnum=1#bc7772aa5ab1f3e4

Implementation should be quite easy but debugging will take more time than I have here, so is left as an excercise for the reader :).

Basically, it looks like this:

 (whereas ((a (some-expr)) 
           (b (other-expr))) 
   (some-long-expr-using-b-and-a)) 

If any of the bound variables is #f, whereas immediately returns #f.

One could imagine some obvious (optional) extensions to the above syntax, for example:

 (whereas ((a (some-expr) pair?) 
           (b (other-expr) positive? even?)) 
   (some-long-expr-using-b-and-a)) 

This is reminiscent of Naggum's suggestion of declarations, but a bit more Schemely. The predicates are applied to the variables as soon as they are bound.

Note that including an alternate clause would be confusing and pointless: instead, wrap the WHEREAS with an OR. On second thoughts, that's kind of ugly. Needs more thought.


A similar need is met by and-let*? (srfi:2), if-let?/when-let and, for the particularly masochistic, anaphoric-if.