<html><head><metahttp-equiv="content-type"content="text/html; charset=utf-8"/><title>5 First tutorial</title><linkrel="stylesheet"type="text/css"href="scribble.css"title="default"/><linkrel="stylesheet"type="text/css"href="racket.css"title="default"/><linkrel="stylesheet"type="text/css"href="manual-style.css"title="default"/><linkrel="stylesheet"type="text/css"href="manual-racket.css"title="default"/><linkrel="stylesheet"type="text/css"href="mb.scss"title="default"/><scripttype="text/javascript"src="scribble-common.js"></script><scripttype="text/javascript"src="manual-racket.js"></script><!--[if IE 6]><style type="text/css">.SIEHidden { overflow: hidden; }</style><![endif]--></head><bodyid="scribble-racket-lang-org"><divclass="tocset"><divclass="tocview"><divclass="tocviewlist tocviewlisttopspace"><divclass="tocviewtitle"><tablecellspacing="0"cellpadding="0"><tr><tdstyle="width: 1em;"><ahref="javascript:void(0);"title="Expand/Collapse"class="tocviewtoggle"onclick="TocviewToggle(this,"tocview_0");">▼</a></td><td></td><td><ahref="index.html"class="tocviewlink"data-pltdoc="x">Pollen:<spanclass="mywbr"> </span> the book is a program</a></td></tr></table></div><divclass="tocviewsublisttop"style="display: block;"id="tocview_0"><tablecellspacing="0"cellpadding="0"><tr><tdalign="right">1 </td><td><ahref="Installation.html"class="tocviewlink"data-pltdoc="x">Installation</a></td></tr><tr><tdalign="right">2 </td><td><ahref="quick-tour.html"class="tocviewlink"data-pltdoc="x">Quick tour</a></td></tr><tr><tdalign="right">3 </td><td><ahref="Backstory.html"class="tocviewlink"data-pltdoc="x">Backstory</a></td></tr><tr><tdalign="right">4 </td><td><ahref="big-picture.html"class="tocviewlink"data-pltdoc="x">The big picture</a></td></tr><tr><tdalign="right">5 </td><td><ahref="first-tutorial.html"class="tocviewselflink"data-pltdoc="x">First tutorial</a></td></tr><tr><tdalign="right">6 </td><td><ahref="second-tutorial.html"class="tocviewlink"data-pltdoc="x">Second tutorial</a></td></tr><tr><tdalign="right">7 </td><td><ahref="third-tutorial.html"class="tocviewlink"data-pltdoc="x">Third tutorial</a></td></tr><tr><tdalign="right">8 </td><td><ahref="raco-pollen.html"class="tocviewlink"data-pltdoc="x">Using <spanclass="stt">raco pollen</span></a></td></tr><tr><tdalign="right">9 </td><td><ahref="File_formats.html"class="tocviewlink"data-pltdoc="x">File formats</a></td></tr><tr><tdalign="right">10 </td><td><ahref="reader.html"class="tocviewlink"data-pltdoc="x">◊ command overview</a></td></tr><tr><tdalign="right">11 </td><td><ahref="Module_reference.html"class="tocviewlink"data-pltdoc="x">Module reference</a></td></tr><tr><tdalign="right">12 </td><td><ahref="Acknowledgments.html"class="tocviewlink"data-pltdoc="x">Acknowledgments</a></td></tr><tr><tdalign="right">13 </td><td><ahref="License___source_code.html"class="tocviewlink"data-pltdoc="x">License & source code</a></td></tr><tr><tdalign="right"></td><td><ahref="doc-index.html"class="tocviewlink"data-pltdoc="x">Index</a></td></tr></table></div></div><divclass="tocviewlist"><tablecellspacing="0"cellpadding="0"><tr><tdstyle="width: 1em;"><ahref="javascript:void(0);"title="Expand/Collapse"class="tocviewtoggle"onclick="TocviewToggle(this,"tocview_1");">►</a></td><td>5 </td><td><ahref="first-tutorial.html"class="tocviewselflink"data-pltdoc="x">First tutorial</a></td></tr></table><divclass="tocviewsublistbottom"style="display: none;"id="tocview_1"><tablecellspacing="0"cellpadding="0"><tr><tdalign="right">5.1 </td><td><ahref="first-tutorial.html#%28part._tutorial-1._.Prerequisites%29"class="tocviewlink"data-pltdoc="x">Prerequisites</a></td></tr><tr><tdalign="right">5.2 </td><td><ahref="first-tutorial.html#%28part._.The_relationship_of_.Racket___.Pollen%29"class="tocviewlink"data-pltdoc="x">The relationship of Racket & Pollen</a></td></tr><tr><td
</div><divclass="SIntrapara"><ul><li><p>inserting <spanclass="stt">#lang pollen</span> as the first line,</p></li><li><p>adding the <spanclass="stt">.pp</span> file extension,</p></li><li><p>running it through Pollen.</p></li></ul></div></p><blockquoteclass="refpara"><blockquoteclass="refcolumn"><blockquoteclass="refcontent"><p>For more about the Pollen processing modes and how to invoke them, see <ahref="file-types.html"data-pltdoc="x">File</a>.</p></blockquote></blockquote></blockquote><p>“The preprocessor be used with <spanstyle="font-weight: bold">any</span> kind of text-based file?” Right. “But how?” The preprocessor reads the source file, handles any Pollen commands it finds, and lets the rest of the content pass through untouched. To the preprocessor, it’s all just text data. It doesn’t care whether that text represents HTML, CSS, JavaScript, or even <ahref="https://en.wikipedia.org/wiki/TI-BASIC">TI-BASIC</a>.</p><p>One caveat: because the preprocessor only deals with text, the Pollen commands you use in the preprocessor also have to produce text. Moreover, Pollen doesn’t enforce the syntax rules of the underlying file — that’s your responsibility. For instance, Pollen won’t stop you from doing nonsensical things like this:</p><divclass="fileblock"><divclass="SIntrapara"><divclass="fileblock_filetitle"><spanclass="fileblock_filename"><spanclass="stt">"bad-poem.html.pp"</span></span></div></div><divclass="SIntrapara"><divclass="fileblock_filecontent"><divclass="SIntrapara"><blockquoteclass="SCodeFlow"><tablecellspacing="0"cellpadding="0"class="RktBlk"><tr><td><spanclass="RktMeta">#lang</span><spanclass="hspace"> </span><spanclass="RktMeta"></span><ahref="index.html"class="RktModLink"data-pltdoc="x"><spanclass="RktSym">pollen</span></a><spanclass="RktMeta"></span></td></tr><tr><td><spanclass="RktMeta"> </span></td></tr><tr><td><spanclass="RktMeta">The</span><spanclass="hspace"> </span><spanclass="RktMeta">cave</span><spanclass="hspace"> </span><spanclass="RktMeta">is</span><spanclass="hspace"> </span><spanclass="RktMeta">pitch</span><spanclass="hspace"> </span><spanclass="RktMeta">black.</span></td></tr><tr><td><spanclass="RktMeta">Look</span><spanclass="hspace"> </span><spanclass="RktMeta">out</span><spanclass="hspace"> </span><spanclass="RktMeta">for</span><spanclass="hspace"> </span><spanclass="RktMeta">the</span><spanclass="hspace"> </span><spanclass="RktMeta">grue.</span></td></tr><tr><td><spanclass="RktMeta">◊</span><spanclass="RktPn">(</span><spanclass="RktSym">insert-mp3-recording-of-scream</span><spanclass="RktPn">)</span><spanclass="RktMeta"></span></td></tr></table></blockquote></div></div></div></div><p>Pollen will fulfill your request, but the result won’t be valid HTML, because you can’t simply drop binary data in the middle of an HTML file. To paraphrase Mr. Babbage — garbage in, garbage out.</p><p>I’ve encouraged you to mess with the source file, but let’s return it to its original state:</p><divclass="fileblock"><divclass="SIntrapara"><divclass="fileblock_filetitle"><spanclass="fileblock_filename"><spanclass="stt">"/path/to/tutorial/poem.html.pp"</span></span></div></div><divclass="SIntrapara"><divclass="fileblock_filecontent"><divclass="SIntrapara"><blockquoteclass="SCodeFlow"><tablecellspacing="0"cellpadding="0"class="RktBlk"><tr><td><spanclass="RktMeta">#lang</span><spanclass="hspace"> </span><spanclass="RktMeta"></span><ahref="index.html"class="RktModLink"data-pltdoc="x"><spanclass="RktSym">pollen</span></a><spanclass="RktMeta"></span></td></tr><tr><td><spanclass="RktMeta"> </span></td></tr><tr><td><spanclass="RktMeta">The</span><spanclass="hspace"> </span><spanclass="RktMeta">margin</span><spanclass="hspace"> </span><spanclass="RktMeta">is</span><spanclass="hspace"> </span><spanclass="RktMeta">42em.</span></td></tr><tr><td><spanclass="RktMeta"
<br/><spanstyle="font-weight: bold">Ubuntu</span>: ctrl + shift + U, then 25CA</p><h5>5.5.4<tt> </tt><aname="(part._.Racket_basics__if_you_re_not_familiar_)"></a>Racket basics (if you’re not familiar)</h5><p>“But I’ve never used Racket.” Today, you start. Here are the five basic rules of Racket:</p><ol><li><p>The core building block of Racket is the <spanstyle="font-style: italic">expression</span>. An expression can be a value (like <spanclass="RktVal">2</span> or <spanclass="RktVal">"blue"</span>), a variable (like <spanclass="stt">edge</span>), or a function call (like <spanclass="RktPn">(</span><spanclass="RktSym">*</span><spanclass="stt"></span><spanclass="RktSym">inner</span><spanclass="stt"></span><spanclass="RktVal">4</span><spanclass="RktPn">)</span>).</p></li><li><p>Every expression is <spanstyle="font-style: italic">evaluated</span> to produce a value.</p></li><li><p>A variable evaluates to whatever value it holds (so <spanclass="stt">inner</span> would become <spanclass="RktVal">2</span>). A function call evaluates to its return value (so <spanclass="RktPn">(</span><spanclass="RktSym">+</span><spanclass="stt"></span><spanclass="RktVal">1</span><spanclass="stt"></span><spanclass="RktVal">1</span><spanclass="RktPn">)</span> would become <spanclass="RktVal">2</span>).</p></li><li><p>Function calls go between parentheses. Unlike most languages, the function name comes <spanstyle="font-style: italic">first</span>, followed by its arguments (so it’s <spanclass="RktPn">(</span><spanclass="RktSym">*</span><spanclass="stt"></span><spanclass="RktSym">inner</span><spanclass="stt"></span><spanclass="RktVal">4</span><spanclass="RktPn">)</span>, not <spanclass="RktPn">(</span><spanclass="RktSym">inner</span><spanclass="stt"></span><spanclass="RktSym">*</span><spanclass="stt"></span><spanclass="RktVal">4</span><spanclass="RktPn">)</span>). This is called <spanstyle="font-style: italic">prefix notation</span>.</p></li><li><p>Expressions can contain recursively nested expressions. Thus, <spanclass="RktPn">(</span><spanclass="RktSym">*</span><spanclass="stt"></span><spanclass="RktSym">inner</span><spanclass="stt"></span><spanclass="RktVal">4</span><spanclass="RktPn">)</span> could be written <spanclass="RktPn">(</span><spanclass="RktSym">*</span><spanclass="stt"></span><spanclass="RktSym">inner</span><spanclass="stt"></span><spanclass="RktPn">(</span><spanclass="RktSym">+</span><spanclass="stt"></span><spanclass="RktVal">2</span><spanclass="stt"></span><spanclass="RktVal">2</span><spanclass="RktPn">)</span><spanclass="RktPn">)</span> or <spanclass="RktPn">(</span><spanclass="RktSym">*</span><spanclass="stt"></span><spanclass="RktSym">inner</span><spanclass="stt"></span><spanclass="RktPn">(</span><spanclass="RktSym">+</span><spanclass="stt"></span><spanclass="RktPn">(</span><spanclass="RktSym">+</span><spanclass="stt"></span><spanclass="RktVal">1</span><spanclass="stt"></span><spanclass="RktVal">1</span><spanclass="RktPn">)</span><spanclass="stt"></span><spanclass="RktPn">(</span><spanclass="RktSym">+</span><spanclass="stt"></span><spanclass="RktVal">1</span><spanclass="stt"></span><spanclass="RktVal">1</span><spanclass="RktPn">)</span><spanclass="RktPn">)</span><spanclass="RktPn">)</span>.</p></li></ol><blockquoteclass="refpara"><blockquoteclass="refcolumn"><blockquoteclass="refcontent"><p>Newcomers to Racket often gripe about prefix notation and the parentheses. If you need to get it out of your system, go ahead. Keep in mind, however, that it’s not some peculiar affectation, but rather a necessary consequence of rule #1. As you’ll come to learn, rule #1 is where the magic happens.</p></blockquote></blockquote></blockquote><p>That should tell you enough to infer what’s going on in the Pollen commands above:</p><blockquoteclass="SCodeFlow"><tablecellspacing="0"cellpadding="0"class="RktBlk"><tr><td><spanclass="RktMeta">#lang</span><spanclass="hspace"> </sp