[racket] Enhancing a macro
Thanks Jeremiah!
I took your idea and modified it slightly so that the let**-debug is
in the body of the parameterize. It works great.
Cheers,
Harry
(define indent-size (make-parameter 0))
(define-syntax let**-debug
(syntax-rules ()
[(let**-debug tmp a ...) (parameterize ([indent-size (+ (indent-size) 5)])
(let**-dbg tmp a ...))]))
(define-syntax let**-dbg
(syntax-rules ()
[(_ tmp body)
(begin (display (make-string (indent-size) #\space))
(displayln 'body)
(time (begin0 body (display (make-string (indent-size)
#\space)) )))]
[(_ tmp a b ... body)
(let ([tmp (begin (display (make-string (indent-size) #\space))
(displayln 'a)
(time (begin0 a (display (make-string
(indent-size) #\space)))))])
(let**-dbg tmp b ... body))]))
On Wed, Aug 22, 2012 at 8:57 PM, Jeremiah Willcock <jewillco at osl.iu.edu> wrote:
> On Wed, 22 Aug 2012, Harry Spier wrote:
>
>> I have a macro let**-debug (based on the let** macro from Matthias
>> Felliesen) which gives me timing information.
>>
>> (define-syntax let**-debug
>> (syntax-rules ()
>> [(_ tmp body) (begin (displayln 'body) (time body))]
>> [(_ tmp a b ... body) (let ([tmp (begin (displayln 'a) (time a))])
>> (let**-debug tmp b ... body))]))
>>
>> It works fine. The idea is that I tune using the form let**-debug and
>> when I'm happy with the results I change let**-debug to let** which
>> still works the same without printing the timing information.
>
>
> What about using a parameter:
>
> (define timing-indent-level (make-parameter 0))
>
>
> (define-syntax let**-debug
> (syntax-rules ()
> [(_ tmp body)
> (begin (displayln 'body)
> (time (begin0 (display (make-string (timing-indent-level)
> #\space)) body)))]
>
> [(_ tmp a b ... body)
> (let ([tmp (begin (displayln 'a)
> (time (begin0
> (parameterize ([timing-indent-level (+ 2
> (timing-indent-level))]) a)
> (display (make-string (timing-indent-level)
> #\space)))))])
>
> (let**-debug tmp b ... body))]))
>
> This assumes that the operation that you're timing is cheap compared to
> printing things out and modifying parameters. If it's not, you may need to
> use time-apply and print out the results yourself.
>
> -- Jeremiah Willcock