<pre><code>coffee> console.log "#{num} bottles of beer" for num in [99..1]
</code></pre></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-2"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-2">¶</a></div><p>Require the <strong>coffee-script</strong> module to get access to the compiler.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">CoffeeScript = </span><spanclass="nx">require</span><spanclass="s1">'./coffee-script'</span>
<spanclass="nv">readline = </span><spanclass="nx">require</span><spanclass="s1">'readline'</span></pre></div></td></tr><trid="section-3"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-3">¶</a></div><p>Start by opening up <strong>stdio</strong>.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">stdio = </span><spanclass="nx">process</span><spanclass="p">.</span><spanclass="nx">openStdin</span><spanclass="p">()</span></pre></div></td></tr><trid="section-4"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-4">¶</a></div><p>Log an error.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">error = </span><spanclass="p">(</span><spanclass="nx">err</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="nx">stdio</span><spanclass="p">.</span><spanclass="nx">write</span><spanclass="p">(</span><spanclass="nx">err</span><spanclass="p">.</span><spanclass="nx">stack</span><spanclass="o">or</span><spanclass="nx">err</span><spanclass="p">.</span><spanclass="nx">toString</span><spanclass="p">())</span><spanclass="o">+</span><spanclass="s1">'\n\n'</span></pre></div></td></tr><trid="section-5"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-5">¶</a></div><p>Quick alias for quitting the REPL.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nx">helpers</span><spanclass="p">.</span><spanclass="nx">extend</span><spanclass="nx">global</span><spanclass="p">,</span><spanclass="nx">quit</span><spanclass="o">:</span><spanclass="o">-></span><spanclass="nx">process</span><spanclass="p">.</span><spanclass="nx">exit</span><spanclass="p">(</span><spanclass="mi">0</span><spanclass="p">)</span></pre></div></td></tr><trid="section-6"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-6">¶</a></div><p>The main REPL function. <strong>run</strong> is called every time a line of code is entered.
of exiting.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">run = </span><spanclass="p">(</span><spanclass="nx">buffer</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="nx">repl</span><spanclass="p">.</span><spanclass="nx">prompt</span><spanclass="p">()</span></pre></div></td></tr><trid="section-7"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-7">¶</a></div><p>Make sure that uncaught exceptions don't kill the REPL.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nx">process</span><spanclass="p">.</span><spanclass="kc">on</span><spanclass="s1">'uncaughtException'</span><spanclass="p">,</span><spanclass="nx">error</span></pre></div></td></tr><trid="section-8"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-8">¶</a></div><p>Create the REPL by listening to <strong>stdin</strong>.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">repl = </span><spanclass="nx">readline</span><spanclass="p">.</span><spanclass="nx">createInterface</span><spanclass="nx">stdio</span>