<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type><BASE
href="x-msg://1444/">
<META name=GENERATOR content="MSHTML 8.00.6001.18928">
<STYLE></STYLE>
</HEAD>
<BODY
style="WORD-WRAP: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space"
bgColor=#ffffff>
<DIV><FONT size=2 face=Arial>Interesting. How does the pattern matcher do that?
I tried comparing two solutions in terms of performance (see below, group
1&4 (naive approach) against 2&3 (matching approach)), and aside from
the fact that I get somewhat inconsistent results (when I run the test suite
several times after one another, I would expect comparable result every time but
don't seem to accomplish those even though calling collect-garbage should get me
a "clean state" every time), it appears that neither #2 or #3 (#3
being taken from the docs) appears to be significantly worse than #1 or
#4 even though the pattern matching and substitution process is expectedly
rather sophisticated (and thus more resource consuming)?</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>P.S. #4 only added for the sake of comparison
between the list and '(,...) implementations.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>(define (switch-one-and-three1
ls)<BR> (list (caddr ls)(cadr ls)(car ls)))</FONT></DIV>
<DIV> </DIV><FONT size=2 face=Arial>
<DIV><BR>(define (switch-one-and-three2 ls)<BR> (match
ls<BR> [`(,one ,two ,three) `(,three ,two ,one)]))</DIV>
<DIV> </DIV>
<DIV>(define (switch-one-and-three3 ls)<BR> (match
ls<BR> [(list a b c) (list c b a)]))</DIV>
<DIV> </DIV>
<DIV>(define (switch-one-and-three4 ls)<BR> `(,(caddr ls)
,(cadr ls) ,(car ls)))<BR> <BR> <BR> <BR>(define iterate (lambda
(ct thunk)
<BR>
(if (zero? ct)
<BR>
#t (begin (thunk) (iterate (- ct 1) thunk)))))</DIV>
<DIV> </DIV>
<DIV>(define (thunk1) (switch-one-and-three1 '(a b c)))</DIV>
<DIV> </DIV>
<DIV>(define (thunk2) (switch-one-and-three2 '(a b c)))</DIV>
<DIV> </DIV>
<DIV>(define (thunk3) (switch-one-and-three3 '(a b c)))</DIV>
<DIV> </DIV>
<DIV>(define (thunk4) (switch-one-and-three4 '(a b c)))</DIV>
<DIV> </DIV>
<DIV><BR>(collect-garbage)
<BR> <BR>(time (iterate 10000000
thunk1))</DIV>
<DIV> </DIV>
<DIV>(collect-garbage) </DIV>
<DIV> </DIV>
<DIV>(time (iterate 10000000 thunk2))</DIV>
<DIV> </DIV>
<DIV>(collect-garbage) </DIV>
<DIV> </DIV>
<DIV>(time (iterate 10000000 thunk3))</DIV>
<DIV> </DIV>
<DIV>(collect-garbage) </DIV>
<DIV> </DIV>
<DIV>(time (iterate 10000000 thunk4))<BR></FONT></DIV><FONT size=2 face=Arial>
<DIV></FONT> </DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="FONT: 10pt arial; BACKGROUND: #e4e4e4; font-color: black"><B>From:</B>
<A title=matthias@ccs.neu.edu href="mailto:matthias@ccs.neu.edu">Matthias
Felleisen</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=afowler2@broncos.uncfsu.edu
href="mailto:afowler2@broncos.uncfsu.edu">Ashley Fowler</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Cc:</B> <A title=users@racket-lang.org
href="mailto:users@racket-lang.org">users@racket-lang.org</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Wednesday, September 05, 2012 8:29
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [racket] Question</DIV>
<DIV><BR></DIV>
<DIV>
<DIV>#lang racket</DIV>
<DIV><BR></DIV>
<DIV>(require rackunit)</DIV>
<DIV><BR></DIV>
<DIV>;; [List X Y Z] -> [List Z Y X]</DIV>
<DIV>;; switch items one and three in a 3-element list </DIV>
<DIV><BR></DIV>
<DIV>(module+ test </DIV>
<DIV> (check-equal? (switch-one-and-three1 '(a b c)) '(c b a))</DIV>
<DIV> (check-equal? (switch-one-and-three1 '(1 2 3)) '(3 2 1)))</DIV>
<DIV><BR></DIV>
<DIV>(define (switch-one-and-three1 ls)</DIV>
<DIV> (match ls</DIV>
<DIV> [`(,one ,two ,three) `(,three ,two ,one)]))</DIV>
<DIV><BR></DIV>
<DIV>That's 50$ -- Matthias</DIV></DIV>
<DIV><BR></DIV><BR>
<DIV>
<DIV>On Sep 5, 2012, at 2:26 PM, Ashley Fowler wrote:</DIV><BR
class=Apple-interchange-newline>
<BLOCKQUOTE type="cite">
<DIV ocsi="0" fpstyle="1">
<DIV
style="FONT-FAMILY: Tahoma; DIRECTION: ltr; COLOR: rgb(0,0,0); FONT-SIZE: 10pt"><SPAN
style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; DISPLAY: inline !important; FONT: 13px Tahoma; WHITE-SPACE: normal; ORPHANS: 2; FLOAT: none; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">Can
anybody help me with this problem? I have an idea but would like some
suggestions on how to start. The problem is below...</SPAN>
<DIV
style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 13px Tahoma; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"><BR></DIV>
<DIV
style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 13px Tahoma; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"><PRE style="WORD-WRAP: break-word; WHITE-SPACE: pre-wrap"><B>Write a procedure (switch-one-and-three1 LS) that takes a list of
exactly three items as its argument and returns the list with the first
and third items switched around. You may assume the input list contains
exactly three items</B></PRE></DIV></DIV>____________________<BR> Racket
Users list:<BR> <A
href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</A><BR></DIV></BLOCKQUOTE></DIV><BR>
<P>
<HR>
<P></P>____________________<BR> Racket Users list:<BR>
http://lists.racket-lang.org/users<BR></BLOCKQUOTE></BODY></HTML>