[plt-scheme] Newbie macro problem

From: John Clements (clements at brinckerhoff.org)
Date: Fri Nov 1 16:29:47 EST 2002

On Friday, November 1, 2002, at 04:01  PM, Robert Bruce Findler wrote:

> At Fri, 1 Nov 2002 13:55:40 -0500, John Clements wrote:
>> (define (flex-format str . rest)
>>    (with-handlers ([exn:application:mismatch?
>>                     (lambda (exn)
>>                       (apply flex-format str (reverse (cdr (reverse
>> rest)))))])
>>      (apply format str rest)))
>>
>>
>> No 'count-format-arguments' required.
>>
>> And very elegant, I might add.
>
> Yikes! Take away this guy's PLT shirt!
>
> Robby
>
> PS: seriously, it seems easier to read the other version and it is
> probably much more efficient. This version does have better "single
> point of control" but I'm not sure that is relatively important given
> the loss in readability and a good test suite for flex-format.
>

Oh, piffle.  Have you seen my new compiler?

(define (my-compiler input desired-result)
   (let outer-loop ()
     (let ([compiled
            (let loop ()
              (case (random 3)
                ((0) null)
                ((1) (random-symbol))
                ((2) (cons (loop) (loop)))))])
       (try-compiled compiled desired-result)
       (outer-loop))))

(define (try-compiled sexp desired-result)
   (when (equal? (eval sexp) desired-result)
     (begin (printf "is this the s-expression you're looking for?\n~v\n" 
sexp)
            (abort))))




Posted on the users mailing list.