You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
113 KiB
HTML
28 lines
113 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><title>7 ◊ command overview</title><link rel="stylesheet" type="text/css" href="scribble.css" title="default"/><link rel="stylesheet" type="text/css" href="racket.css" title="default"/><link rel="stylesheet" type="text/css" href="manual-style.css" title="default"/><link rel="stylesheet" type="text/css" href="manual-racket.css" title="default"/><script type="text/javascript" src="scribble-common.js"></script><!--[if IE 6]><style type="text/css">.SIEHidden { overflow: hidden; }</style><![endif]--></head><body id="scribble-racket-lang-org"><div class="tocset"><div class="tocview"><div class="tocviewlist tocviewlisttopspace"><div class="tocviewtitle"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,"tocview_0");">▼</a></td><td></td><td><a href="index.html" class="tocviewlink" data-pltdoc="x">Pollen:<span class="mywbr"> </span> the book is a program</a></td></tr></table></div><div class="tocviewsublisttop" style="display: block;" id="tocview_0"><table cellspacing="0" cellpadding="0"><tr><td align="right">1 </td><td><a href="Installation.html" class="tocviewlink" data-pltdoc="x">Installation</a></td></tr><tr><td align="right">2 </td><td><a href="quick-tour.html" class="tocviewlink" data-pltdoc="x">Quick tour</a></td></tr><tr><td align="right">3 </td><td><a href="Backstory.html" class="tocviewlink" data-pltdoc="x">Backstory</a></td></tr><tr><td align="right">4 </td><td><a href="The_big_picture.html" class="tocviewlink" data-pltdoc="x">The big picture</a></td></tr><tr><td align="right">5 </td><td><a href="Using_raco_pollen.html" class="tocviewlink" data-pltdoc="x">Using <span class="stt">raco pollen</span></a></td></tr><tr><td align="right">6 </td><td><a href="File_formats.html" class="tocviewlink" data-pltdoc="x">File formats</a></td></tr><tr><td align="right">7 </td><td><a href="reader.html" class="tocviewselflink" data-pltdoc="x">◊ command overview</a></td></tr><tr><td align="right">8 </td><td><a href="Module_reference.html" class="tocviewlink" data-pltdoc="x">Module reference</a></td></tr><tr><td align="right">9 </td><td><a href="Acknowledgments.html" class="tocviewlink" data-pltdoc="x">Acknowledgments</a></td></tr><tr><td align="right">10 </td><td><a href="License___source_code.html" class="tocviewlink" data-pltdoc="x">License & source code</a></td></tr><tr><td align="right"></td><td><a href="doc-index.html" class="tocviewlink" data-pltdoc="x">Index</a></td></tr></table></div></div><div class="tocviewlist"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,"tocview_1");">►</a></td><td>7 </td><td><a href="reader.html" class="tocviewselflink" data-pltdoc="x">◊ command overview</a></td></tr></table><div class="tocviewsublistbottom" style="display: none;" id="tocview_1"><table cellspacing="0" cellpadding="0"><tr><td align="right">7.1 </td><td><a href="reader.html#%28part._.The_golden_rule%29" class="tocviewlink" data-pltdoc="x">The golden rule</a></td></tr><tr><td align="right">7.2 </td><td><a href="reader.html#%28part._.The_lozenge_glyph____%29" class="tocviewlink" data-pltdoc="x">The lozenge glyph (◊)</a></td></tr><tr><td align="right">7.3 </td><td><a href="reader.html#%28part._.The_two_command_modes__text_mode___.Racket_mode%29" class="tocviewlink" data-pltdoc="x">The two command modes:<span class="mywbr"> </span> text mode & Racket mode</a></td></tr><tr><td align="right">7.4 </td><td><a href="reader.html#%28part._.Further_reading%29" class="tocviewlink" data-pltdoc="x">Further reading</a></td></tr></table></div></div></div><div class="tocsub"><div class="tocsubtitle">On this page:</div><table class="tocsublist" cellspacing="0"><tr><td><span class="tocsublinknumber">7.1<tt> </tt></span><a href="#%28part._.The_golden_rule%29" class="tocsubseclink" data-pltdoc="x">The golden rule</a></td></tr><tr><td><span class="tocsublinknumber">7.2<tt> </tt></span><a href="#%28part._.The_lozenge_glyph____%29" class="tocsubseclink" data-pltdoc="x">The lozenge glyph (◊)</a></td></tr><tr><td><span class="tocsublinknumber">7.3<tt> </tt></span><a href="#%28part._.The_two_command_modes__text_mode___.Racket_mode%29" class="tocsubseclink" data-pltdoc="x">The two command modes:<span class="mywbr"> </span> text mode & Racket mode</a></td></tr><tr><td><span class="tocsublinknumber">7.3.1<tt> </tt></span><a href="#%28part._.The_command_name%29" class="tocsubseclink" data-pltdoc="x">The command name</a></td></tr><tr><td><span class="tocsublinknumber">7.3.1.1<tt> </tt></span><a href="#%28part._.Invoking_tag_functions%29" class="tocsubseclink" data-pltdoc="x">Invoking tag functions</a></td></tr><tr><td><span class="tocsublinknumber">7.3.1.2<tt> </tt></span><a href="#%28part._.Invoking_other_functions%29" class="tocsubseclink" data-pltdoc="x">Invoking other functions</a></td></tr><tr><td><span class="tocsublinknumber">7.3.1.3<tt> </tt></span><a href="#%28part._.Inserting_the_value_of_a_variable%29" class="tocsubseclink" data-pltdoc="x">Inserting the value of a variable</a></td></tr><tr><td><span class="tocsublinknumber">7.3.1.4<tt> </tt></span><a href="#%28part._.Inserting_a_comment%29" class="tocsubseclink" data-pltdoc="x">Inserting a comment</a></td></tr><tr><td><span class="tocsublinknumber">7.3.2<tt> </tt></span><a href="#%28part._.The_.Racket_arguments%29" class="tocsubseclink" data-pltdoc="x">The Racket arguments</a></td></tr><tr><td><span class="tocsublinknumber">7.3.3<tt> </tt></span><a href="#%28part._.The_text_argument%29" class="tocsubseclink" data-pltdoc="x">The text argument</a></td></tr><tr><td><span class="tocsublinknumber">7.4<tt> </tt></span><a href="#%28part._.Further_reading%29" class="tocsubseclink" data-pltdoc="x">Further reading</a></td></tr></table></div></div><div class="maincolumn"><div class="main"><div class="versionbox"><span class="version">6.0.1.6</span></div><div class="navsettop"><span class="navleft"> </span><span class="navright"> <a href="File_formats.html" title="backward to "6 File formats"" data-pltdoc="x">← prev</a> <a href="index.html" title="up to "Pollen: the book is a program"" data-pltdoc="x">up</a> <a href="Module_reference.html" title="forward to "8 Module reference"" data-pltdoc="x">next →</a></span> </div><h3>7<tt> </tt><a name="(part._reader)"></a>◊ command overview</h3><h4>7.1<tt> </tt><a name="(part._.The_golden_rule)"></a>The golden rule</h4><p>Pollen uses a special character — the <span style="font-style: italic">lozenge</span>, which looks like this: ◊ — to mark commands within a Pollen source file. So when you put a ◊ in your source, whatever comes next will be treated as a command. If you don’t, it will just be interpreted as plain text.</p><h4>7.2<tt> </tt><a name="(part._.The_lozenge_glyph____)"></a>The lozenge glyph (◊)</h4><p>I chose the lozenge as the command marker because a) it appears in almost every font, b) it’s barely used in ordinary typesetting, c) it’s not used in any programming language that I know of, and d) its shape and color allow it to stand out easily in code without being distracting.</p><p>Here’s how you type it:</p><p><span style="font-weight: bold">Mac</span>: option + shift + V
|
|
<br/>
|
|
<span style="font-weight: bold">Windows</span>:
|
|
<br/>
|
|
<span style="font-weight: bold">Ubuntu</span>:</p><p>Still, if you don’t want to use the lozenge as your command marker, you can use something else. Set Pollen’s <span class="RktSym">world:command-marker</span> value to whatever character you want.</p><blockquote class="refpara"><blockquote class="refcolumn"><blockquote class="refcontent"><p>Scribble uses the @ sign as a delimiter. It’s not a bad choice if you only work with Racket files. But as you use Pollen to work on other kinds of text-based files that commonly contain @ signs — HTML pages especially — it gets cumbersome. So I changed it.</p></blockquote></blockquote></blockquote><p>But don’t knock the lozenge till you try it.</p><h4>7.3<tt> </tt><a name="(part._.The_two_command_modes__text_mode___.Racket_mode)"></a>The two command modes: text mode & Racket mode</h4><p>Pollen commands can be entered in one of two modes: <span style="font-style: italic">text mode</span> or <span style="font-style: italic">Racket mode</span>. Both modes start with a lozenge (<span class="RktInBG"><span class="hspace"></span><span class="RktIn">◊</span><span class="hspace"></span></span>):</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktInBG"><span class="hspace"></span><span class="RktIn">◊</span><span class="hspace"></span></span><span class="hspace"> </span><span class="sroman">‹<span style="font-style: italic">command name</span>›</span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">[</span><span class="hspace"></span></span><span class="hspace"> </span><span class="sroman">‹<span style="font-style: italic">Racket arguments ...</span>›</span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">]</span><span class="hspace"></span></span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">{</span><span class="hspace"></span></span><span class="hspace"> </span><span class="sroman">‹<span style="font-style: italic">text argument</span>›</span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">}</span><span class="hspace"></span></span></td></tr><tr><td><span class="RktInBG"><span class="hspace"></span><span class="RktIn">◊</span><span class="hspace"></span></span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">(</span><span class="hspace"></span></span><span class="hspace"> </span><span class="sroman">‹<span style="font-style: italic">Racket expression</span>›</span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">)</span><span class="hspace"></span></span></td></tr></table></blockquote><p><span style="font-weight: bold">Text-mode commands</span></p><p>A text-mode command has the three possible parts after the <span class="RktInBG"><span class="hspace"></span><span class="RktIn">◊</span><span class="hspace"></span></span>:</p><ul><li><p>The <span style="font-style: italic">command name</span> appears immediately after the <span class="RktInBG"><span class="hspace"></span><span class="RktIn">◊</span><span class="hspace"></span></span>. Typically it’s a short word.</p></li><li><p>The <span style="font-style: italic">Racket arguments</span> appear between square brackets. Pollen is partly an interface to the Racket programming language. These arguments are entered using Racket conventions — e.g., a <span class="stt">string of text</span> needs to be put in quotes as a <span class="RktVal">"string</span><span class="hspace"> </span><span class="RktVal">of</span><span class="hspace"> </span><span class="RktVal">text"</span><span class="RktMeta"></span>. If you like programming, you’ll end up using these frequently. If you don’t, you won’t.</p></li><li><p>The <span style="font-style: italic">text argument</span> appears between braces (aka curly brackets). You can put any ordinary text here. Unlike with the Racket arguments, you don’t put quotes around the text.</p></li></ul><p>Each of the three parts is optional. You can also nest commands within each other. However:</p><ul><li><p>You can never have spaces between the three parts.</p></li><li><p>Whatever parts you use must always appear in the order above.</p></li></ul><p>Here are a few examples of correct text-mode commands:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">variable-name</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._tag%29%29" class="RktStxLink" data-pltdoc="x">tag</a></span><span class="RktPn">{</span><span class="RktMeta">Text</span><span class="hspace"> </span><span class="RktMeta">inside</span><span class="hspace"> </span><span class="RktMeta">the</span><span class="hspace"> </span><span class="RktMeta">tag.</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._tag%29%29" class="RktStxLink" data-pltdoc="x">tag</a></span><span class="RktPn">[</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quote.html#%28form._%28%28quote._~23~25kernel%29._quote%29%29" class="RktStxLink" data-pltdoc="x">'</a></span><span class="RktSym">attr:</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"value"</span><span class="RktPn">]</span><span class="RktPn">{</span><span class="RktMeta">Text</span><span class="hspace"> </span><span class="RktMeta">inside</span><span class="hspace"> </span><span class="RktMeta">the</span><span class="hspace"> </span><span class="RktMeta">tag</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">get-customer-id</span><span class="RktPn">[</span><span class="RktVal">"Brennan</span><span class="hspace"> </span><span class="RktVal">Huff"</span><span class="RktPn">]</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._tag%29%29" class="RktStxLink" data-pltdoc="x">tag</a></span><span class="RktPn">{</span><span class="RktMeta">His</span><span class="hspace"> </span><span class="RktMeta">ID</span><span class="hspace"> </span><span class="RktMeta">is</span><span class="hspace"> </span><span class="RktMeta">◊</span><span class="RktSym">get-customer-id</span><span class="RktPn">[</span><span class="RktVal">"Brennan</span><span class="hspace"> </span><span class="RktVal">Huff"</span><span class="RktPn">]</span><span class="RktMeta">.</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p>And some incorrect examples:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._tag%29%29" class="RktStxLink" data-pltdoc="x">tag</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">{</span><span class="RktMeta">Text</span><span class="hspace"> </span><span class="RktMeta">inside</span><span class="hspace"> </span><span class="RktMeta">the</span><span class="hspace"> </span><span class="RktMeta">tag.</span><span class="RktPn">}</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktCmt">;</span><span class="hspace"> </span><span class="RktCmt">space</span><span class="hspace"> </span><span class="RktCmt">between</span><span class="hspace"> </span><span class="RktCmt">first</span><span class="hspace"> </span><span class="RktCmt">and</span><span class="hspace"> </span><span class="RktCmt">second</span><span class="hspace"> </span><span class="RktCmt">parts</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._tag%29%29" class="RktStxLink" data-pltdoc="x">tag</a></span><span class="RktPn">[</span><span class="RktSym">Text</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">inside</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">the</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._tag%29%29" class="RktStxLink" data-pltdoc="x">tag</a></span><span class="RktPn">]</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktCmt">;</span><span class="hspace"> </span><span class="RktCmt">text</span><span class="hspace"> </span><span class="RktCmt">argument</span><span class="hspace"> </span><span class="RktCmt">needs</span><span class="hspace"> </span><span class="RktCmt">to</span><span class="hspace"> </span><span class="RktCmt">be</span><span class="hspace"> </span><span class="RktCmt">within</span><span class="hspace"> </span><span class="RktCmt">braces</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._tag%29%29" class="RktStxLink" data-pltdoc="x">tag</a></span><span class="RktPn">{</span><span class="RktMeta">Text</span><span class="hspace"> </span><span class="RktMeta">inside</span><span class="hspace"> </span><span class="RktMeta">the</span><span class="hspace"> </span><span class="RktMeta">tag</span><span class="RktPn">}</span><span class="RktPn">[</span><span class="RktVal">'</span><span class="RktMeta">attr:</span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"value"</span><span class="RktPn">]</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktCmt">;</span><span class="hspace"> </span><span class="RktCmt">wrong</span><span class="hspace"> </span><span class="RktCmt">order</span><span class="RktMeta"></span></td></tr></table></blockquote><p>The next section describes each of these parts in detail.</p><p><span style="font-weight: bold">Racket-mode commands</span></p><p>If you’re familiar with Racket expressions, you can use the Racket-mode commands to embed them within Pollen source files. It’s simple: any Racket expression can become a Pollen command by adding <span class="RktInBG"><span class="hspace"></span><span class="RktIn">◊</span><span class="hspace"></span></span> to the front. So in Racket, this code:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="http://docs.racket-lang.org/reference/index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">racket</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">song</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"Revolution"</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/Writing.html#%28def._%28%28quote._~23~25kernel%29._format%29%29" class="RktValLink" data-pltdoc="x">format</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"~a</span><span class="hspace"> </span><span class="RktVal">#~a"</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">song</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2A%29%29" class="RktValLink" data-pltdoc="x">*</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">3</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">3</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr></table></blockquote><p>Can be converted to Pollen like so:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">song</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"Revolution"</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/Writing.html#%28def._%28%28quote._~23~25kernel%29._format%29%29" class="RktValLink" data-pltdoc="x">format</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"~a</span><span class="hspace"> </span><span class="RktVal">#~a"</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">song</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2A%29%29" class="RktValLink" data-pltdoc="x">*</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">3</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">3</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr></table></blockquote><p>And in DrRacket, they produce the same output:</p><blockquote><p><span class="RktOut">Revolution #9</span></p></blockquote><p>Beyond that, there’s not much to say about Racket mode — any valid expression you can write in Racket will also be a valid Racket-mode Pollen command.</p><p><span style="font-weight: bold">The relationship of text mode and Racket mode</span></p><p>Even if you don’t plan to write a lot of Racket-mode commands, you should be aware that under the hood, Pollen is converting all commands in text mode to Racket mode. So a text-mode command that looks like this:</p><blockquote class="SCodeFlow"><p><span class="RktSym">◊headline</span><span class="RktPn">[</span><span class="RktPn">#:size</span><span class="hspace"> </span><span class="RktVal">'</span><span class="RktVal">enormous</span><span class="RktPn">]</span><span class="RktPn">{</span><span class="RktSym">Man</span><span class="hspace"> </span><span class="RktSym">Bites</span><span class="hspace"> </span><span class="RktSym">Dog!</span><span class="RktPn">}</span></p></blockquote><p>Is actually being turned into a Racket-mode command like this:</p><blockquote class="SCodeFlow"><p><span class="RktPn">(</span><span class="RktSym">headline</span><span class="hspace"> </span><span class="RktPn">#:size</span><span class="hspace"> </span><span class="RktVal">'</span><span class="RktVal">enormous</span><span class="hspace"> </span><span class="RktVal">"Man Bites Dog!"</span><span class="RktPn">)</span></p></blockquote><p>Thus a text-mode command is just an alternate way of writing a Racket-mode command. (More broadly, all of Pollen is just an alternate way of using Racket.)</p><p>The corollary is that you can always write Pollen commands using whichever mode is more convenient or readable. For instance, the earlier example, written in the Racket mode:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">song</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"Revolution"</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/Writing.html#%28def._%28%28quote._~23~25kernel%29._format%29%29" class="RktValLink" data-pltdoc="x">format</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"~a</span><span class="hspace"> </span><span class="RktVal">#~a"</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">song</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2A%29%29" class="RktValLink" data-pltdoc="x">*</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">3</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">3</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr></table></blockquote><p>Can be rewritten using text mode:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym"><a href="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><span class="RktPn">[</span><span class="RktSym">song</span><span class="RktPn">]</span><span class="RktPn">{</span><span class="RktMeta">Revolution</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/Writing.html#%28def._%28%28quote._~23~25kernel%29._format%29%29" class="RktValLink" data-pltdoc="x">format</a></span><span class="RktPn">[</span><span class="RktVal">"~a</span><span class="hspace"> </span><span class="RktVal">#~a"</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">song</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2A%29%29" class="RktValLink" data-pltdoc="x">*</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">3</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">3</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktMeta"></span></td></tr></table></blockquote><p>And it will work the same way.</p><h5>7.3.1<tt> </tt><a name="(part._.The_command_name)"></a>The command name</h5><p>In Pollen, you’ll typically use the command name for one of four purposes:</p><ul><li><p>To invoke a tag function.</p></li><li><p>To invoke another function.</p></li><li><p>To insert the value of a variable.</p></li><li><p>To insert a comment.</p></li></ul><h5>7.3.1.1<tt> </tt><a name="(part._.Invoking_tag_functions)"></a>Invoking tag functions</h5><p>By default, Pollen treats every command name as a <span style="font-style: italic">tag function</span>. As the name implies, a tag function creates a tagged X-expression with the command name as the tag, and the text argument as the content.</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">strong</span><span class="RktPn">{</span><span class="RktMeta">Fancy</span><span class="hspace"> </span><span class="RktMeta">Sauce</span><span class="RktMeta">,</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta">$1</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(strong "Fancy Sauce, $1")</span></p><p>To streamline markup, Pollen doesn’t restrict you to a certain set of tags, nor does it make you define your tag functions ahead of time. Just type a tag, and you can start using it.</p><p><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">utterlyridiculoustagname</span><span class="RktPn">{</span><span class="RktMeta">Oh</span><span class="hspace"> </span><span class="RktMeta">really?</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote></div><div class="SIntrapara"><span class="RktOut">'(utterlyridiculoustagname "Oh really?")</span></div></p><p>The one restriction is that you can’t invent names for tag functions that are already being used for other commands. For instance, <span class="stt">map</span> is a name permanently reserved by the Racket function <span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Fprivate%2Fmap..rkt%29._map%29%29" class="RktValLink" data-pltdoc="x">map</a></span>. It’s also a rarely-used HTML tag. But gosh, you really want to use it. Problem is, if you invoke it directly, Pollen will think you mean the other <span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Fprivate%2Fmap..rkt%29._map%29%29" class="RktValLink" data-pltdoc="x">map</a></span>:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Fprivate%2Fmap..rkt%29._map%29%29" class="RktValLink" data-pltdoc="x">map</a></span><span class="RktPn">{</span><span class="RktMeta">Fancy</span><span class="hspace"> </span><span class="RktMeta">Sauce</span><span class="RktMeta">,</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta">$1</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktErr">map: arity mismatch;<br/>
|
|
the expected number of arguments does not match the given number<br/>
|
|
  given: 1<br/>
|
|
  arguments...:<br/>
|
|
    "Fancy Sauce, $1"</span></p><p>What to do? Read on.</p><h5>7.3.1.2<tt> </tt><a name="(part._.Invoking_other_functions)"></a>Invoking other functions</h5><p>Though every command name starts out as a tag function, it doesn’t necessarily end there. You have two options for invoking other functions: defining your own , or invoking others from Racket.</p><p><span style="font-weight: bold">Defining your own functions</span></p><p>Use the <span class="RktSym"><a href="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> command to create your own function for a command name. After that, when you use the command name, you’ll get the new behavior. For instance, recall this example showing the default tag-function behavior:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">strong</span><span class="RktPn">{</span><span class="RktMeta">Fancy</span><span class="hspace"> </span><span class="RktMeta">Sauce</span><span class="RktMeta">,</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta">$1</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(strong "Fancy Sauce, $1")</span></p><p>We can define <span class="stt">strong</span> to do something else, like add to the text:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym">strong</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">text</span><span class="RktPn">)</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quasiquote.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._quasiquote%29%29" class="RktStxLink" data-pltdoc="x">`</a></span><span class="RktPn">(</span><span class="RktSym">strong</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quasiquote.html#%28form._%28%28quote._~23~25kernel%29._unquote%29%29" class="RktStxLink" data-pltdoc="x">,</a></span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/Writing.html#%28def._%28%28quote._~23~25kernel%29._format%29%29" class="RktValLink" data-pltdoc="x">format</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"Hey!</span><span class="hspace"> </span><span class="RktVal">Listen</span><span class="hspace"> </span><span class="RktVal">up!</span><span class="hspace"> </span><span class="RktVal">~a"</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">text</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">strong</span><span class="RktPn">{</span><span class="RktMeta">Fancy</span><span class="hspace"> </span><span class="RktMeta">Sauce</span><span class="RktMeta">,</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta">$1</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(strong "Hey! Listen up! Fancy Sauce, $1")</span></p><p>The replacement function has to accept any arguments that might get passed along, but it doesn’t have to do anything with them. For instance, this function definition won’t work because <span class="stt">strong</span> is going to get a text argument that it’s not defined to handle:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym">strong</span><span class="RktPn">)</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quote.html#%28form._%28%28quote._~23~25kernel%29._quote%29%29" class="RktStxLink" data-pltdoc="x">'</a></span><span class="RktPn">(</span><span class="RktSym">fib</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"1</span><span class="hspace"> </span><span class="RktVal">1</span><span class="hspace"> </span><span class="RktVal">2</span><span class="hspace"> </span><span class="RktVal">3</span><span class="hspace"> </span><span class="RktVal">5</span><span class="hspace"> </span><span class="RktVal">8</span><span class="hspace"> </span><span class="RktVal">13</span><span class="hspace"> </span><span class="RktVal">..."</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">strong</span><span class="RktPn">{</span><span class="RktMeta">Fancy</span><span class="hspace"> </span><span class="RktMeta">Sauce</span><span class="RktMeta">,</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta">$1</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktErr">strong: arity mismatch;<br/>
|
|
the expected number of arguments does not match the given number<br/>
|
|
  expected: 0<br/>
|
|
  given: 1<br/>
|
|
  arguments...:<br/>
|
|
    "Fancy Sauce, $1"</span></p><p>Whereas in this version, <span class="stt">strong</span> accepts an argument called <span class="stt">text</span>, but then ignores it:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym">strong</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">text</span><span class="RktPn">)</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quote.html#%28form._%28%28quote._~23~25kernel%29._quote%29%29" class="RktStxLink" data-pltdoc="x">'</a></span><span class="RktPn">(</span><span class="RktSym">fib</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"1</span><span class="hspace"> </span><span class="RktVal">1</span><span class="hspace"> </span><span class="RktVal">2</span><span class="hspace"> </span><span class="RktVal">3</span><span class="hspace"> </span><span class="RktVal">5</span><span class="hspace"> </span><span class="RktVal">8</span><span class="hspace"> </span><span class="RktVal">13</span><span class="hspace"> </span><span class="RktVal">..."</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">strong</span><span class="RktPn">{</span><span class="RktMeta">Fancy</span><span class="hspace"> </span><span class="RktMeta">Sauce</span><span class="RktMeta">,</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta">$1</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(fib "1 1 2 3 5 8 13 ...")</span></p><p>You can attach any behavior to a command name. As your project evolves, you can also update the behavior of a command name. In that way, Pollen commands become a set of hooks to which you can attach more elaborate processing.</p><p><span style="font-weight: bold">Using Racket functions</span></p><p>You aren’t limited to functions you define. Any function from Racket, or any Racket library, can be invoked directly by using it as a command name. Here’s the function <span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Flist..rkt%29._range%29%29" class="RktValLink" data-pltdoc="x">range</a></span>, which creates a list of numbers:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Flist..rkt%29._range%29%29" class="RktValLink" data-pltdoc="x">range</a></span><span class="RktPn">[</span><span class="RktVal">1</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">20</span><span class="RktPn">]</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(range 1 20)</span></p><p>Hold on — that’s not what we want. Where’s the list of numbers? The problem here is that we didn’t explicitly import the <a href="http://docs.racket-lang.org/reference/pairs.html#%28mod-path._racket%2Flist%29" class="RktModLink" data-pltdoc="x"><span class="RktSym">racket/list</span></a> library, which contains the definition for <span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Flist..rkt%29._range%29%29" class="RktValLink" data-pltdoc="x">range</a></span>. (If you need to find out what library contains a certain function, the Racket documentation will tell you.) Without <a href="http://docs.racket-lang.org/reference/pairs.html#%28mod-path._racket%2Flist%29" class="RktModLink" data-pltdoc="x"><span class="RktSym">racket/list</span></a>, Pollen just thinks we’re trying to use <span class="stt">range</span> as a tag function (and if we had been, then <span class="RktOut">'(range 1 20)</span> would’ve been the right result).</p><p>We fix this by using the <span class="RktSym"><a href="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> command to bring in the <a href="http://docs.racket-lang.org/reference/pairs.html#%28mod-path._racket%2Flist%29" class="RktModLink" data-pltdoc="x"><span class="RktSym">racket/list</span></a> library, which contains the <span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Flist..rkt%29._range%29%29" class="RktValLink" data-pltdoc="x">range</a></span> we want:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">racket/list</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Flist..rkt%29._range%29%29" class="RktValLink" data-pltdoc="x">range</a></span><span class="RktPn">[</span><span class="RktVal">1</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">20</span><span class="RktPn">]</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)</span></p><p>Of course, you can also invoke Racket functions indirectly, by attaching them to functions you define for command names:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">racket/list</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym">rick</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">start</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">finish</span><span class="RktPn">)</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Flist..rkt%29._range%29%29" class="RktValLink" data-pltdoc="x">range</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">start</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">finish</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">rick</span><span class="RktPn">[</span><span class="RktVal">1</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">20</span><span class="RktPn">]</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)</span></p><p>Let’s return to the problem that surfaced in the last section — the fact that some command names can’t be used as tag functions because they’re already being used for other things. You can work around this by defining your own tag function with a non-conflicting name.</p><p>For instance, suppose we want to use <span class="stt">map</span> as a tag even though Racket is using it for its own function called <span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Fprivate%2Fmap..rkt%29._map%29%29" class="RktValLink" data-pltdoc="x">map</a></span>. First, we invent a command name that doesn’t conflict. Let’s call it <span class="RktSym">my-map</span><span class="RktMeta"></span>. As you learned above, Pollen will treat a new command name as a tag function by default:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">my-map</span><span class="RktPn">{</span><span class="RktMeta">How</span><span class="hspace"> </span><span class="RktMeta">I</span><span class="hspace"> </span><span class="RktMeta">would</span><span class="hspace"> </span><span class="RktMeta">love</span><span class="hspace"> </span><span class="RktMeta">this</span><span class="hspace"> </span><span class="RktMeta">to</span><span class="hspace"> </span><span class="RktMeta">be</span><span class="hspace"> </span><span class="RktMeta">a</span><span class="hspace"> </span><span class="RktMeta">map.</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(my-map "How I would love this to be a map.")</span></p><p>But <span class="RktSym">my-map</span><span class="RktMeta"></span> is not the tag we want. We need to define <span class="RktSym">my-map</span><span class="RktMeta"></span> to be a tag function for <span class="stt">map</span>. We can do this with the Pollen helper <span class="RktSym">make-tag-function</span>. That function lives in <span class="RktSym">pollen/tag</span>, so we <span class="RktSym"><a href="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> that too:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">pollen/tag</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">my-map</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym">make-tag-function</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quote.html#%28form._%28%28quote._~23~25kernel%29._quote%29%29" class="RktStxLink" data-pltdoc="x">'</a></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Fprivate%2Fmap..rkt%29._map%29%29" class="RktValLink" data-pltdoc="x">map</a></span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">my-map</span><span class="RktPn">{</span><span class="RktMeta">How</span><span class="hspace"> </span><span class="RktMeta">I</span><span class="hspace"> </span><span class="RktMeta">would</span><span class="hspace"> </span><span class="RktMeta">love</span><span class="hspace"> </span><span class="RktMeta">this</span><span class="hspace"> </span><span class="RktMeta">to</span><span class="hspace"> </span><span class="RktMeta">be</span><span class="hspace"> </span><span class="RktMeta">a</span><span class="hspace"> </span><span class="RktMeta">map.</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(map "How I would love this to be a map.")</span></p><p>Problem solved.</p><h5>7.3.1.3<tt> </tt><a name="(part._.Inserting_the_value_of_a_variable)"></a>Inserting the value of a variable</h5><p>A Pollen command name usually refers to a function, but it can also refer to a <span style="font-style: italic">variable</span>, which is a data value. Once you define the variable, you can insert it into your source by using the ◊ notation without any other arguments:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">foo</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"bar"</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">The</span><span class="hspace"> </span><span class="RktMeta">value</span><span class="hspace"> </span><span class="RktMeta">of</span><span class="hspace"> </span><span class="RktMeta">foo</span><span class="hspace"> </span><span class="RktMeta">is</span><span class="hspace"> </span><span class="RktMeta">◊</span><span class="RktSym">foo</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">The value of foo is bar</span></p><p>Be careful — if you include arguments, even blank ones, Pollen will treat the command name as a function. This won’t work, because a variable is not a function:</p><blockquote class="refpara"><blockquote class="refcolumn"><blockquote class="refcontent"><p>To understand what happens here, recall the relationship between Pollen’s command modes. The text-mode command <span class="RktSym">◊foo</span><span class="RktPn">[</span><span class="RktPn">]</span><span class="RktMeta"></span> becomes the Racket-mode command <span class="RktPn">(</span><span class="RktSym">foo</span><span class="RktPn">)</span><span class="RktMeta"></span>, which after variable substitution becomes <span class="RktPn">(</span><span class="RktVal">"bar"</span><span class="RktPn">)</span><span class="RktMeta"></span>. If you try to evaluate <span class="RktPn">(</span><span class="RktVal">"bar"</span><span class="RktPn">)</span><span class="RktMeta"></span> — e.g., in DrRacket — you’ll get the same error.</p></blockquote></blockquote></blockquote><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">foo</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"bar"</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">The</span><span class="hspace"> </span><span class="RktMeta">value</span><span class="hspace"> </span><span class="RktMeta">of</span><span class="hspace"> </span><span class="RktMeta">foo</span><span class="hspace"> </span><span class="RktMeta">is</span><span class="hspace"> </span><span class="RktMeta">◊</span><span class="RktSym">foo</span><span class="RktPn">[</span><span class="RktPn">]</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktErr">application: not a procedure;<br/>
|
|
expected a procedure that can be applied to arguments<br/>
|
|
  given: "bar"<br/>
|
|
  arguments...: [none]</span></p><p>The reason we can simply drop <span class="RktSym">◊foo</span><span class="RktMeta"></span> into the text argument of another Pollen command is that the variable <span class="RktSym">foo</span><span class="RktMeta"></span> holds a string (i.e., a text value). When appropriate, Pollen will convert a variable to a string in a sensible way. For instance, numbers are easily converted:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">zam</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">42</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">The</span><span class="hspace"> </span><span class="RktMeta">value</span><span class="hspace"> </span><span class="RktMeta">of</span><span class="hspace"> </span><span class="RktMeta">zam</span><span class="hspace"> </span><span class="RktMeta">is</span><span class="hspace"> </span><span class="RktMeta">◊</span><span class="RktSym">zam</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">The value of zam is 42</span></p><p>If the variable holds a container datatype (like a <span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29" class="RktValLink" data-pltdoc="x">list</a></span>, <span class="RktSym"><a href="http://docs.racket-lang.org/reference/hashtables.html#%28def._%28%28quote._~23~25kernel%29._hash%29%29" class="RktValLink" data-pltdoc="x">hash</a></span>, or <span class="RktSym"><a href="http://docs.racket-lang.org/reference/vectors.html#%28def._%28%28quote._~23~25kernel%29._vector%29%29" class="RktValLink" data-pltdoc="x">vector</a></span>), Pollen will produce the Racket text representation of the item. Here, <span class="stt">zam</span> is a <span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29" class="RktValLink" data-pltdoc="x">list</a></span> of integers:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">zam</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29" class="RktValLink" data-pltdoc="x">list</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">1</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">2</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">3</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">The</span><span class="hspace"> </span><span class="RktMeta">value</span><span class="hspace"> </span><span class="RktMeta">of</span><span class="hspace"> </span><span class="RktMeta">zam</span><span class="hspace"> </span><span class="RktMeta">is</span><span class="hspace"> </span><span class="RktMeta">◊</span><span class="RktSym">zam</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">The value of zam is '(1 2 3)</span></p><p>This feature is included for your convenience as an author. But in general, your readers won’t want to see the Racket representation of a container. So in these cases, you should convert to a string manually in some sensible way. Here, the integers in the list are converted to strings, which are then combined using <span class="RktSym"><a href="http://docs.racket-lang.org/reference/strings.html#%28def._%28%28lib._racket%2Fstring..rkt%29._string-join%29%29" class="RktValLink" data-pltdoc="x">string-join</a></span> from the <a href="http://docs.racket-lang.org/reference/strings.html#%28mod-path._racket%2Fstring%29" class="RktModLink" data-pltdoc="x"><span class="RktSym">racket/string</span></a> library:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">racket/string</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">zam</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29" class="RktValLink" data-pltdoc="x">list</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">1</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">2</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">3</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">The</span><span class="hspace"> </span><span class="RktMeta">value</span><span class="hspace"> </span><span class="RktMeta">of</span><span class="hspace"> </span><span class="RktMeta">zam</span><span class="hspace"> </span><span class="RktMeta">is</span><span class="hspace"> </span><span class="RktMeta">◊</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/strings.html#%28def._%28%28lib._racket%2Fstring..rkt%29._string-join%29%29" class="RktValLink" data-pltdoc="x">string-join</a></span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Fprivate%2Fmap..rkt%29._map%29%29" class="RktValLink" data-pltdoc="x">map</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._number-~3estring%29%29" class="RktValLink" data-pltdoc="x">number->string</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">zam</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">{</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta">and</span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">The value of zam is 1 and 2 and 3</span></p><p>Pollen will still produce an error if you try to convert an esoteric value to a string. Here, <span class="stt">zam</span> is the addition function (<span class="RktSym"><a href="http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2B%29%29" class="RktValLink" data-pltdoc="x">+</a></span>):</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">zam</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2B%29%29" class="RktValLink" data-pltdoc="x">+</a></span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">The</span><span class="hspace"> </span><span class="RktMeta">value</span><span class="hspace"> </span><span class="RktMeta">of</span><span class="hspace"> </span><span class="RktMeta">zam</span><span class="hspace"> </span><span class="RktMeta">is</span><span class="hspace"> </span><span class="RktMeta">◊</span><span class="RktSym">zam</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktErr">Pollen decoder: can’t convert #<procedure:+> to string</span></p><p>One special case to know about. In the examples above, there’s a word space between the variable and the other text. But suppose you need to insert a variable into text so that there’s no space in between. The simple ◊ notation won’t work, because it won’t be clear where the variable name ends and the text begins.</p><p>For instance, suppose we want to use a variable <span class="stt">edge</span> next to the string <span class="stt">px</span>:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">edge</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">100</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">p</span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">{</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta">margin-left:</span><span class="hspace"> </span><span class="RktMeta">◊</span><span class="RktSym">edgepx</span><span class="RktCmt">;</span><span class="hspace"> </span><span class="RktCmt">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktErr">Pollen decoder: can’t convert #<procedure:...t/pollen/tag.rkt:6:2> to string</span></p><p>The example fails because Pollen reads the whole string after the <span class="RktInBG"><span class="hspace"></span><span class="RktIn">◊</span><span class="hspace"></span></span> as the single variable name <span class="stt">edgepx</span>. Since <span class="stt">edgepx</span> isn’t defined, it’s treated as a tag function, and since Pollen can’t convert a function to a string, we get an error.</p><p>In these situations, surround the variable name with vertical bars <span class="RktInBG"><span class="hspace"></span><span class="RktIn">◊|</span><span class="hspace"></span></span>like so<span class="RktInBG"><span class="hspace"></span><span class="RktIn">|</span><span class="hspace"></span></span> to explicitly indicate where the variable name ends. The bars are not treated as part of the name, nor are they included in the result. Once we do that, we get what we intended:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">edge</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">100</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">p</span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">{</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta">margin-left:</span><span class="hspace"> </span><span class="RktMeta">◊|</span><span class="RktSym">edge</span><span class="RktMeta">|px</span><span class="RktCmt">;</span><span class="hspace"> </span><span class="RktCmt">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">p { margin-left: 100px; }</span></p><p>If you use this notation when you don’t need to, nothing bad will happen. The vertical bars are always ignored.</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">edge</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">100</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">The</span><span class="hspace"> </span><span class="RktMeta">value</span><span class="hspace"> </span><span class="RktMeta">of</span><span class="hspace"> </span><span class="RktMeta">edge</span><span class="hspace"> </span><span class="RktMeta">is</span><span class="hspace"> </span><span class="RktMeta">◊|</span><span class="RktSym">edge</span><span class="RktMeta">|</span><span class="hspace"> </span><span class="RktMeta">pixels</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">The value of edge is 100 pixels</span></p><h5>7.3.1.4<tt> </tt><a name="(part._.Inserting_a_comment)"></a>Inserting a comment</h5><p>Two options.</p><p>To comment out the rest of a single line, use a lozenge followed by a semicolon <span class="RktInBG"><span class="hspace"></span><span class="RktIn">◊;</span><span class="hspace"></span></span>.</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">span</span><span class="RktPn">{</span><span class="RktMeta">This</span><span class="hspace"> </span><span class="RktMeta">is</span><span class="hspace"> </span><span class="RktMeta">not</span><span class="hspace"> </span><span class="RktMeta">a</span><span class="hspace"> </span><span class="RktMeta">comment</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">span</span><span class="RktPn">{</span><span class="RktMeta">Nor</span><span class="hspace"> </span><span class="RktMeta">is</span><span class="hspace"> </span><span class="RktMeta">this</span><span class="RktPn">}</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta">◊</span><span class="RktCmt">;span{But</span><span class="hspace"> </span><span class="RktCmt">this</span><span class="hspace"> </span><span class="RktCmt">is}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(span "This is not a comment") <br/>
|
|
'(span "Nor is this")</span></p><p>To comment out a multiline block, use the lozenge–semicolon signal <span class="RktInBG"><span class="hspace"></span><span class="RktIn">◊;</span><span class="hspace"></span></span> with curly braces, <span class="RktInBG"><span class="hspace"></span><span class="RktIn">◊;{</span><span class="hspace"></span></span>like so<span class="RktInBG"><span class="hspace"></span><span class="RktIn">}</span><span class="hspace"></span></span>.</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktCmt">;{</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊span</span><span class="RktPn">{</span><span class="RktMeta">This</span><span class="hspace"> </span><span class="RktMeta">is</span><span class="hspace"> </span><span class="RktMeta">not</span><span class="hspace"> </span><span class="RktMeta">a</span><span class="hspace"> </span><span class="RktMeta">comment</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊span</span><span class="RktPn">{</span><span class="RktMeta">Nor</span><span class="hspace"> </span><span class="RktMeta">is</span><span class="hspace"> </span><span class="RktMeta">this</span><span class="RktPn">}</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta">◊</span><span class="RktCmt">;span{But</span><span class="hspace"> </span><span class="RktCmt">this</span><span class="hspace"> </span><span class="RktCmt">is}</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta"></span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">Actually</span><span class="RktMeta">,</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta">it</span><span class="RktVal">'</span><span class="RktMeta">s</span><span class="hspace"> </span><span class="RktMeta">all</span><span class="hspace"> </span><span class="RktMeta">a</span><span class="hspace"> </span><span class="RktMeta">comment</span><span class="hspace"> </span><span class="RktMeta">now</span></td></tr></table></blockquote><p><span class="RktOut">Actually, it's all a comment now</span></p><h5>7.3.2<tt> </tt><a name="(part._.The_.Racket_arguments)"></a>The Racket arguments</h5><p>The middle part of a text-mode Pollen command contains the <span style="font-style: italic">Racket arguments</span> <span class="RktInBG"><span class="hspace"></span><span class="RktIn">[</span><span class="hspace"></span></span>between square brackets.<span class="RktInBG"><span class="hspace"></span><span class="RktIn">]</span><span class="hspace"></span></span> Most often, you’ll see these used to pass extra information to commands that operate on text.</p><p>For instance, tag functions. Recall from before that any not-yet-defined command name in Pollen is treated as a tag function:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym"><a href="http://docs.racket-lang.org/scribble/base.html#%28def._%28%28lib._scribble%2Fbase..rkt%29._title%29%29" class="RktValLink" data-pltdoc="x">title</a></span><span class="RktPn">{</span><span class="RktMeta">The</span><span class="hspace"> </span><span class="RktMeta">Beginning</span><span class="hspace"> </span><span class="RktMeta">of</span><span class="hspace"> </span><span class="RktMeta">the</span><span class="hspace"> </span><span class="RktMeta">End</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(title "The Beginning of the End")</span></p><p>But what if you wanted to add attributes to this tag, so that it comes out like this?</p><p><span class="RktOut">'(title ((class "red")(id "first")) "The Beginning of the End")</span></p><p>You can do it with Racket arguments.</p><p>Here’s the hard way. You can type out your list of attributes in Racket format and drop them into the brackets as a single argument:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym"><a href="http://docs.racket-lang.org/scribble/base.html#%28def._%28%28lib._scribble%2Fbase..rkt%29._title%29%29" class="RktValLink" data-pltdoc="x">title</a></span><span class="RktPn">[</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quote.html#%28form._%28%28quote._~23~25kernel%29._quote%29%29" class="RktStxLink" data-pltdoc="x">'</a></span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/createclass.html#%28form._%28%28lib._racket%2Fprivate%2Fclass-internal..rkt%29._class%29%29" class="RktStxLink" data-pltdoc="x">class</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"red"</span><span class="RktPn">)</span><span class="RktPn">(</span><span class="RktSym">id</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"first"</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">{</span><span class="RktMeta">The</span><span class="hspace"> </span><span class="RktMeta">Beginning</span><span class="hspace"> </span><span class="RktMeta">of</span><span class="hspace"> </span><span class="RktMeta">the</span><span class="hspace"> </span><span class="RktMeta">End</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(title ((class "red") (id "first")) "The Beginning of the End")</span></p><p>But that’s a lot of parentheses to think about. So here’s the easy way. Anytime you use a tag function, there’s a shortcut for inserting attributes. You can enter them as a series of <span class="RktSym">symbol</span> / <span class="RktSym"><a href="http://docs.racket-lang.org/reference/strings.html#%28def._%28%28quote._~23~25kernel%29._string%29%29" class="RktValLink" data-pltdoc="x">string</a></span> pairs between the Racket-argument brackets. The only caveat is that the symbols have to begin with a quote mark <span class="RktInBG"><span class="hspace"></span><span class="RktIn">'</span><span class="hspace"></span></span> and end with a colon <span class="RktInBG"><span class="hspace"></span><span class="RktIn">:</span><span class="hspace"></span></span>. So taken together, they look like this:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym"><a href="http://docs.racket-lang.org/scribble/base.html#%28def._%28%28lib._scribble%2Fbase..rkt%29._title%29%29" class="RktValLink" data-pltdoc="x">title</a></span><span class="RktPn">[</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quote.html#%28form._%28%28quote._~23~25kernel%29._quote%29%29" class="RktStxLink" data-pltdoc="x">'</a></span><span class="RktSym">class:</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"red"</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quote.html#%28form._%28%28quote._~23~25kernel%29._quote%29%29" class="RktStxLink" data-pltdoc="x">'</a></span><span class="RktSym">id:</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"first"</span><span class="RktPn">]</span><span class="RktPn">{</span><span class="RktMeta">The</span><span class="hspace"> </span><span class="RktMeta">Beginning</span><span class="hspace"> </span><span class="RktMeta">of</span><span class="hspace"> </span><span class="RktMeta">the</span><span class="hspace"> </span><span class="RktMeta">End</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(title ((class "red") (id "first")) "The Beginning of the End")</span></p><p>Racket arguments can be any valid Racket expressions. For instance, this will also work:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym"><a href="http://docs.racket-lang.org/scribble/base.html#%28def._%28%28lib._scribble%2Fbase..rkt%29._title%29%29" class="RktValLink" data-pltdoc="x">title</a></span><span class="RktPn">[</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quote.html#%28form._%28%28quote._~23~25kernel%29._quote%29%29" class="RktStxLink" data-pltdoc="x">'</a></span><span class="RktSym">class:</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/Writing.html#%28def._%28%28quote._~23~25kernel%29._format%29%29" class="RktValLink" data-pltdoc="x">format</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"~a"</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2A%29%29" class="RktValLink" data-pltdoc="x">*</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">6</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">7</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quote.html#%28form._%28%28quote._~23~25kernel%29._quote%29%29" class="RktStxLink" data-pltdoc="x">'</a></span><span class="RktSym">id:</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"first"</span><span class="RktPn">]</span><span class="RktPn">{</span><span class="RktMeta">The</span><span class="hspace"> </span><span class="RktMeta">Beginning</span><span class="hspace"> </span><span class="RktMeta">of</span><span class="hspace"> </span><span class="RktMeta">the</span><span class="hspace"> </span><span class="RktMeta">End</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(title ((class "42") (id "first")) "The Beginning of the End")</span></p><p>Since Pollen commands are really just Racket arguments underneath, you can use those too. Here, we’ll define a variable called <span class="stt">name</span> and use it in the Racket arguments of <span class="stt">title</span>:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">name</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"Brennan"</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym"><a href="http://docs.racket-lang.org/scribble/base.html#%28def._%28%28lib._scribble%2Fbase..rkt%29._title%29%29" class="RktValLink" data-pltdoc="x">title</a></span><span class="RktPn">[</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quote.html#%28form._%28%28quote._~23~25kernel%29._quote%29%29" class="RktStxLink" data-pltdoc="x">'</a></span><span class="RktSym">class:</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"red"</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quote.html#%28form._%28%28quote._~23~25kernel%29._quote%29%29" class="RktStxLink" data-pltdoc="x">'</a></span><span class="RktSym">id:</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta">◊</span><span class="RktSym">name</span><span class="RktPn">]</span><span class="RktPn">{</span><span class="RktMeta">The</span><span class="hspace"> </span><span class="RktMeta">Beginning</span><span class="hspace"> </span><span class="RktMeta">of</span><span class="hspace"> </span><span class="RktMeta">the</span><span class="hspace"> </span><span class="RktMeta">End</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(title ((class "read") (id "Brennan")) "The Beginning of the End")</span></p><p>You can also use this area for <span style="font-style: italic">keyword arguments</span>. Keyword arguments can be used to provide options for a particular Pollen command, to avoid redundancy. Suppose that instead of using the <span class="stt">h1 ... h6</span> tags, you want to consolidate them into one command called <span class="stt">heading</span> and select the level separately. You can do this with a keyword, in this case <span class="RktPn">#:level</span>, which is passed as a Racket argument:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym">heading</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">#:level</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">which</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">text</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quasiquote.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._quasiquote%29%29" class="RktStxLink" data-pltdoc="x">`</a></span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quasiquote.html#%28form._%28%28quote._~23~25kernel%29._unquote%29%29" class="RktStxLink" data-pltdoc="x">,</a></span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/symbols.html#%28def._%28%28quote._~23~25kernel%29._string-~3esymbol%29%29" class="RktValLink" data-pltdoc="x">string->symbol</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/Writing.html#%28def._%28%28quote._~23~25kernel%29._format%29%29" class="RktValLink" data-pltdoc="x">format</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">"h~a"</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">which</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quasiquote.html#%28form._%28%28quote._~23~25kernel%29._unquote%29%29" class="RktStxLink" data-pltdoc="x">,</a></span><span class="RktSym">text</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta"> </span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">heading</span><span class="RktPn">[</span><span class="RktPn">#:level</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">1</span><span class="RktPn">]</span><span class="RktPn">{</span><span class="RktMeta">Major</span><span class="hspace"> </span><span class="RktMeta">league</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">heading</span><span class="RktPn">[</span><span class="RktPn">#:level</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">2</span><span class="RktPn">]</span><span class="RktPn">{</span><span class="RktMeta">Minor</span><span class="hspace"> </span><span class="RktMeta">league</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">heading</span><span class="RktPn">[</span><span class="RktPn">#:level</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">6</span><span class="RktPn">]</span><span class="RktPn">{</span><span class="RktMeta">Trivial</span><span class="hspace"> </span><span class="RktMeta">league</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(h1 "Major league") <br/>
|
|
'(h2 "Minor league") <br/>
|
|
'(h6 "Trivial league")</span></p><h5>7.3.3<tt> </tt><a name="(part._.The_text_argument)"></a>The text argument</h5><p>The third part of a text-mode Pollen command is the text argument. The text argument <span class="RktInBG"><span class="hspace"></span><span class="RktIn">{</span><span class="hspace"></span></span>appears between curly braces<span class="RktInBG"><span class="hspace"></span><span class="RktIn">}</span><span class="hspace"></span></span>. It can contain any text you want. The text argument can also contain other Pollen commands with their own text arguments. And they can contain other Pollen commands ... and so on, all the way down.</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">div</span><span class="RktPn">{</span><span class="RktMeta">Do</span><span class="hspace"> </span><span class="RktMeta">it</span><span class="hspace"> </span><span class="RktMeta">again.</span><span class="hspace"> </span><span class="RktMeta">◊</span><span class="RktSym">div</span><span class="RktPn">{</span><span class="RktMeta">And</span><span class="hspace"> </span><span class="RktMeta">again.</span><span class="hspace"> </span><span class="RktMeta">◊</span><span class="RktSym">div</span><span class="RktPn">{</span><span class="RktMeta">And</span><span class="hspace"> </span><span class="RktMeta">yet</span><span class="hspace"> </span><span class="RktMeta">again.</span><span class="RktPn">}</span><span class="RktPn">}</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(div "Do it again. " (div "And again. " (div "And yet again.")))</span></p><p>Three small details to know about the text argument.</p><p>First, the only character that needs special handling in a text argument is the lozenge <span class="RktInBG"><span class="hspace"></span><span class="RktIn">◊</span><span class="hspace"></span></span>. A lozenge ordinarily marks a new command. So if you want an actual lozenge to appear in the text, you have to escape it by typing <span class="RktInBG"><span class="hspace"></span><span class="RktIn">◊"◊"</span><span class="hspace"></span></span>.</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">definition</span><span class="RktPn">{</span><span class="RktMeta">This</span><span class="hspace"> </span><span class="RktMeta">is</span><span class="hspace"> </span><span class="RktMeta">the</span><span class="hspace"> </span><span class="RktMeta">lozenge:</span><span class="hspace"> </span><span class="RktMeta">◊</span><span class="RktVal">"◊"</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(definition "This is the lozenge: ◊")</span></p><p>Second, the whitespace-trimming policy. Here’s the short version: if there’s a carriage return at either end of the text argument, it is trimmed, and whitespace at the end of each line is selectively trimmed in an intelligent way. So this text argument, with carriage returns on the ends:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">div</span><span class="RktPn">{</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">Roomy!</span></td></tr><tr><td><span class="RktMeta"> </span></td></tr><tr><td><span class="RktMeta">I</span><span class="hspace"> </span><span class="RktMeta">agree.</span></td></tr><tr><td><span class="RktMeta"></span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(div "Roomy!" "\n" "\n" "I agree.")</span></p><p>Yields the same result as this one:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">div</span><span class="RktPn">{</span><span class="RktMeta">Roomy!</span></td></tr><tr><td><span class="RktMeta"> </span></td></tr><tr><td><span class="RktMeta">I</span><span class="hspace"> </span><span class="RktMeta">agree.</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(div "Roomy!" "\n" "\n" "I agree.")</span></p><p>For the long version, please see [future link: Spaces, Newlines, and Indentation].</p><p>Third, within a multiline text argument, newline characters become individual strings that are not merged with adjacent text. So what you end up with is a list of strings, not a single string. That’s why in the last example, we got this:</p><p><span class="RktOut">'(div "Roomy!" "\n" "\n" "I agree.")</span></p><p>Instead of this:</p><p><span class="RktOut">'(div "Roomy!\n\nI agree.")</span></p><p>Under most circumstances, these two tagged X-expressions will behave the same way. The biggest exception is with functions. A function that operates on multiline text arguments needs to be able to handle an indefinite number of strings. For instance, this <span class="stt">jejune</span> function only accepts a single argument. It will work with a single-line text argument, because that produces a single string:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym">jejune</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">text</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quasiquote.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._quasiquote%29%29" class="RktStxLink" data-pltdoc="x">`</a></span><span class="RktPn">(</span><span class="RktSym">jejune</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quasiquote.html#%28form._%28%28quote._~23~25kernel%29._unquote%29%29" class="RktStxLink" data-pltdoc="x">,</a></span><span class="RktSym">text</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">jejune</span><span class="RktPn">{</span><span class="RktMeta">Irrational</span><span class="hspace"> </span><span class="RktMeta">confidence</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(jejune "Irrational confidence")</span></p><p>But watch what happens with a multiline text argument:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym">jejune</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">text</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quasiquote.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._quasiquote%29%29" class="RktStxLink" data-pltdoc="x">`</a></span><span class="RktPn">(</span><span class="RktSym">jejune</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quasiquote.html#%28form._%28%28quote._~23~25kernel%29._unquote%29%29" class="RktStxLink" data-pltdoc="x">,</a></span><span class="RktSym">text</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">jejune</span><span class="RktPn">{</span><span class="RktMeta">Deeply</span></td></tr><tr><td><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta">chastened</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktErr">jejune: arity mismatch;<br/>
|
|
the expected number of arguments does not match the given number<br/>
|
|
  expected: 1<br/>
|
|
  given: 3<br/>
|
|
  arguments...:<br/>
|
|
   "Deeply"<br/>
|
|
   "\n"<br/>
|
|
   "chastened"</span></p><p>The answer is to use a <span style="font-style: italic">rest argument</span> in the function, which takes the “rest” of the arguments — however many there may be — and combines them into a single <span class="RktSym"><a href="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29" class="RktValLink" data-pltdoc="x">list</a></span>. If we rewrite <span class="stt">jejune</span> with a rest argument, we can fix the problem:</p><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="RktMeta">#lang</span><span class="hspace"> </span><span class="RktMeta"></span><a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktPn">(</span><span class="RktSym"><a href="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><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym">jejune</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktMeta">.</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">texts</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quasiquote.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._quasiquote%29%29" class="RktStxLink" data-pltdoc="x">`</a></span><span class="RktPn">(</span><span class="RktSym">jejune</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/quasiquote.html#%28form._%28%28quote._~23~25kernel%29._unquote-splicing%29%29" class="RktStxLink" data-pltdoc="x">,@</a></span><span class="RktSym">texts</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta">◊</span><span class="RktSym">jejune</span><span class="RktPn">{</span><span class="RktMeta">Deeply</span></td></tr><tr><td><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta">chastened</span><span class="RktPn">}</span><span class="RktMeta"></span></td></tr></table></blockquote><p><span class="RktOut">'(jejune "Deeply" "\n" "chastened")</span></p><h4>7.4<tt> </tt><a name="(part._.Further_reading)"></a>Further reading</h4><p>The Pollen language is a variant of Racket’s own text-processing language, called Scribble. So many things that are true about Scribble are also true about Pollen. For the sake of clarity & brevity, I’ve omitted them from this summary. But if you want the full story, see <a href="http://docs.racket-lang.org/scribble/reader.html" data-pltdoc="x">@ Syntax</a> in the Scribble documentation.</p><div class="navsetbottom"><span class="navleft"> </span><span class="navright"> <a href="File_formats.html" title="backward to "6 File formats"" data-pltdoc="x">← prev</a> <a href="index.html" title="up to "Pollen: the book is a program"" data-pltdoc="x">up</a> <a href="Module_reference.html" title="forward to "8 Module reference"" data-pltdoc="x">next →</a></span> </div></div></div><div id="contextindicator"> </div></body></html> |