<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I was at a CS education conference over the weekend, and saw a number of people showing off the things their students can do to images in the first week or two of class in Python. &nbsp;For the most part, these operations boil down to (not real Python syntax)<div><br><div><span class="Apple-tab-span" style="white-space:pre">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</span>for i = 1 to image.height</div><div><span class="Apple-tab-span" style="white-space:pre">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</span>for j = 1 to image.width</div><div><span class="Apple-tab-span" style="white-space:pre">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</span>image.pixel[i,j] = some modification of image.pixel[i,j]</div><div><br></div><div>Of course, as everyone on this list knows, the loops are a distraction from what's really going on: we don't actually care in what order the pixels are processed, as long as they all get processed and the results put together.</div><div><br></div><div>So to be able to beat the Pythonistas at this game, a Schemer would need</div><div><br></div><div>; map-image : (color -&gt; color) image -&gt; image</div><div><br></div><div>or better yet</div><div><br></div><div>; map-image : (x y color -&gt; color) image -&gt; image</div><div><br></div><div>which allows you to easily write, for example, a color gradient transform.</div><div><br></div><div>Of course, that only builds images the same size and shape as the original image, and each pixel of the result can only depend on the corresponding pixel of the original (you can't write smoothing, edge detection, shadowing, etc.) &nbsp;So one would also want the more general function</div><div><br></div><div>; build-image : width height (x y -&gt; color) -&gt; image</div><div><br></div><div>But if I want my students to be able to use this before they've seen local or lambda, I would want them to be able to specify "side parameters" (which are curried in before calling the above version):</div><div><br></div><div>; build-image : width height (x y . others -&gt; color) . others -&gt; image</div><div><br></div><div>I think I can figure out how to do most of this, although I'm sure it would be done quicker and better if some of the PLT image gurus out there wanted to help :-)</div><div><br></div><div>But here's the part I'm having trouble with. &nbsp;In most applications of build-image,&nbsp;some or all of the "others" will be images, and the user-provided function will want to call</div><div><br></div><div>; get-pixel : x y image -&gt; color</div><div><br></div><div>on them. &nbsp;In order to "get-pixel", you need to render the 2htdp/images to bitmaps, and it makes sense to do that only once before doing presumably hundreds or thousands of get-pixel calls. &nbsp;Which I could do easily if I knew that get-pixel would ONLY be called on a bitmap, but the natural, beginner-friendly API would have it callable on _any_ 2htdp/image.</div><div><br></div><div>The solution that springs to my mind (alternative suggestions cheerfully welcomed!) is for image% to have a bitmap field, initially empty, which is cached the first time the image is rendered. &nbsp;This could be a good idea for other performance reasons too, but as far as I can tell it isn't currently being done. &nbsp;(It could also be a memory hog; one might want to mark these caches as "expendable" for garbage-collection purposes.)</div><div><br></div><div><br></div><div>How much of this is a good idea? &nbsp;How much is completely off base?</div></div><br><br><div> <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div>Stephen Bloch</div><div><a href="mailto:sbloch@adelphi.edu">sbloch@adelphi.edu</a></div><div><br class="webkit-block-placeholder"></div></span><br class="Apple-interchange-newline"> </div><br></body></html>