<html><head><metahttp-equiv="content-type"content="text/html; charset=utf-8"/><title>7 Third 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.css"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="tocviewlink"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="tocviewselflink"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>7 </td><td><ahref="third-tutorial.html"class="tocviewselflink"data-pltdoc="x">Third tutorial</a></td></tr></table><divclass="tocviewsublistbottom"style="display: none;"id="tocview_1"><tablecellspacing="0"cellpadding="0"><tr><tdalign="right">7.1 </td><td><ahref="third-tutorial.html#%28part._tutorial-3._.Prerequisites%29"class="tocviewlink"data-pltdoc="x">Prerequisites</a></td></tr><tr><tdalign="right">7.2 </td><td><ahref="third-tutorial.html#%28part._.Pollen_markup_vs__.X.M.L%29"class="tocviewlink"data-pltdoc="x">Pollen markup vs. XML</a></td></tr><tr><tdalign="right">7.3 </td><td
Pollen won’t stop you from calling a function that returns an incompatible value, like <spanclass="RktSym"><ahref="http://docs.racket-lang.org/plot/plotting.html#%28def._%28%28lib._plot%2Fmain..rkt%29._plot%29%29"class="RktValLink"data-pltdoc="x">plot</a></span>, which returns a bitmap image:</p><divclass="fileblock"><divclass="SIntrapara"><divclass="fileblock_filetitle"><spanclass="fileblock_filename"><spanclass="stt">"article.html.pm"</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">◊</span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29"class="RktStxLink"data-pltdoc="x">require</a></span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktSym">math</span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/plot/plotting.html#%28def._%28%28lib._plot%2Fmain..rkt%29._plot%29%29"class="RktValLink"data-pltdoc="x">plot</a></span><spanclass="RktPn">)</span><spanclass="RktMeta"></span></td></tr><tr><td><spanclass="RktMeta"> </span></td></tr><tr><td><spanclass="RktMeta">Here</span><spanclass="RktVal">'</span><spanclass="RktMeta">s</span><spanclass="hspace"> </span><spanclass="RktMeta">a</span><spanclass="hspace"> </span><spanclass="RktMeta">sine</span><spanclass="hspace"> </span><spanclass="RktMeta">wave:</span></td></tr><tr><td><spanclass="RktMeta">◊</span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/plot/plotting.html#%28def._%28%28lib._plot%2Fmain..rkt%29._plot%29%29"class="RktValLink"data-pltdoc="x">plot</a></span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/plot/renderer2d.html#%28def._%28%28lib._plot%2Fmain..rkt%29._function%29%29"class="RktValLink"data-pltdoc="x">function</a></span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._sin%29%29"class="RktValLink"data-pltdoc="x">sin</a></span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._-%29%29"class="RktValLink"data-pltdoc="x"><spanclass="nobreak">-</span></a></span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktSym">pi</span><spanclass="RktPn">)</span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktSym">pi</span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktPn">#:label</span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktVal">"y</span><spanclass="hspace"> </span><spanclass="RktVal">=</span><spanclass="hspace"> </span><spanclass="RktVal">sin(x)"</span><spanclass="RktPn">)</span><spanclass="RktPn">)</span><spanclass="RktMeta"></span></td></tr></table></blockquote></div></div></div></div><p>But it won’t work when you try to run it in DrRacket or load it in the project server.
And a new line.
<br/><br/>
The second paragraph.</span></span></p></td></tr></table></div></div><p>Of course, in practice you wouldn’t put your decoding function in a single source file. You’d make it available to all your source files by putting it in <spanclass="stt">directory-require.rkt</span>. So let’s do that now:</p><divclass="fileblock"><divclass="SIntrapara"><divclass="fileblock_filetitle"><spanclass="fileblock_filename"><spanclass="stt">"directory-require.rkt"</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="http://docs.racket-lang.org/reference/index.html"class="RktModLink"data-pltdoc="x"><spanclass="RktSym">racket</span></a><spanclass="RktMeta"></span></td></tr><tr><td><spanclass="RktMeta"></span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29"class="RktStxLink"data-pltdoc="x">require</a></span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktSym">pollen/decode</span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktSym">txexpr</span><spanclass="RktPn">)</span><spanclass="RktMeta"></span></td></tr><tr><td><spanclass="RktMeta"></span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29"class="RktStxLink"data-pltdoc="x">define</a></span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktPn">(</span><spanclass="RktSym">root</span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktMeta">.</span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktSym">elements</span><spanclass="RktPn">)</span><spanclass="RktMeta"></span></td></tr><tr><td><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/txexpr/index.html#%28def._%28%28lib._txexpr%2Fmain..rkt%29._make-txexpr%29%29"class="RktValLink"data-pltdoc="x">make-txexpr</a></span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/quote.html#%28form._%28%28quote._~23~25kernel%29._quote%29%29"class="RktStxLink"data-pltdoc="x">'</a></span><spanclass="RktSym">root</span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._null%29%29"class="RktValLink"data-pltdoc="x">null</a></span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="Decode.html#%28def._%28%28lib._pollen%2Fdecode..rkt%29._decode-elements%29%29"class="RktValLink"data-pltdoc="x">decode-elements</a></span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktSym">elements</span><spanclass="RktMeta"></span></td></tr><tr><td><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktPn">#:txexpr-elements-proc</span><spanclass="RktMeta"></span><spanclass="hspace"> </span><spanclass="RktMeta"></span><spanclass="RktSym"><ahref="Decode.html#%28def._%28%28lib._pollen%2Fdecode..rkt%29._detect-paragraphs%29%29"class="RktValLink"data-pltdoc="x">detect-paragraphs</a></span><spanclass="RktPn">)</spa
And a new line.
<br/><br/>
The second paragraph.</span></span></p></td></tr></table></div></div><p>By the way, though decoding via the <spanclass="stt">root</span> tag is the most likely usage scenario, you don’t have to do it that way. Decoding is just a special kind of tag function. So you can make a decoder that only affects a certain tag within the page. Or you can make multiple decoders for different tags. The advantage of using a decoder with <spanclass="stt">root</span> is that it can affect all the content, and it will be the last tag function that gets called.</p><h4>7.8<tt> </tt><aname="(part._.Putting_it_all_together)"></a>Putting it all together</h4><p>[Coming soon]</p><divclass="navsetbottom"><spanclass="navleft"><divclass="nosearchform"></div> </span><spanclass="navright"> <ahref="second-tutorial.html"title="backward to "6 Second tutorial""data-pltdoc="x">← prev</a> <ahref="index.html"title="up to "Pollen: the book is a program""data-pltdoc="x">up</a> <ahref="raco-pollen.html"title="forward to "8 Using raco pollen""data-pltdoc="x">next →</a></span> </div></div></div><divid="contextindicator"> </div></body></html>