<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 9.00.8112.16443">
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2 face=Arial>Matthias Felleisen <matthias@...>
writes:</FONT></DIV>
<DIV><FONT size=2 face=Arial>. <BR>> <BR>> If this is about sequencing a
bunch of functional manipulations, try this: <BR>> <BR>> #lang
racket<BR>> <BR>> ;; this would be in a library<BR>> <BR>>
(define-syntax let**<BR>> (syntax-rules
()<BR>> [(_ tmp body)
body]<BR>> [(_ tmp a b ... body) (let ([tmp a])
(let** tmp b ... body))]))<BR>> <BR>> ;;
-----------------------------------------------------------------------------<BR>>
<BR>> (define (fix str)<BR>> (let** tmp
str<BR>>
(regexp-replace* " / " tmp
"_")<BR>>
(regexp-replace* " " tmp
"_")<BR>>
(regexp-replace* "%" tmp
"")<BR>>
(regexp-replace* "-" tmp
"_")<BR>>
(string-upcase tmp)))<BR>> <BR>> (fix "this/is%a-test right?")<BR>>
<BR>> I have found this useful and readable in circumstances where the above
is a sequence of say image<BR>> manipulations where even a for/fold isn't
quite right. <BR>> </FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2 face=Arial>Using this macro that Matthias shared I made a nice
little "tuning tool". </FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>I added the macro form let** to a
library and then created a "companion macro" let-debug** which was similar but
which printed out the manipulating procedure name.and wrapped
the manipulating procedure with the "time" function
I.e.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>(define-syntax let-debug**<BR> (syntax-rules
()<BR> [(_ tmp body) (begin (displayln 'body) (time
body))]<BR> [(_ tmp a b ... body) (let ([tmp (begin (displayln
'a) (time a))]) (let-debug** tmp b ... body))]))<BR></FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>So I write something like:</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>(let-debug** data image-data</FONT></DIV>
<DIV><FONT size=2 face=Arial>
(image->transformation1 data)</FONT></DIV>
<DIV><FONT size=2 face=Arial>
(transformation1->transformation2 data)</FONT></DIV>
<DIV><FONT size=2 face=Arial>
(transformation2->transformation3 data)</FONT></DIV>
<DIV><FONT size=2 face=Arial> etc.
etc.)</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>This then prints out each procedure name and the
cpu, garbage collection and actual time it uses. I can then see any
inefficiencies and once I've fixed these, instead of having to take out a bunch
of "display" and "time" functions I just have to change one word in my
code " let-debug** " back to " let** " to stop
printing the debugging information and be back in production
code.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>Harry Spier</DIV>
<DIV><BR></DIV></FONT></BODY></HTML>