<meta charset="utf-8"><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 12.5px; "><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 12.5px; border-collapse: collapse; ">I adapted the Sierpinski example from the <a href="http://racket-lang.org">racket-lang.org</a> home page for Intermediate Student Language. The parameter represents recursive depth, which requires no division and a single local definition. If it weren't for the local, this would be a BSL program:</span></div>
<div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 12.5px; "><br></div><div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;">(require 2htdp/image)</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;"><br></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;">;; Examples</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;">(define st0 (triangle 16 'solid 'red))</span></font></div><div>
<font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;">(define st1 (above st0 (beside st0 st0)))</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;"><br>
</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;">;; Tests</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;">(check-expect (ski 0) st0)</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;">(check-expect (ski 1) st1)</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;"><br>
</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;">;; number -> image</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;">;; Draws Sierpinski Triangle to given recursive depth</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;">(define (ski n)</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;"> (cond</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;"> [(zero? n) (triangle 16 'solid 'red)]</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;"> [else (local ((define next (ski (- n 1))))</span></font></div><div>
<font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;"> (above next (beside next next)))]))</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;"><br>
</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;">;; Draw Sierpinski Triangles to different recursive depths</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;">(ski 0)</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;">(ski 1)</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;">(ski 2)</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;">(ski 3)</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;"><br></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif" size="5"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 18px;"><br>
</span></font></div><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 12.5px; "><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 12.5px; border-collapse: collapse; ">Hope this helps,</span></div>
<div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 12.5px; "><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 12.5px; border-collapse: collapse; ">Marc</span></div>
<div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 12.5px; "><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 12.5px; border-collapse: collapse; "><br></span></div>
<div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 12.5px; "><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 12.5px; border-collapse: collapse; "><br></span></div>
<div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 12.5px; "><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 12.5px; border-collapse: collapse; "><meta charset="utf-8"><span class="Apple-style-span" style="font-size: 12.5px; ">Gregor Kiczales wrote:</span></span></div>
<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif" size="4"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 15px;">Date: Sat, 30 Oct 2010 21:18:43 -0700</span></font></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;">From: Gregor Kiczales <</span></font><a href="mailto:gregor@cs.ubc.ca"><font class="Apple-style-span" color="#000000" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;">gregor@cs.ubc.ca</span></font></a><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;">></span></font></blockquote>
<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;">To: </span></font><a href="mailto:users@racket-lang.org"><font class="Apple-style-span" color="#000000" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;">users@racket-lang.org</span></font></a></blockquote>
<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;">Subject: [racket] 2htdp/image Sierpinski</span></font></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;">Message-ID: <</span></font><a href="mailto:EFC7275A-B06E-463F-AE96-EA9E0C36CCC7@cs.ubc.ca"><font class="Apple-style-span" color="#000000" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;">EFC7275A-B06E-463F-AE96-EA9E0C36CCC7@cs.ubc.ca</span></font></a><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;">></span></font></blockquote>
<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;">Content-Type: text/plain; charset=us-ascii</span></font></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<br></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;">In 2htdp/image the implementations of Sierpinski triangle and carpet are nice and simple, which is great for using them in class.</span></font></blockquote>
<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<br></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<br></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;">(define (carpet size c)</span></font></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;"> (if (<= size 2)</span></font></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;"> (square size "outline" c)</span></font></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;"> (local [(define sub (carpet (/ size 3) c))</span></font></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;"> (define ctr (square (/ size 3) "solid" "white"))]</span></font></blockquote>
<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;"> (overlay (square size "outline" c)</span></font></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;"> (above (beside sub sub sub)</span></font></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;"> (beside sub ctr sub)</span></font></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;"> (beside sub sub sub))))))</span></font></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<br></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;">But... (carpet 200 "red") produces some strange behavior on my Mac. (carpet 300 "red") is even worse. The image draws very slowly, which I assume comes from the way the image is actually composed of all the composed images rather than a single bitmap. But, stranger than that, it seems to need to draw itself several times.</span></font></blockquote>
<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<br></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;">Also I would have thought that 'forcing' the image by actually drawing it would save the bitmap so that future drawing was faster. But I may not understand how this is actually working.</span></font></blockquote>
<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<br></blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: medium;">Is this style of using above, beside and friends to make something this big intended to work? Or is there a different style I should be using?</span></font></blockquote>
<br>