On Thu, Aug 20, 2009 at 3:05 PM, Eduardo Cavazos<[email protected]>
wrote:

Sometimes I want the convenience of anamorphic 'if', but the version which
always uses the symbol 'it' seems funny.

I'm experimenting with a variant; here's an example:

Grant Rettke wrote:

How do you feel about the results of your experiment?

So far so good. Here's a slight variation. Instead of the 'is' keyword I'm using '->'. So to bind to a variable, use '->'. To pass to a procedure (like in 'cond') use '=>'.

(library (dharmatech misc if)

  (export if)

  (import (rename (rnrs) (if rnrs:if)))

  (define-syntax if

    (syntax-rules (-> =>)

      ( (if test -> var then else)

        (let ((var test))

          (rnrs:if var then else)) )

      ( (if test -> var then)

        (let ((var test))

          (rnrs:if var then)) )

      ( (if test => then else)

        (let ((val test))

          (rnrs:if val (then val) else)) )

      ( (if test => then)

        (let ((val test))

          (rnrs:if val (then val))) )

      ( (if test then else)

        (rnrs:if test then else) )

      ( (if test then)

        (rnrs:if test then) )))

  )

Reply via email to