miller/docs6/docs/_build/html/reference-dsl-overview.html

3504 lines
No EOL
295 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>DSL reference &#8212; Miller 6.0.0-alpha documentation</title>
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/language_data.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Manpage" href="manpage.html" />
<link rel="prev" title="Verbs reference" href="reference-verbs.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="manpage.html" title="Manpage"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="reference-verbs.html" title="Verbs reference"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Miller 6.0.0-alpha documentation</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">DSL reference</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="dsl-reference">
<h1>DSL reference<a class="headerlink" href="#dsl-reference" title="Permalink to this headline"></a></h1>
<div class="section" id="overview">
<h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline"></a></h2>
<p>Heres comparison of verbs and <code class="docutils literal notranslate"><span class="pre">put</span></code>/<code class="docutils literal notranslate"><span class="pre">filter</span></code> DSL expressions:</p>
<p>Example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr stats1 -a sum -f x -g a data/small
</span> a=pan,x_sum=0.3467901443380824
a=eks,x_sum=1.1400793586611044
a=wye,x_sum=0.7778922255683036
</pre></div>
</div>
<ul class="simple">
<li><p>Verbs are coded in Go</p></li>
<li><p>They run a bit faster</p></li>
<li><p>They take fewer keystrokes</p></li>
<li><p>There is less to learn</p></li>
<li><p>Their customization is limited to each verbs options</p></li>
</ul>
<p>Example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@x_sum[$a] += $x; end{emit @x_sum, &quot;a&quot;}&#39; data/small
</span> a=pan,x_sum=0.3467901443380824
a=eks,x_sum=1.1400793586611044
a=wye,x_sum=0.7778922255683036
</pre></div>
</div>
<ul class="simple">
<li><p>You get to write your own DSL expressions</p></li>
<li><p>They run a bit slower</p></li>
<li><p>They take more keystrokes</p></li>
<li><p>There is more to learn</p></li>
<li><p>They are highly customizable</p></li>
</ul>
<p>Please see <a class="reference internal" href="reference-verbs.html"><span class="doc">Verbs reference</span></a> for information on verbs other than <code class="docutils literal notranslate"><span class="pre">put</span></code> and <code class="docutils literal notranslate"><span class="pre">filter</span></code>.</p>
<p>The essential usages of <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">filter</span></code> and <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span></code> are for record-selection and record-updating expressions, respectively. For example, given the following input data:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ cat data/small
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729
</pre></div>
</div>
<p>you might retain only the records whose <code class="docutils literal notranslate"><span class="pre">a</span></code> field has value <code class="docutils literal notranslate"><span class="pre">eks</span></code>:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr filter &#39;$a == &quot;eks&quot;&#39; data/small
</span> a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463
</pre></div>
</div>
<p>or you might add a new field which is a function of existing fields:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;$ab = $a . &quot;_&quot; . $b &#39; data/small
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533,ab=pan_pan
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797,ab=eks_pan
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776,ab=wye_wye
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463,ab=eks_wye
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729,ab=wye_pan
</pre></div>
</div>
<p>The two verbs <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">filter</span></code> and <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span></code> are essentially the same. The only differences are:</p>
<ul class="simple">
<li><p>Expressions sent to <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">filter</span></code> must end with a boolean expression, which is the filtering criterion;</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">filter</span></code> expressions may not reference the <code class="docutils literal notranslate"><span class="pre">filter</span></code> keyword within them; and</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">filter</span></code> expressions may not use <code class="docutils literal notranslate"><span class="pre">tee</span></code>, <code class="docutils literal notranslate"><span class="pre">emit</span></code>, <code class="docutils literal notranslate"><span class="pre">emitp</span></code>, or <code class="docutils literal notranslate"><span class="pre">emitf</span></code>.</p></li>
</ul>
<p>All the rest is the same: in particular, you can define and invoke functions and subroutines to help produce the final boolean statement, and record fields may be assigned to in the statements preceding the final boolean statement.</p>
<p>There are more details and more choices, of course, as detailed in the following sections.</p>
</div>
<div class="section" id="syntax">
<h2>Syntax<a class="headerlink" href="#syntax" title="Permalink to this headline"></a></h2>
<div class="section" id="expression-formatting">
<h3>Expression formatting<a class="headerlink" href="#expression-formatting" title="Permalink to this headline"></a></h3>
<p>Multiple expressions may be given, separated by semicolons, and each may refer to the ones before:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ ruby -e &#39;10.times{|i|puts &quot;i=#{i}&quot;}&#39; | mlr --opprint put &#39;$j = $i + 1; $k = $i +$j&#39;
</span> i j k
0 1 1
1 2 3
2 3 5
3 4 7
4 5 9
5 6 11
6 7 13
7 8 15
8 9 17
9 10 19
</pre></div>
</div>
<p>Newlines within the expression are ignored, which can help increase legibility of complex expressions:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --opprint put &#39;
</span><span class="hll"> $nf = NF;
</span><span class="hll"> $nr = NR;
</span><span class="hll"> $fnr = FNR;
</span><span class="hll"> $filenum = FILENUM;
</span><span class="hll"> $filename = FILENAME
</span><span class="hll"> &#39; data/small data/small2
</span> a b i x y nf nr fnr filenum filename
pan pan 1 0.3467901443380824 0.7268028627434533 5 1 1 1 data/small
eks pan 2 0.7586799647899636 0.5221511083334797 5 2 2 1 data/small
wye wye 3 0.20460330576630303 0.33831852551664776 5 3 3 1 data/small
eks wye 4 0.38139939387114097 0.13418874328430463 5 4 4 1 data/small
wye pan 5 0.5732889198020006 0.8636244699032729 5 5 5 1 data/small
pan eks 9999 0.267481232652199086 0.557077185510228001 5 6 1 2 data/small2
wye eks 10000 0.734806020620654365 0.884788571337605134 5 7 2 2 data/small2
pan wye 10001 0.870530722602517626 0.009854780514656930 5 8 3 2 data/small2
hat wye 10002 0.321507044286237609 0.568893318795083758 5 9 4 2 data/small2
pan zee 10003 0.272054845593895200 0.425789896597056627 5 10 5 2 data/small2
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --opprint filter &#39;($x &gt; 0.5 &amp;&amp; $y &lt; 0.5) || ($x &lt; 0.5 &amp;&amp; $y &gt; 0.5)&#39; then stats2 -a corr -f x,y data/medium
</span> x_y_corr
-0.7479940285189345
</pre></div>
</div>
</div>
<div class="section" id="expressions-from-files">
<span id="reference-dsl-expressions-from-files"></span><h3>Expressions from files<a class="headerlink" href="#expressions-from-files" title="Permalink to this headline"></a></h3>
<p>The simplest way to enter expressions for <code class="docutils literal notranslate"><span class="pre">put</span></code> and <code class="docutils literal notranslate"><span class="pre">filter</span></code> is between single quotes on the command line, e.g.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/small put &#39;$xy = sqrt($x**2 + $y**2)&#39;
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533,xy=0.8052985815845617
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797,xy=0.9209978658539777
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776,xy=0.3953756915115773
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463,xy=0.40431685157744135
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729,xy=1.036584492737304
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/small put &#39;func f(a, b) { return sqrt(a**2 + b**2) } $xy = f($x, $y)&#39;
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533,xy=0.8052985815845617
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797,xy=0.9209978658539777
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776,xy=0.3953756915115773
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463,xy=0.40431685157744135
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729,xy=1.036584492737304
</pre></div>
</div>
<p>You may, though, find it convenient to put expressions into files for reuse, and read them
<strong>using the -f option</strong>. For example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ cat data/fe-example-3.mlr
</span> func f(a, b) {
return sqrt(a**2 + b**2)
}
$xy = f($x, $y)
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/small put -f data/fe-example-3.mlr
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533,xy=0.8052985815845617
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797,xy=0.9209978658539777
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776,xy=0.3953756915115773
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463,xy=0.40431685157744135
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729,xy=1.036584492737304
</pre></div>
</div>
<p>If you have some of the logic in a file and you want to write the rest on the command line, you can <strong>use the -f and -e options together</strong>:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ cat data/fe-example-4.mlr
</span> func f(a, b) {
return sqrt(a**2 + b**2)
}
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/small put -f data/fe-example-4.mlr -e &#39;$xy = f($x, $y)&#39;
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533,xy=0.8052985815845617
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797,xy=0.9209978658539777
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776,xy=0.3953756915115773
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463,xy=0.40431685157744135
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729,xy=1.036584492737304
</pre></div>
</div>
<p>A suggested use-case here is defining functions in files, and calling them from command-line expressions.</p>
<p>Another suggested use-case is putting default parameter values in files, e.g. using <code class="docutils literal notranslate"><span class="pre">begin{&#64;count=is_present(&#64;count)?&#64;count:10}</span></code> in the file, where you can precede that using <code class="docutils literal notranslate"><span class="pre">begin{&#64;count=40}</span></code> using <code class="docutils literal notranslate"><span class="pre">-e</span></code>.</p>
<p>Moreover, you can have one or more <code class="docutils literal notranslate"><span class="pre">-f</span></code> expressions (maybe one function per file, for example) and one or more <code class="docutils literal notranslate"><span class="pre">-e</span></code> expressions on the command line. If you mix <code class="docutils literal notranslate"><span class="pre">-f</span></code> and <code class="docutils literal notranslate"><span class="pre">-e</span></code> then the expressions are evaluated in the order encountered. (Since the expressions are all simply concatenated together in order, dont forget intervening semicolons: e.g. not <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span> <span class="pre">-e</span> <span class="pre">'$x=1'</span> <span class="pre">-e</span> <span class="pre">'$y=2</span> <span class="pre">...'</span></code> but rather <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span> <span class="pre">-e</span> <span class="pre">'$x=1;'</span> <span class="pre">-e</span> <span class="pre">'$y=2'</span> <span class="pre">...</span></code>.)</p>
</div>
<div class="section" id="semicolons-commas-newlines-and-curly-braces">
<h3>Semicolons, commas, newlines, and curly braces<a class="headerlink" href="#semicolons-commas-newlines-and-curly-braces" title="Permalink to this headline"></a></h3>
<p>Miller uses <strong>semicolons as statement separators</strong>, not statement terminators. This means you can write:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>mlr put &#39;x=1&#39;
mlr put &#39;x=1;$y=2&#39;
mlr put &#39;x=1;$y=2;&#39;
mlr put &#39;x=1;;;;$y=2;&#39;
</pre></div>
</div>
<p>Semicolons are optional after closing curly braces (which close conditionals and loops as discussed below).</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ echo x=1,y=2 | mlr put &#39;while (NF &lt; 10) { $[NF+1] = &quot;&quot;} $foo = &quot;bar&quot;&#39;
</span> x=1,y=2,3=,4=,5=,6=,7=,8=,9=,10=,foo=bar
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ echo x=1,y=2 | mlr put &#39;while (NF &lt; 10) { $[NF+1] = &quot;&quot;}; $foo = &quot;bar&quot;&#39;
</span> x=1,y=2,3=,4=,5=,6=,7=,8=,9=,10=,foo=bar
</pre></div>
</div>
<p>Semicolons are required between statements even if those statements are on separate lines. <strong>Newlines</strong> are for your convenience but have no syntactic meaning: line endings do not terminate statements. For example, adjacent assignment statements must be separated by semicolons even if those statements are on separate lines:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>mlr put &#39;
$x = 1
$y = 2 # Syntax error
&#39;
mlr put &#39;
$x = 1;
$y = 2 # This is OK
&#39;
</pre></div>
</div>
<p><strong>Trailing commas</strong> are allowed in function/subroutine definitions, function/subroutine callsites, and map literals. This is intended for (although not restricted to) the multi-line case:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --csvlite --from data/a.csv put &#39;
</span><span class="hll"> func f(
</span><span class="hll"> num a,
</span><span class="hll"> num b,
</span><span class="hll"> ): num {
</span><span class="hll"> return a**2 + b**2;
</span><span class="hll"> }
</span><span class="hll"> $* = {
</span><span class="hll"> &quot;s&quot;: $a + $b,
</span><span class="hll"> &quot;t&quot;: $a - $b,
</span><span class="hll"> &quot;u&quot;: f(
</span><span class="hll"> $a,
</span><span class="hll"> $b,
</span><span class="hll"> ),
</span><span class="hll"> &quot;v&quot;: NR,
</span><span class="hll"> }
</span><span class="hll"> &#39;
</span></pre></div>
</div>
<p>Bodies for all compound statements must be enclosed in <strong>curly braces</strong>, even if the body is a single statement:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> mlr put &#39;if ($x == 1) $y = 2&#39; # Syntax error
</span></pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> mlr put &#39;if ($x == 1) { $y = 2 }&#39; # This is OK
</span></pre></div>
</div>
<p>Bodies for compound statements may be empty:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> mlr put &#39;if ($x == 1) { }&#39; # This no-op is syntactically acceptable
</span></pre></div>
</div>
</div>
</div>
<div class="section" id="variables">
<h2>Variables<a class="headerlink" href="#variables" title="Permalink to this headline"></a></h2>
<p>Miller has the following kinds of variables:</p>
<p><strong>Built-in variables</strong> such as <code class="docutils literal notranslate"><span class="pre">NF</span></code>, <code class="docutils literal notranslate"><span class="pre">NF</span></code>, <code class="docutils literal notranslate"><span class="pre">FILENAME</span></code>, <code class="docutils literal notranslate"><span class="pre">M_PI</span></code>, and <code class="docutils literal notranslate"><span class="pre">M_E</span></code>. These are all capital letters and are read-only (although some of them change value from one record to another).</p>
<p><strong>Fields of stream records</strong>, accessed using the <code class="docutils literal notranslate"><span class="pre">$</span></code> prefix. These refer to fields of the current data-stream record. For example, in <code class="docutils literal notranslate"><span class="pre">echo</span> <span class="pre">x=1,y=2</span> <span class="pre">|</span> <span class="pre">mlr</span> <span class="pre">put</span> <span class="pre">'$z</span> <span class="pre">=</span> <span class="pre">$x</span> <span class="pre">+</span> <span class="pre">$y'</span></code>, <code class="docutils literal notranslate"><span class="pre">$x</span></code> and <code class="docutils literal notranslate"><span class="pre">$y</span></code> refer to input fields, and <code class="docutils literal notranslate"><span class="pre">$z</span></code> refers to a new, computed output field. In a few contexts, presented below, you can refer to the entire record as <code class="docutils literal notranslate"><span class="pre">$*</span></code>.</p>
<p><strong>Out-of-stream variables</strong> accessed using the <code class="docutils literal notranslate"><span class="pre">&#64;</span></code> prefix. These refer to data which persist from one record to the next, including in <code class="docutils literal notranslate"><span class="pre">begin</span></code> and <code class="docutils literal notranslate"><span class="pre">end</span></code> blocks (which execute before/after the record stream is consumed, respectively). You use them to remember values across records, such as sums, differences, counters, and so on. In a few contexts, presented below, you can refer to the entire out-of-stream-variables collection as <code class="docutils literal notranslate"><span class="pre">&#64;*</span></code>.</p>
<p><strong>Local variables</strong> are limited in scope and extent to the current statements being executed: these include function arguments, bound variables in for loops, and explicitly declared local variables.</p>
<p><strong>Keywords</strong> are not variables, but since their names are reserved, you cannot use these names for local variables.</p>
<div class="section" id="built-in-variables">
<h3>Built-in variables<a class="headerlink" href="#built-in-variables" title="Permalink to this headline"></a></h3>
<p>These are written all in capital letters, such as <code class="docutils literal notranslate"><span class="pre">NR</span></code>, <code class="docutils literal notranslate"><span class="pre">NF</span></code>, <code class="docutils literal notranslate"><span class="pre">FILENAME</span></code>, and only a small, specific set of them is defined by Miller.</p>
<p>Namely, Miller supports the following five built-in variables for <span class="xref std std-doc">filter and put</span>, all <code class="docutils literal notranslate"><span class="pre">awk</span></code>-inspired: <code class="docutils literal notranslate"><span class="pre">NF</span></code>, <code class="docutils literal notranslate"><span class="pre">NR</span></code>, <code class="docutils literal notranslate"><span class="pre">FNR</span></code>, <code class="docutils literal notranslate"><span class="pre">FILENUM</span></code>, and <code class="docutils literal notranslate"><span class="pre">FILENAME</span></code>, as well as the mathematical constants <code class="docutils literal notranslate"><span class="pre">M_PI</span></code> and <code class="docutils literal notranslate"><span class="pre">M_E</span></code>. Lastly, the <code class="docutils literal notranslate"><span class="pre">ENV</span></code> hashmap allows read access to environment variables, e.g. <code class="docutils literal notranslate"><span class="pre">ENV[&quot;HOME&quot;]</span></code> or <code class="docutils literal notranslate"><span class="pre">ENV[&quot;foo_&quot;.$hostname]</span></code>.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr filter &#39;FNR == 2&#39; data/small*
</span> a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
1=pan,2=pan,3=1,4=0.3467901443380824,5=0.7268028627434533
a=wye,b=eks,i=10000,x=0.734806020620654365,y=0.884788571337605134
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;$fnr = FNR&#39; data/small*
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533,fnr=1
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797,fnr=2
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776,fnr=3
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463,fnr=4
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729,fnr=5
1=a,2=b,3=i,4=x,5=y,fnr=1
1=pan,2=pan,3=1,4=0.3467901443380824,5=0.7268028627434533,fnr=2
1=eks,2=pan,3=2,4=0.7586799647899636,5=0.5221511083334797,fnr=3
1=wye,2=wye,3=3,4=0.20460330576630303,5=0.33831852551664776,fnr=4
1=eks,2=wye,3=4,4=0.38139939387114097,5=0.13418874328430463,fnr=5
1=wye,2=pan,3=5,4=0.5732889198020006,5=0.8636244699032729,fnr=6
a=pan,b=eks,i=9999,x=0.267481232652199086,y=0.557077185510228001,fnr=1
a=wye,b=eks,i=10000,x=0.734806020620654365,y=0.884788571337605134,fnr=2
a=pan,b=wye,i=10001,x=0.870530722602517626,y=0.009854780514656930,fnr=3
a=hat,b=wye,i=10002,x=0.321507044286237609,y=0.568893318795083758,fnr=4
a=pan,b=zee,i=10003,x=0.272054845593895200,y=0.425789896597056627,fnr=5
</pre></div>
</div>
<p>Their values of <code class="docutils literal notranslate"><span class="pre">NF</span></code>, <code class="docutils literal notranslate"><span class="pre">NR</span></code>, <code class="docutils literal notranslate"><span class="pre">FNR</span></code>, <code class="docutils literal notranslate"><span class="pre">FILENUM</span></code>, and <code class="docutils literal notranslate"><span class="pre">FILENAME</span></code> change from one record to the next as Miller scans through your input data stream. The mathematical constants, of course, do not change; <code class="docutils literal notranslate"><span class="pre">ENV</span></code> is populated from the system environment variables at the time Miller starts and is read-only for the remainder of program execution.</p>
<p>Their <strong>scope is global</strong>: you can refer to them in any <code class="docutils literal notranslate"><span class="pre">filter</span></code> or <code class="docutils literal notranslate"><span class="pre">put</span></code> statement. Their values are assigned by the input-record reader:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --csv put &#39;$nr = NR&#39; data/a.csv
</span> X,Y,Z,nr
m,n,o,1
p,q,r,2
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --csv repeat -n 3 then put &#39;$nr = NR&#39; data/a.csv
</span> X,Y,Z,nr
m,n,o,1
m,n,o,1
m,n,o,1
p,q,r,2
p,q,r,2
p,q,r,2
</pre></div>
</div>
<p>The <strong>extent</strong> is for the duration of the put/filter: in a <code class="docutils literal notranslate"><span class="pre">begin</span></code> statement (which executes before the first input record is consumed) you will find <code class="docutils literal notranslate"><span class="pre">NR=1</span></code> and in an <code class="docutils literal notranslate"><span class="pre">end</span></code> statement (which is executed after the last input record is consumed) you will find <code class="docutils literal notranslate"><span class="pre">NR</span></code> to be the total number of records ingested.</p>
<p>These are all <strong>read-only</strong> for the <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span></code> and <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">filter</span></code> DSLs: they may be assigned from, e.g. <code class="docutils literal notranslate"><span class="pre">$nr=NR</span></code>, but they may not be assigned to: <code class="docutils literal notranslate"><span class="pre">NR=100</span></code> is a syntax error.</p>
</div>
<div class="section" id="field-names">
<h3>Field names<a class="headerlink" href="#field-names" title="Permalink to this headline"></a></h3>
<p>Names of fields within stream records must be specified using a <code class="docutils literal notranslate"><span class="pre">$</span></code> in <span class="xref std std-doc">filter and put expressions</span>, even though the dollar signs dont appear in the data stream itself. For integer-indexed data, this looks like <code class="docutils literal notranslate"><span class="pre">awk</span></code>s <code class="docutils literal notranslate"><span class="pre">$1,$2,$3</span></code>, except that Miller allows non-numeric names such as <code class="docutils literal notranslate"><span class="pre">$quantity</span></code> or <code class="docutils literal notranslate"><span class="pre">$hostname</span></code>. Likewise, enclose string literals in double quotes in <code class="docutils literal notranslate"><span class="pre">filter</span></code> expressions even though they dont appear in file data. In particular, <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">filter</span> <span class="pre">'$x==&quot;abc&quot;'</span></code> passes through the record <code class="docutils literal notranslate"><span class="pre">x=abc</span></code>.</p>
<p>If field names have <strong>special characters</strong> such as <code class="docutils literal notranslate"><span class="pre">.</span></code> then you can use braces, e.g. <code class="docutils literal notranslate"><span class="pre">'${field.name}'</span></code>.</p>
<p>You may also use a <strong>computed field name</strong> in square brackets, e.g.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ echo a=3,b=4 | mlr filter &#39;$[&quot;x&quot;] &lt; 0.5&#39;
</span></pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ echo s=green,t=blue,a=3,b=4 | mlr put &#39;$[$s.&quot;_&quot;.$t] = $a * $b&#39;
</span> s=green,t=blue,a=3,b=4,green_blue=12
</pre></div>
</div>
<p>Notes:</p>
<p>The names of record fields depend on the contents of your input data stream, and their values change from one record to the next as Miller scans through your input data stream.</p>
<p>Their <strong>extent</strong> is limited to the current record; their <strong>scope</strong> is the <code class="docutils literal notranslate"><span class="pre">filter</span></code> or <code class="docutils literal notranslate"><span class="pre">put</span></code> command in which they appear.</p>
<p>These are <strong>read-write</strong>: you can do <code class="docutils literal notranslate"><span class="pre">$y=2*$x</span></code>, <code class="docutils literal notranslate"><span class="pre">$x=$x+1</span></code>, etc.</p>
<p>Records are Millers output: field names present in the input stream are passed through to output (written to standard output) unless fields are removed with <code class="docutils literal notranslate"><span class="pre">cut</span></code>, or records are excluded with <code class="docutils literal notranslate"><span class="pre">filter</span></code> or <code class="docutils literal notranslate"><span class="pre">put</span> <span class="pre">-q</span></code>, etc. Simply assign a value to a field and it will be output.</p>
</div>
<div class="section" id="positional-field-names">
<h3>Positional field names<a class="headerlink" href="#positional-field-names" title="Permalink to this headline"></a></h3>
<p>Even though Millers main selling point is name-indexing, sometimes you really want to refer to a field name by its positional index (starting from 1).</p>
<p>Use <code class="docutils literal notranslate"><span class="pre">$[[3]]</span></code> to access the name of field 3. More generally, any expression evaluating to an integer can go between <code class="docutils literal notranslate"><span class="pre">$[[</span></code> and <code class="docutils literal notranslate"><span class="pre">]]</span></code>.</p>
<p>Then using a computed field name, <code class="docutils literal notranslate"><span class="pre">$[</span> <span class="pre">$[[3]]</span> <span class="pre">]</span></code> is the value in the third field. This has the shorter equivalent notation <code class="docutils literal notranslate"><span class="pre">$[[[3]]]</span></code>.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr cat data/small
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;$[[3]] = &quot;NEW&quot;&#39; data/small
</span> a=pan,b=pan,NEW=1,x=0.3467901443380824,y=0.7268028627434533
a=eks,b=pan,NEW=2,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=wye,NEW=3,x=0.20460330576630303,y=0.33831852551664776
a=eks,b=wye,NEW=4,x=0.38139939387114097,y=0.13418874328430463
a=wye,b=pan,NEW=5,x=0.5732889198020006,y=0.8636244699032729
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;$[[[3]]] = &quot;NEW&quot;&#39; data/small
</span> a=pan,b=pan,i=NEW,x=0.3467901443380824,y=0.7268028627434533
a=eks,b=pan,i=NEW,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=wye,i=NEW,x=0.20460330576630303,y=0.33831852551664776
a=eks,b=wye,i=NEW,x=0.38139939387114097,y=0.13418874328430463
a=wye,b=pan,i=NEW,x=0.5732889198020006,y=0.8636244699032729
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;$NEW = $[[NR]]&#39; data/small
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533,NEW=a
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797,NEW=b
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776,NEW=i
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463,NEW=x
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729,NEW=y
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;$NEW = $[[[NR]]]&#39; data/small
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533,NEW=pan
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797,NEW=pan
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776,NEW=3
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463,NEW=0.38139939387114097
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729,NEW=0.8636244699032729
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;$[[[NR]]] = &quot;NEW&quot;&#39; data/small
</span> a=NEW,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533
a=eks,b=NEW,i=2,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=wye,i=NEW,x=0.20460330576630303,y=0.33831852551664776
a=eks,b=wye,i=4,x=NEW,y=0.13418874328430463
a=wye,b=pan,i=5,x=0.5732889198020006,y=NEW
</pre></div>
</div>
<p>Right-hand side accesses to non-existent fields i.e. with index less than 1 or greater than <code class="docutils literal notranslate"><span class="pre">NF</span></code> return an absent value. Likewise, left-hand side accesses only refer to fields which already exist. For example, if a field has 5 records then assigning the name or value of the 6th (or 600th) field results in a no-op.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;$[[6]] = &quot;NEW&quot;&#39; data/small
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;$[[[6]]] = &quot;NEW&quot;&#39; data/small
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729
</pre></div>
</div>
</div>
<div class="section" id="out-of-stream-variables">
<h3>Out-of-stream variables<a class="headerlink" href="#out-of-stream-variables" title="Permalink to this headline"></a></h3>
<p>These are prefixed with an at-sign, e.g. <code class="docutils literal notranslate"><span class="pre">&#64;sum</span></code>. Furthermore, unlike built-in variables and stream-record fields, they are maintained in an arbitrarily nested hashmap: you can do <code class="docutils literal notranslate"><span class="pre">&#64;sum</span> <span class="pre">+=</span> <span class="pre">$quanity</span></code>, or <code class="docutils literal notranslate"><span class="pre">&#64;sum[$color]</span> <span class="pre">+=</span> <span class="pre">$quanity</span></code>, or <code class="docutils literal notranslate"><span class="pre">&#64;sum[$color][$shape]</span> <span class="pre">+=</span> <span class="pre">$quanity</span></code>. The keys for the multi-level hashmap can be any expression which evaluates to string or integer: e.g. <code class="docutils literal notranslate"><span class="pre">&#64;sum[NR]</span> <span class="pre">=</span> <span class="pre">$a</span> <span class="pre">+</span> <span class="pre">$b</span></code>, <code class="docutils literal notranslate"><span class="pre">&#64;sum[$a.&quot;-&quot;.$b]</span> <span class="pre">=</span> <span class="pre">$x</span></code>, etc.</p>
<p>Their names and their values are entirely under your control; they change only when you assign to them.</p>
<p>Just as for field names in stream records, if you want to define out-of-stream variables with <strong>special characters</strong> such as <code class="docutils literal notranslate"><span class="pre">.</span></code> then you can use braces, e.g. <code class="docutils literal notranslate"><span class="pre">'&#64;{variable.name}[&quot;index&quot;]'</span></code>.</p>
<p>You may use a <strong>computed key</strong> in square brackets, e.g.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ echo s=green,t=blue,a=3,b=4 | mlr put -q &#39;@[$s.&quot;_&quot;.$t] = $a * $b; emit all&#39;
</span> green_blue=12
</pre></div>
</div>
<p>Out-of-stream variables are <strong>scoped</strong> to the <code class="docutils literal notranslate"><span class="pre">put</span></code> command in which they appear. In particular, if you have two or more <code class="docutils literal notranslate"><span class="pre">put</span></code> commands separated by <code class="docutils literal notranslate"><span class="pre">then</span></code>, each put will have its own set of out-of-stream variables:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ cat data/a.dkvp
</span> a=1,b=2,c=3
a=4,b=5,c=6
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;@sum += $a; end {emit @sum}&#39; then put &#39;is_present($a) {$a=10*$a; @sum += $a}; end {emit @sum}&#39; data/a.dkvp
</span> a=10,b=2,c=3
a=40,b=5,c=6
sum=5
sum=50
</pre></div>
</div>
<p>Out-of-stream variables <strong>extent</strong> is from the start to the end of the record stream, i.e. every time the <code class="docutils literal notranslate"><span class="pre">put</span></code> or <code class="docutils literal notranslate"><span class="pre">filter</span></code> statement referring to them is executed.</p>
<p>Out-of-stream variables are <strong>read-write</strong>: you can do <code class="docutils literal notranslate"><span class="pre">$sum=&#64;sum</span></code>, <code class="docutils literal notranslate"><span class="pre">&#64;sum=$sum</span></code>, etc.</p>
</div>
<div class="section" id="indexed-out-of-stream-variables">
<h3>Indexed out-of-stream variables<a class="headerlink" href="#indexed-out-of-stream-variables" title="Permalink to this headline"></a></h3>
<p>Using an index on the <code class="docutils literal notranslate"><span class="pre">&#64;count</span></code> and <code class="docutils literal notranslate"><span class="pre">&#64;sum</span></code> variables, we get the benefit of the <code class="docutils literal notranslate"><span class="pre">-g</span></code> (group-by) option which <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">stats1</span></code> and various other Miller commands have:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;
</span><span class="hll"> @x_count[$a] += 1;
</span><span class="hll"> @x_sum[$a] += $x;
</span><span class="hll"> end {
</span><span class="hll"> emit @x_count, &quot;a&quot;;
</span><span class="hll"> emit @x_sum, &quot;a&quot;;
</span><span class="hll"> }
</span><span class="hll"> &#39; ../data/small
</span> a=pan,x_count=2
a=eks,x_count=3
a=wye,x_count=2
a=zee,x_count=2
a=hat,x_count=1
a=pan,x_sum=0.8494161498792961
a=eks,x_sum=1.75186341922895
a=wye,x_sum=0.7778922255683036
a=zee,x_sum=1.1256801691982772
a=hat,x_sum=0.03144187646093577
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr stats1 -a count,sum -f x -g a ../data/small
</span> a=pan,x_count=2,x_sum=0.8494161498792961
a=eks,x_count=3,x_sum=1.75186341922895
a=wye,x_count=2,x_sum=0.7778922255683036
a=zee,x_count=2,x_sum=1.1256801691982772
a=hat,x_count=1,x_sum=0.03144187646093577
</pre></div>
</div>
<p>Indices can be arbitrarily deep here there are two or more of them:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/medium put -q &#39;
</span><span class="hll"> @x_count[$a][$b] += 1;
</span><span class="hll"> @x_sum[$a][$b] += $x;
</span><span class="hll"> end {
</span><span class="hll"> emit (@x_count, @x_sum), &quot;a&quot;, &quot;b&quot;;
</span><span class="hll"> }
</span><span class="hll"> &#39;
</span> a=pan,b=pan,x_count=427,x_sum=219.1851288316854
a=pan,b=wye,x_count=395,x_sum=198.43293070748447
a=pan,b=eks,x_count=429,x_sum=216.07522773165525
a=pan,b=hat,x_count=417,x_sum=205.22277621488686
a=pan,b=zee,x_count=413,x_sum=205.09751802331917
a=eks,b=pan,x_count=371,x_sum=179.96303047250723
a=eks,b=wye,x_count=407,x_sum=196.9452860713734
a=eks,b=zee,x_count=357,x_sum=176.8803651584733
a=eks,b=eks,x_count=413,x_sum=215.91609712937984
a=eks,b=hat,x_count=417,x_sum=208.783170520597
a=wye,b=wye,x_count=377,x_sum=185.29584980261419
a=wye,b=pan,x_count=392,x_sum=195.84790012056564
a=wye,b=hat,x_count=426,x_sum=212.0331829346132
a=wye,b=zee,x_count=385,x_sum=194.77404756708714
a=wye,b=eks,x_count=386,x_sum=204.8129608356315
a=zee,b=pan,x_count=389,x_sum=202.21380378504267
a=zee,b=wye,x_count=455,x_sum=233.9913939194868
a=zee,b=eks,x_count=391,x_sum=190.9617780631925
a=zee,b=zee,x_count=403,x_sum=206.64063510417319
a=zee,b=hat,x_count=409,x_sum=191.30000620900935
a=hat,b=wye,x_count=423,x_sum=208.8830097609959
a=hat,b=zee,x_count=385,x_sum=196.3494502965293
a=hat,b=eks,x_count=389,x_sum=189.0067933716193
a=hat,b=hat,x_count=381,x_sum=182.8535323148762
a=hat,b=pan,x_count=363,x_sum=168.5538067327806
</pre></div>
</div>
<p>The idea is that <code class="docutils literal notranslate"><span class="pre">stats1</span></code>, and other Miller verbs, encapsulate frequently-used patterns with a minimum of keystroking (and run a little faster), whereas using out-of-stream variables you have more flexibility and control in what you do.</p>
<p>Begin/end blocks can be mixed with pattern/action blocks. For example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;
</span><span class="hll"> begin {
</span><span class="hll"> @num_total = 0;
</span><span class="hll"> @num_positive = 0;
</span><span class="hll"> };
</span><span class="hll"> @num_total += 1;
</span><span class="hll"> $x &gt; 0.0 {
</span><span class="hll"> @num_positive += 1;
</span><span class="hll"> $y = log10($x); $z = sqrt($y)
</span><span class="hll"> };
</span><span class="hll"> end {
</span><span class="hll"> emitf @num_total, @num_positive
</span><span class="hll"> }
</span><span class="hll"> &#39; data/put-gating-example-1.dkvp
</span> x=-1
x=0
x=1,y=0,z=0
x=2,y=0.3010299956639812,z=0.5486620049392715
x=3,y=0.4771212547196624,z=0.6907396432228734
num_total=5,num_positive=3
</pre></div>
</div>
</div>
<div class="section" id="local-variables">
<span id="reference-dsl-local-variables"></span><h3>Local variables<a class="headerlink" href="#local-variables" title="Permalink to this headline"></a></h3>
<p>Local variables are similar to out-of-stream variables, except that their extent is limited to the expressions in which they appear (and their basenames cant be computed using square brackets). There are three kinds of local variables: <strong>arguments</strong> to functions/subroutines, <strong>variables bound within for-loops</strong>, and <strong>locals</strong> defined within control blocks. They may be untyped using <code class="docutils literal notranslate"><span class="pre">var</span></code>, or typed using <code class="docutils literal notranslate"><span class="pre">num</span></code>, <code class="docutils literal notranslate"><span class="pre">int</span></code>, <code class="docutils literal notranslate"><span class="pre">float</span></code>, <code class="docutils literal notranslate"><span class="pre">str</span></code>, <code class="docutils literal notranslate"><span class="pre">bool</span></code>, and <code class="docutils literal notranslate"><span class="pre">map</span></code>.</p>
<p>For example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ # Here I&#39;m using a specified random-number seed so this example always
</span><span class="hll"> # produces the same output for this web document: in everyday practice we
</span><span class="hll"> # would leave off the --seed 12345 part.
</span><span class="hll"> mlr --seed 12345 seqgen --start 1 --stop 10 then put &#39;
</span><span class="hll"> func f(a, b) { # function arguments a and b
</span><span class="hll"> r = 0.0; # local r scoped to the function
</span><span class="hll"> for (int i = 0; i &lt; 6; i += 1) { # local i scoped to the for-loop
</span><span class="hll"> num u = urand(); # local u scoped to the for-loop
</span><span class="hll"> r += u; # updates r from the enclosing scope
</span><span class="hll"> }
</span><span class="hll"> r /= 6;
</span><span class="hll"> return a + (b - a) * r;
</span><span class="hll"> }
</span><span class="hll"> num o = f(10, 20); # local to the top-level scope
</span><span class="hll"> $o = o;
</span><span class="hll"> &#39;
</span> i=1,o=15.952526011537227
i=2,o=12.782237754999116
i=3,o=15.126606630220966
i=4,o=14.794357488895775
i=5,o=15.168665974047421
i=6,o=16.20662783079942
i=7,o=13.966128063060479
i=8,o=13.99248245928659
i=9,o=15.784270485515197
i=10,o=15.37686787628025
</pre></div>
</div>
<p>Things which are completely unsurprising, resembling many other languages:</p>
<ul class="simple">
<li><p>Parameter names are bound to their arguments but can be reassigned, e.g. if there is a parameter named <code class="docutils literal notranslate"><span class="pre">a</span></code> then you can reassign the value of <code class="docutils literal notranslate"><span class="pre">a</span></code> to be something else within the function if you like.</p></li>
<li><p>However, you cannot redeclare the <em>type</em> of an argument or a local: <code class="docutils literal notranslate"><span class="pre">var</span> <span class="pre">a=1;</span> <span class="pre">var</span> <span class="pre">a=2</span></code> is an error but <code class="docutils literal notranslate"><span class="pre">var</span> <span class="pre">a=1;</span>&#160; <span class="pre">a=2</span></code> is OK.</p></li>
<li><p>All argument-passing is positional rather than by name; arguments are passed by value, not by reference. (This is also true for map-valued variables: they are not, and cannot be, passed by reference)</p></li>
<li><p>You can define locals (using <code class="docutils literal notranslate"><span class="pre">var</span></code>, <code class="docutils literal notranslate"><span class="pre">num</span></code>, etc.) at any scope (if-statements, else-statements, while-loops, for-loops, or the top-level scope), and nested scopes will have access (more details on scope in the next section). If you define a local variable with the same name inside an inner scope, then a new variable is created with the narrower scope.</p></li>
<li><p>If you assign to a local variable for the first time in a scope without declaring it as <code class="docutils literal notranslate"><span class="pre">var</span></code>, <code class="docutils literal notranslate"><span class="pre">num</span></code>, etc. then: if it exists in an outer scope, that outer-scope variable will be updated; if not, it will be defined in the current scope as if <code class="docutils literal notranslate"><span class="pre">var</span></code> had been used. (See also <a class="reference internal" href="#reference-dsl-type-checking"><span class="std std-ref">Type-checking</span></a> for an example.) I recommend always declaring variables explicitly to make the intended scoping clear.</p></li>
<li><p>Functions and subroutines never have access to locals from their callee (unless passed by value as arguments).</p></li>
</ul>
<p>Things which are perhaps surprising compared to other languages:</p>
<ul class="simple">
<li><p>Type declarations using <code class="docutils literal notranslate"><span class="pre">var</span></code>, or typed using <code class="docutils literal notranslate"><span class="pre">num</span></code>, <code class="docutils literal notranslate"><span class="pre">int</span></code>, <code class="docutils literal notranslate"><span class="pre">float</span></code>, <code class="docutils literal notranslate"><span class="pre">str</span></code>, and <code class="docutils literal notranslate"><span class="pre">bool</span></code> are necessary to declare local variables. Function arguments and variables bound in for-loops over stream records and out-of-stream variables are <em>implicitly</em> declared using <code class="docutils literal notranslate"><span class="pre">var</span></code>. (Some examples are shown below.)</p></li>
<li><p>Type-checking is done at assignment time. For example, <code class="docutils literal notranslate"><span class="pre">float</span> <span class="pre">f</span> <span class="pre">=</span> <span class="pre">0</span></code> is an error (since <code class="docutils literal notranslate"><span class="pre">0</span></code> is an integer), as is <code class="docutils literal notranslate"><span class="pre">float</span> <span class="pre">f</span> <span class="pre">=</span> <span class="pre">0.0;</span> <span class="pre">f</span> <span class="pre">=</span> <span class="pre">1</span></code>. For this reason I prefer to use <code class="docutils literal notranslate"><span class="pre">num</span></code> over <code class="docutils literal notranslate"><span class="pre">float</span></code> in most contexts since <code class="docutils literal notranslate"><span class="pre">num</span></code> encompasses integer and floating-point values. More information about type-checking is at <a class="reference internal" href="#reference-dsl-type-checking"><span class="std std-ref">Type-checking</span></a>.</p></li>
<li><p>Bound variables in for-loops over stream records and out-of-stream variables are implicitly local to that block. E.g. in <code class="docutils literal notranslate"><span class="pre">for</span> <span class="pre">(k,</span> <span class="pre">v</span> <span class="pre">in</span> <span class="pre">$*)</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">}</span></code> <code class="docutils literal notranslate"><span class="pre">for</span> <span class="pre">((k1,</span> <span class="pre">k2),</span> <span class="pre">v</span> <span class="pre">in</span> <span class="pre">&#64;*)</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">}</span></code> if there are <code class="docutils literal notranslate"><span class="pre">k</span></code>, <code class="docutils literal notranslate"><span class="pre">v</span></code>, etc. in the enclosing scope then those will be masked by the loop-local bound variables in the loop, and moreover the values of the loop-local bound variables are not available after the end of the loop.</p></li>
<li><p>For C-style triple-for loops, if a for-loop variable is defined using <code class="docutils literal notranslate"><span class="pre">var</span></code>, <code class="docutils literal notranslate"><span class="pre">int</span></code>, etc. then it is scoped to that for-loop. E.g. <code class="docutils literal notranslate"><span class="pre">for</span> <span class="pre">(i</span> <span class="pre">=</span> <span class="pre">0;</span> <span class="pre">i</span> <span class="pre">&lt;</span> <span class="pre">10;</span> <span class="pre">i</span> <span class="pre">+=</span> <span class="pre">1)</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">}</span></code> and <code class="docutils literal notranslate"><span class="pre">for</span> <span class="pre">(int</span> <span class="pre">i</span> <span class="pre">=</span> <span class="pre">0;</span> <span class="pre">i</span> <span class="pre">&lt;</span> <span class="pre">10;</span> <span class="pre">i</span> <span class="pre">+=</span> <span class="pre">1)</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">}</span></code>. (This is unsurprising.). If there is no typedecl and an outer-scope variable of that name exists, then it is used. (This is also unsurprising.) But of there is no outer-scope variable of that name then the variable is scoped to the for-loop only.</p></li>
</ul>
<p>The following example demonstrates the scope rules:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ cat data/scope-example.mlr
</span> func f(a) { # argument is local to the function
var b = 100; # local to the function
c = 100; # local to the function; does not overwrite outer c
return a + 1;
}
var a = 10; # local at top level
var b = 20; # local at top level
c = 30; # local at top level; there is no more-outer-scope c
if (NR == 3) {
var a = 40; # scoped to the if-statement; doesn&#39;t overwrite outer a
b = 50; # not scoped to the if-statement; overwrites outer b
c = 60; # not scoped to the if-statement; overwrites outer c
d = 70; # there is no outer d so a local d is created here
$inner_a = a;
$inner_b = b;
$inner_c = c;
$inner_d = d;
}
$outer_a = a;
$outer_b = b;
$outer_c = c;
$outer_d = d; # there is no outer d defined so no assignment happens
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ cat data/scope-example.dat
</span> n=1,x=123
n=2,x=456
n=3,x=789
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --oxtab --from data/scope-example.dat put -f data/scope-example.mlr
</span> n 1
x 123
outer_a 10
outer_b 20
outer_c 30
n 2
x 456
outer_a 10
outer_b 20
outer_c 30
n 3
x 789
inner_a 40
inner_b 50
inner_c 60
inner_d 70
outer_a 10
outer_b 50
outer_c 60
</pre></div>
</div>
<p>And this example demonstrates the type-declaration rules:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ cat data/type-decl-example.mlr
</span> subr s(a, str b, int c) { # a is implicitly var (untyped).
# b is explicitly str.
# c is explicitly int.
# The type-checking is done at the callsite
# when arguments are bound to parameters.
#
var b = 100; # error # Re-declaration in the same scope is disallowed.
int n = 10; # Declaration of variable local to the subroutine.
n = 20; # Assignment is OK.
int n = 30; # error # Re-declaration in the same scope is disallowed.
str n = &quot;abc&quot;; # error # Re-declaration in the same scope is disallowed.
#
float f1 = 1; # error # 1 is an int, not a float.
float f2 = 2.0; # 2.0 is a float.
num f3 = 3; # 3 is a num.
num f4 = 4.0; # 4.0 is a num.
} #
#
call s(1, 2, 3); # Type-assertion &#39;3 is int&#39; is done here at the callsite.
#
k = &quot;def&quot;; # Top-level variable k.
#
for (str k, v in $*) { # k and v are bound here, masking outer k.
print k . &quot;:&quot; . v; # k is explicitly str; v is implicitly var.
} #
#
print &quot;k is&quot;.k; # k at this scope level is still &quot;def&quot;.
print &quot;v is&quot;.v; # v is undefined in this scope.
#
i = -1; #
for (i = 1, int j = 2; i &lt;= 10; i += 1, j *= 2) { # C-style triple-for variables use enclosing scope, unless
# declared local: i is outer, j is local to the loop.
print &quot;inner i =&quot; . i; #
print &quot;inner j =&quot; . j; #
} #
print &quot;outer i =&quot; . i; # i has been modified by the loop.
print &quot;outer j =&quot; . j; # j is undefined in this scope.
</pre></div>
</div>
</div>
<div class="section" id="map-literals">
<h3>Map literals<a class="headerlink" href="#map-literals" title="Permalink to this headline"></a></h3>
<p>Millers <code class="docutils literal notranslate"><span class="pre">put</span></code>/<code class="docutils literal notranslate"><span class="pre">filter</span></code> DSL has four kinds of hashmaps. <strong>Stream records</strong> are (single-level) maps from name to value. <strong>Out-of-stream variables</strong> and <strong>local variables</strong> can also be maps, although they can be multi-level hashmaps (e.g. <code class="docutils literal notranslate"><span class="pre">&#64;sum[$x][$y]</span></code>). The fourth kind is <strong>map literals</strong>. These cannot be on the left-hand side of assignment expressions. Syntactically they look like JSON, although Miller allows string and integer keys in its map literals while JSON allows only string keys (e.g. <code class="docutils literal notranslate"><span class="pre">&quot;3&quot;</span></code> rather than <code class="docutils literal notranslate"><span class="pre">3</span></code>).</p>
<p>For example, the following swaps the input streams <code class="docutils literal notranslate"><span class="pre">a</span></code> and <code class="docutils literal notranslate"><span class="pre">i</span></code> fields, modifies <code class="docutils literal notranslate"><span class="pre">y</span></code>, and drops the rest:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --opprint put &#39;
</span><span class="hll"> $* = {
</span><span class="hll"> &quot;a&quot;: $i,
</span><span class="hll"> &quot;i&quot;: $a,
</span><span class="hll"> &quot;y&quot;: $y * 10,
</span><span class="hll"> }
</span><span class="hll"> &#39; data/small
</span> a i y
1 pan 7.268028627434533
2 eks 5.221511083334796
3 wye 3.3831852551664774
4 eks 1.3418874328430463
5 wye 8.63624469903273
</pre></div>
</div>
<p>Likewise, you can assign map literals to out-of-stream variables or local variables; pass them as arguments to user-defined functions, return them from functions, and so on:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/small put &#39;
</span><span class="hll"> func f(map m): map {
</span><span class="hll"> m[&quot;x&quot;] *= 200;
</span><span class="hll"> return m;
</span><span class="hll"> }
</span><span class="hll"> $* = f({&quot;a&quot;: $a, &quot;x&quot;: $x});
</span><span class="hll"> &#39;
</span> a=pan,x=69.35802886761648
a=eks,x=151.73599295799272
a=wye,x=40.92066115326061
a=eks,x=76.2798787742282
a=wye,x=114.65778396040011
</pre></div>
</div>
<p>Like out-of-stream and local variables, map literals can be multi-level:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/small put -q &#39;
</span><span class="hll"> begin {
</span><span class="hll"> @o = {
</span><span class="hll"> &quot;nrec&quot;: 0,
</span><span class="hll"> &quot;nkey&quot;: {&quot;numeric&quot;:0, &quot;non-numeric&quot;:0},
</span><span class="hll"> };
</span><span class="hll"> }
</span><span class="hll"> @o[&quot;nrec&quot;] += 1;
</span><span class="hll"> for (k, v in $*) {
</span><span class="hll"> if (is_numeric(v)) {
</span><span class="hll"> @o[&quot;nkey&quot;][&quot;numeric&quot;] += 1;
</span><span class="hll"> } else {
</span><span class="hll"> @o[&quot;nkey&quot;][&quot;non-numeric&quot;] += 1;
</span><span class="hll"> }
</span><span class="hll"> }
</span><span class="hll"> end {
</span><span class="hll"> dump @o;
</span><span class="hll"> }
</span><span class="hll"> &#39;
</span> {
&quot;nrec&quot;: 5,
&quot;nkey&quot;: {
&quot;numeric&quot;: 15,
&quot;non-numeric&quot;: 10
}
}
</pre></div>
</div>
<p>By default, map-valued expressions are dumped using JSON formatting. If you use <code class="docutils literal notranslate"><span class="pre">dump</span></code> to print a hashmap with integer keys and you dont want them double-quoted (JSON-style) then you can use <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span> <span class="pre">--jknquoteint</span></code>. See also <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span> <span class="pre">--help</span></code>.</p>
</div>
<div class="section" id="type-checking">
<span id="reference-dsl-type-checking"></span><h3>Type-checking<a class="headerlink" href="#type-checking" title="Permalink to this headline"></a></h3>
<p>Millers <code class="docutils literal notranslate"><span class="pre">put</span></code>/<code class="docutils literal notranslate"><span class="pre">filter</span></code> DSLs support two optional kinds of type-checking. One is inline <strong>type-tests</strong> and <strong>type-assertions</strong> within expressions. The other is <strong>type declarations</strong> for assignments to local variables, binding of arguments to user-defined functions, and return values from user-defined functions, These are discussed in the following subsections.</p>
<p>Use of type-checking is entirely up to you: omit it if you want flexibility with heterogeneous data; use it if you want to help catch misspellings in your DSL code or unexpected irregularities in your input data.</p>
<div class="section" id="type-test-and-type-assertion-expressions">
<span id="reference-dsl-type-tests-and-assertions"></span><h4>Type-test and type-assertion expressions<a class="headerlink" href="#type-test-and-type-assertion-expressions" title="Permalink to this headline"></a></h4>
<p>The following <code class="docutils literal notranslate"><span class="pre">is...</span></code> functions take a value and return a boolean indicating whether the argument is of the indicated type. The <code class="docutils literal notranslate"><span class="pre">assert_...</span></code> functions return their argument if it is of the specified type, and cause a fatal error otherwise:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr -F | grep ^is
</span> is_absent
is_array
is_bool
is_boolean
is_empty
is_empty_map
is_error
is_float
is_int
is_map
is_nonempty_map
is_not_empty
is_not_map
is_not_array
is_not_null
is_null
is_numeric
is_present
is_string
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr -F | grep ^assert
</span> asserting_absent
asserting_array
asserting_bool
asserting_boolean
asserting_error
asserting_empty
asserting_empty_map
asserting_float
asserting_int
asserting_map
asserting_nonempty_map
asserting_not_empty
asserting_not_map
asserting_not_array
asserting_not_null
asserting_null
asserting_numeric
asserting_present
asserting_string
</pre></div>
</div>
<p>Please see <span class="xref std std-ref">cookbook-data-cleaning-examples</span> for examples of how to use these.</p>
</div>
<div class="section" id="type-declarations-for-local-variables-function-parameter-and-function-return-values">
<h4>Type-declarations for local variables, function parameter, and function return values<a class="headerlink" href="#type-declarations-for-local-variables-function-parameter-and-function-return-values" title="Permalink to this headline"></a></h4>
<p>Local variables can be defined either untyped as in <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">=</span> <span class="pre">1</span></code>, or typed as in <code class="docutils literal notranslate"><span class="pre">int</span> <span class="pre">x</span> <span class="pre">=</span> <span class="pre">1</span></code>. Types include <strong>var</strong> (explicitly untyped), <strong>int</strong>, <strong>float</strong>, <strong>num</strong> (int or float), <strong>str</strong>, <strong>bool</strong>, and <strong>map</strong>. These optional type declarations are enforced at the time values are assigned to variables: whether at the initial value assignment as in <code class="docutils literal notranslate"><span class="pre">int</span> <span class="pre">x</span> <span class="pre">=</span> <span class="pre">1</span></code> or in any subsequent assignments to the same variable farther down in the scope.</p>
<p>The reason for <code class="docutils literal notranslate"><span class="pre">num</span></code> is that <code class="docutils literal notranslate"><span class="pre">int</span></code> and <code class="docutils literal notranslate"><span class="pre">float</span></code> typedecls are very precise:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>float a = 0; # Runtime error since 0 is int not float
int b = 1.0; # Runtime error since 1.0 is float not int
num c = 0; # OK
num d = 1.0; # OK
</pre></div>
</div>
<p>A suggestion is to use <code class="docutils literal notranslate"><span class="pre">num</span></code> for general use when you want numeric content, and use <code class="docutils literal notranslate"><span class="pre">int</span></code> when you genuinely want integer-only values, e.g. in loop indices or map keys (since Miller map keys can only be strings or ints).</p>
<p>The <code class="docutils literal notranslate"><span class="pre">var</span></code> type declaration indicates no type restrictions, e.g. <code class="docutils literal notranslate"><span class="pre">var</span> <span class="pre">x</span> <span class="pre">=</span> <span class="pre">1</span></code> has the same type restrictions on <code class="docutils literal notranslate"><span class="pre">x</span></code> as <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">=</span> <span class="pre">1</span></code>. The difference is in intentional shadowing: if you have <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">=</span> <span class="pre">1</span></code> in outer scope and <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">=</span> <span class="pre">2</span></code> in inner scope (e.g. within a for-loop or an if-statement) then outer-scope <code class="docutils literal notranslate"><span class="pre">x</span></code> has value 2 after the second assignment. But if you have <code class="docutils literal notranslate"><span class="pre">var</span> <span class="pre">x</span> <span class="pre">=</span> <span class="pre">2</span></code> in the inner scope, then you are declaring a variable scoped to the inner block.) For example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>x = 1;
if (NR == 4) {
x = 2; # Refers to outer-scope x: value changes from 1 to 2.
}
print x; # Value of x is now two
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>x = 1;
if (NR == 4) {
var x = 2; # Defines a new inner-scope x with value 2
}
print x; # Value of this x is still 1
</pre></div>
</div>
<p>Likewise function arguments can optionally be typed, with type enforced when the function is called:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>func f(map m, int i) {
...
}
$a = f({1:2, 3:4}, 5); # OK
$b = f({1:2, 3:4}, &quot;abc&quot;); # Runtime error
$c = f({1:2, 3:4}, $x); # Runtime error for records with non-integer field named x
if (NR == 4) {
var x = 2; # Defines a new inner-scope x with value 2
}
print x; # Value of this x is still 1
</pre></div>
</div>
<p>Thirdly, function return values can be type-checked at the point of <code class="docutils literal notranslate"><span class="pre">return</span></code> using <code class="docutils literal notranslate"><span class="pre">:</span></code> and a typedecl after the parameter list:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>func f(map m, int i): bool {
...
...
if (...) {
return &quot;false&quot;; # Runtime error if this branch is taken
}
...
...
if (...) {
return retval; # Runtime error if this function doesn&#39;t have an in-scope
# boolean-valued variable named retval
}
...
...
# In Miller if your functions don&#39;t explicitly return a value, they return absent-null.
# So it would also be a runtime error on reaching the end of this function without
# an explicit return statement.
}
</pre></div>
</div>
</div>
</div>
<div class="section" id="null-data-empty-and-absent">
<h3>Null data: empty and absent<a class="headerlink" href="#null-data-empty-and-absent" title="Permalink to this headline"></a></h3>
<p>Please see <a class="reference internal" href="reference.html#reference-null-data"><span class="std std-ref">Null data: empty and absent</span></a>.</p>
</div>
<div class="section" id="aggregate-variable-assignments">
<h3>Aggregate variable assignments<a class="headerlink" href="#aggregate-variable-assignments" title="Permalink to this headline"></a></h3>
<p>There are three remaining kinds of variable assignment using out-of-stream variables, the last two of which use the <code class="docutils literal notranslate"><span class="pre">$*</span></code> syntax:</p>
<ul class="simple">
<li><p>Recursive copy of out-of-stream variables</p></li>
<li><p>Out-of-stream variable assigned to full stream record</p></li>
<li><p>Full stream record assigned to an out-of-stream variable</p></li>
</ul>
<p>Example recursive copy of out-of-stream variables:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --opprint put -q &#39;@v[&quot;sum&quot;] += $x; @v[&quot;count&quot;] += 1; end{dump; @w = @v; dump}&#39; data/small
</span> {
&quot;v&quot;: {
&quot;sum&quot;: 2.264761728567491,
&quot;count&quot;: 5
}
}
{
&quot;v&quot;: {
&quot;sum&quot;: 2.264761728567491,
&quot;count&quot;: 5
},
&quot;w&quot;: {
&quot;sum&quot;: 2.264761728567491,
&quot;count&quot;: 5
}
}
</pre></div>
</div>
<p>Example of out-of-stream variable assigned to full stream record, where the 2nd record is stashed, and the 4th record is overwritten with that:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;NR == 2 {@keep = $*}; NR == 4 {$* = @keep}&#39; data/small
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729
</pre></div>
</div>
<p>Example of full stream record assigned to an out-of-stream variable, finding the record for which the <code class="docutils literal notranslate"><span class="pre">x</span></code> field has the largest value in the input stream:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ cat data/small
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --opprint put -q &#39;is_null(@xmax) || $x &gt; @xmax {@xmax=$x; @recmax=$*}; end {emit @recmax}&#39; data/small
</span> a b i x y
eks pan 2 0.7586799647899636 0.5221511083334797
</pre></div>
</div>
</div>
<div class="section" id="keywords-for-filter-and-put">
<h3>Keywords for filter and put<a class="headerlink" href="#keywords-for-filter-and-put" title="Permalink to this headline"></a></h3>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --help-all-keywords
</span> TOD: port mlr_dsl_list_all_keywords
</pre></div>
</div>
</div>
</div>
<div class="section" id="operator-precedence">
<h2>Operator precedence<a class="headerlink" href="#operator-precedence" title="Permalink to this headline"></a></h2>
<p>Operators are listed in order of decreasing precedence, highest first.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Operators Associativity
--------- -------------
() left to right
** right to left
! ~ unary+ unary- &amp; right to left
binary* / // % left to right
binary+ binary- . left to right
&lt;&lt; &gt;&gt; left to right
&amp; left to right
^ left to right
| left to right
&lt; &lt;= &gt; &gt;= left to right
== != =~ !=~ left to right
&amp;&amp; left to right
^^ left to right
|| left to right
? : right to left
= N/A for Miller (there is no $a=$b=$c)
</pre></div>
</div>
</div>
<div class="section" id="operator-and-function-semantics">
<h2>Operator and function semantics<a class="headerlink" href="#operator-and-function-semantics" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li><p>Functions are often pass-throughs straight to the system-standard Go libraries.</p></li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">min</span></code> and <code class="docutils literal notranslate"><span class="pre">max</span></code> functions are different from other multi-argument functions which return null if any of their inputs are null: for <code class="docutils literal notranslate"><span class="pre">min</span></code> and <code class="docutils literal notranslate"><span class="pre">max</span></code>, by contrast, if one argument is absent-null, the other is returned. Empty-null loses min or max against numeric or boolean; empty-null is less than any other string.</p></li>
<li><p>Symmetrically with respect to the bitwise OR, XOR, and AND operators <code class="docutils literal notranslate"><span class="pre">|</span></code>, <code class="docutils literal notranslate"><span class="pre">^</span></code>, <code class="docutils literal notranslate"><span class="pre">&amp;</span></code>, Miller has logical operators <code class="docutils literal notranslate"><span class="pre">||</span></code>, <code class="docutils literal notranslate"><span class="pre">^^</span></code>, <code class="docutils literal notranslate"><span class="pre">&amp;&amp;</span></code>: the logical XOR not existing in Go.</p></li>
<li><p>The exponentiation operator <code class="docutils literal notranslate"><span class="pre">**</span></code> is familiar from many languages.</p></li>
<li><p>The regex-match and regex-not-match operators <code class="docutils literal notranslate"><span class="pre">=~</span></code> and <code class="docutils literal notranslate"><span class="pre">!=~</span></code> are similar to those in Ruby and Perl.</p></li>
</ul>
</div>
<div class="section" id="control-structures">
<h2>Control structures<a class="headerlink" href="#control-structures" title="Permalink to this headline"></a></h2>
<div class="section" id="pattern-action-blocks">
<h3>Pattern-action blocks<a class="headerlink" href="#pattern-action-blocks" title="Permalink to this headline"></a></h3>
<p>These are reminiscent of <code class="docutils literal notranslate"><span class="pre">awk</span></code> syntax. They can be used to allow assignments to be done only when appropriate e.g. for math-function domain restrictions, regex-matching, and so on:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr cat data/put-gating-example-1.dkvp
</span> x=-1
x=0
x=1
x=2
x=3
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;$x &gt; 0.0 { $y = log10($x); $z = sqrt($y) }&#39; data/put-gating-example-1.dkvp
</span> x=-1
x=0
x=1,y=0,z=0
x=2,y=0.3010299956639812,z=0.5486620049392715
x=3,y=0.4771212547196624,z=0.6907396432228734
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr cat data/put-gating-example-2.dkvp
</span> a=abc_123
a=some other name
a=xyz_789
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;$a =~ &quot;([a-z]+)_([0-9]+)&quot; { $b = &quot;left_\1&quot;; $c = &quot;right_\2&quot; }&#39; data/put-gating-example-2.dkvp
</span> a=abc_123,b=left_\1,c=right_\2
a=some other name
a=xyz_789,b=left_\1,c=right_\2
</pre></div>
</div>
<p>This produces heteregenous output which Miller, of course, has no problems with (see <a class="reference internal" href="record-heterogeneity.html"><span class="doc">Record-heterogeneity</span></a>). But if you want homogeneous output, the curly braces can be replaced with a semicolon between the expression and the body statements. This causes <code class="docutils literal notranslate"><span class="pre">put</span></code> to evaluate the boolean expression (along with any side effects, namely, regex-captures <code class="docutils literal notranslate"><span class="pre">\1</span></code>, <code class="docutils literal notranslate"><span class="pre">\2</span></code>, etc.) but doesnt use it as a criterion for whether subsequent assignments should be executed. Instead, subsequent assignments are done unconditionally:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;$x &gt; 0.0; $y = log10($x); $z = sqrt($y)&#39; data/put-gating-example-1.dkvp
</span> x=1,y=0,z=0
x=2,y=0.3010299956639812,z=0.5486620049392715
x=3,y=0.4771212547196624,z=0.6907396432228734
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;$a =~ &quot;([a-z]+)_([0-9]+)&quot;; $b = &quot;left_\1&quot;; $c = &quot;right_\2&quot;&#39; data/put-gating-example-2.dkvp
</span> a=abc_123,b=left_\1,c=right_\2
a=xyz_789,b=left_\1,c=right_\2
</pre></div>
</div>
</div>
<div class="section" id="if-statements">
<h3>If-statements<a class="headerlink" href="#if-statements" title="Permalink to this headline"></a></h3>
<p>These are again reminiscent of <code class="docutils literal notranslate"><span class="pre">awk</span></code>. Pattern-action blocks are a special case of <code class="docutils literal notranslate"><span class="pre">if</span></code> with no <code class="docutils literal notranslate"><span class="pre">elif</span></code> or <code class="docutils literal notranslate"><span class="pre">else</span></code> blocks, no <code class="docutils literal notranslate"><span class="pre">if</span></code> keyword, and parentheses optional around the boolean expression:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>mlr put &#39;NR == 4 {$foo = &quot;bar&quot;}&#39;
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>mlr put &#39;if (NR == 4) {$foo = &quot;bar&quot;}&#39;
</pre></div>
</div>
<p>Compound statements use <code class="docutils literal notranslate"><span class="pre">elif</span></code> (rather than <code class="docutils literal notranslate"><span class="pre">elsif</span></code> or <code class="docutils literal notranslate"><span class="pre">else</span> <span class="pre">if</span></code>):</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>mlr put &#39;
if (NR == 2) {
...
} elif (NR ==4) {
...
} elif (NR ==6) {
...
} else {
...
}
&#39;
</pre></div>
</div>
</div>
<div class="section" id="while-and-do-while-loops">
<h3>While and do-while loops<a class="headerlink" href="#while-and-do-while-loops" title="Permalink to this headline"></a></h3>
<p>Millers <code class="docutils literal notranslate"><span class="pre">while</span></code> and <code class="docutils literal notranslate"><span class="pre">do-while</span></code> are unsurprising in comparison to various languages, as are <code class="docutils literal notranslate"><span class="pre">break</span></code> and <code class="docutils literal notranslate"><span class="pre">continue</span></code>:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ echo x=1,y=2 | mlr put &#39;
</span><span class="hll"> while (NF &lt; 10) {
</span><span class="hll"> $[NF+1] = &quot;&quot;
</span><span class="hll"> }
</span><span class="hll"> $foo = &quot;bar&quot;
</span><span class="hll"> &#39;
</span> x=1,y=2,3=,4=,5=,6=,7=,8=,9=,10=,foo=bar
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ echo x=1,y=2 | mlr put &#39;
</span><span class="hll"> do {
</span><span class="hll"> $[NF+1] = &quot;&quot;;
</span><span class="hll"> if (NF == 5) {
</span><span class="hll"> break
</span><span class="hll"> }
</span><span class="hll"> } while (NF &lt; 10);
</span><span class="hll"> $foo = &quot;bar&quot;
</span><span class="hll"> &#39;
</span> x=1,y=2,3=,4=,5=,foo=bar
</pre></div>
</div>
<p>A <code class="docutils literal notranslate"><span class="pre">break</span></code> or <code class="docutils literal notranslate"><span class="pre">continue</span></code> within nested conditional blocks or if-statements will, of course, propagate to the innermost loop enclosing them, if any. A <code class="docutils literal notranslate"><span class="pre">break</span></code> or <code class="docutils literal notranslate"><span class="pre">continue</span></code> outside a loop is a syntax error that will be flagged as soon as the expression is parsed, before any input records are ingested.
The existence of <code class="docutils literal notranslate"><span class="pre">while</span></code>, <code class="docutils literal notranslate"><span class="pre">do-while</span></code>, and <code class="docutils literal notranslate"><span class="pre">for</span></code> loops in Millers DSL means that you can create infinite-loop scenarios inadvertently. In particular, please recall that DSL statements are executed once if in <code class="docutils literal notranslate"><span class="pre">begin</span></code> or <code class="docutils literal notranslate"><span class="pre">end</span></code> blocks, and once <em>per record</em> otherwise. For example, <strong>while (NR &lt; 10) will never terminate as NR is only incremented between records</strong>.</p>
</div>
<div class="section" id="for-loops">
<h3>For-loops<a class="headerlink" href="#for-loops" title="Permalink to this headline"></a></h3>
<p>While Millers <code class="docutils literal notranslate"><span class="pre">while</span></code> and <code class="docutils literal notranslate"><span class="pre">do-while</span></code> statements are much as in many other languages, <code class="docutils literal notranslate"><span class="pre">for</span></code> loops are more idiosyncratic to Miller. They are loops over key-value pairs, whether in stream records, out-of-stream variables, local variables, or map-literals: more reminiscent of <code class="docutils literal notranslate"><span class="pre">foreach</span></code>, as in (for example) PHP. There are <strong>for-loops over map keys</strong> and <strong>for-loops over key-value tuples</strong>. Additionally, Miller has a <strong>C-style triple-for loop</strong> with initialize, test, and update statements.</p>
<p>As with <code class="docutils literal notranslate"><span class="pre">while</span></code> and <code class="docutils literal notranslate"><span class="pre">do-while</span></code>, a <code class="docutils literal notranslate"><span class="pre">break</span></code> or <code class="docutils literal notranslate"><span class="pre">continue</span></code> within nested control structures will propagate to the innermost loop enclosing them, if any, and a <code class="docutils literal notranslate"><span class="pre">break</span></code> or <code class="docutils literal notranslate"><span class="pre">continue</span></code> outside a loop is a syntax error that will be flagged as soon as the expression is parsed, before any input records are ingested.</p>
<div class="section" id="key-only-for-loops">
<h4>Key-only for-loops<a class="headerlink" href="#key-only-for-loops" title="Permalink to this headline"></a></h4>
<p>The <code class="docutils literal notranslate"><span class="pre">key</span></code> variable is always bound to the <em>key</em> of key-value pairs:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/small put &#39;
</span><span class="hll"> print &quot;NR = &quot;.NR;
</span><span class="hll"> for (key in $*) {
</span><span class="hll"> value = $[key];
</span><span class="hll"> print &quot; key:&quot; . key . &quot; value:&quot;.value;
</span><span class="hll"> }
</span><span class="hll">
</span><span class="hll"> &#39;
</span> NR = 1
key:a value:pan
key:b value:pan
key:i value:1
key:x value:0.3467901443380824
key:y value:0.7268028627434533
a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533
NR = 2
key:a value:eks
key:b value:pan
key:i value:2
key:x value:0.7586799647899636
key:y value:0.5221511083334797
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
NR = 3
key:a value:wye
key:b value:wye
key:i value:3
key:x value:0.20460330576630303
key:y value:0.33831852551664776
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776
NR = 4
key:a value:eks
key:b value:wye
key:i value:4
key:x value:0.38139939387114097
key:y value:0.13418874328430463
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463
NR = 5
key:a value:wye
key:b value:pan
key:i value:5
key:x value:0.5732889198020006
key:y value:0.8636244699032729
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr -n put &#39;
</span><span class="hll"> end {
</span><span class="hll"> o = {1:2, 3:{4:5}};
</span><span class="hll"> for (key in o) {
</span><span class="hll"> print &quot; key:&quot; . key . &quot; valuetype:&quot; . typeof(o[key]);
</span><span class="hll"> }
</span><span class="hll"> }
</span><span class="hll"> &#39;
</span> key:1 valuetype:int
key:3 valuetype:map
</pre></div>
</div>
<p>Note that the value corresponding to a given key may be gotten as through a <strong>computed field name</strong> using square brackets as in <code class="docutils literal notranslate"><span class="pre">$[key]</span></code> for stream records, or by indexing the looped-over variable using square brackets.</p>
</div>
<div class="section" id="key-value-for-loops">
<h4>Key-value for-loops<a class="headerlink" href="#key-value-for-loops" title="Permalink to this headline"></a></h4>
<p>Single-level keys may be gotten at using either <code class="docutils literal notranslate"><span class="pre">for(k,v)</span></code> or <code class="docutils literal notranslate"><span class="pre">for((k),v)</span></code>; multi-level keys may be gotten at using <code class="docutils literal notranslate"><span class="pre">for((k1,k2,k3),v)</span></code> and so on. The <code class="docutils literal notranslate"><span class="pre">v</span></code> variable will be bound to to a scalar value (a string or a number) if the map stops at that level, or to a map-valued variable if the map goes deeper. If the map isnt deep enough then the loop body wont be executed.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ cat data/for-srec-example.tbl
</span> label1 label2 f1 f2 f3
blue green 100 240 350
red green 120 11 195
yellow blue 140 0 240
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --pprint --from data/for-srec-example.tbl put &#39;
</span><span class="hll"> $sum1 = $f1 + $f2 + $f3;
</span><span class="hll"> $sum2 = 0;
</span><span class="hll"> $sum3 = 0;
</span><span class="hll"> for (key, value in $*) {
</span><span class="hll"> if (key =~ &quot;^f[0-9]+&quot;) {
</span><span class="hll"> $sum2 += value;
</span><span class="hll"> $sum3 += $[key];
</span><span class="hll"> }
</span><span class="hll"> }
</span><span class="hll"> &#39;
</span> label1 label2 f1 f2 f3 sum1 sum2 sum3
blue green 100 240 350 690 690 690
red green 120 11 195 326 326 326
yellow blue 140 0 240 380 380 380
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/small --opprint put &#39;for (k,v in $*) { $[k.&quot;_type&quot;] = typeof(v) }&#39;
</span> a b i x y a_type b_type i_type x_type y_type
pan pan 1 0.3467901443380824 0.7268028627434533 string string int float float
eks pan 2 0.7586799647899636 0.5221511083334797 string string int float float
wye wye 3 0.20460330576630303 0.33831852551664776 string string int float float
eks wye 4 0.38139939387114097 0.13418874328430463 string string int float float
wye pan 5 0.5732889198020006 0.8636244699032729 string string int float float
</pre></div>
</div>
<p>Note that the value of the current field in the for-loop can be gotten either using the bound variable <code class="docutils literal notranslate"><span class="pre">value</span></code>, or through a <strong>computed field name</strong> using square brackets as in <code class="docutils literal notranslate"><span class="pre">$[key]</span></code>.</p>
<p>Important note: to avoid inconsistent looping behavior in case youre setting new fields (and/or unsetting existing ones) while looping over the record, <strong>Miller makes a copy of the record before the loop: loop variables are bound from the copy and all other reads/writes involve the record itself</strong>:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/small --opprint put &#39;
</span><span class="hll"> $sum1 = 0;
</span><span class="hll"> $sum2 = 0;
</span><span class="hll"> for (k,v in $*) {
</span><span class="hll"> if (is_numeric(v)) {
</span><span class="hll"> $sum1 +=v;
</span><span class="hll"> $sum2 += $[k];
</span><span class="hll"> }
</span><span class="hll"> }
</span><span class="hll"> &#39;
</span> a b i x y sum1 sum2
pan pan 1 0.3467901443380824 0.7268028627434533 2.0735930070815356 8.294372028326142
eks pan 2 0.7586799647899636 0.5221511083334797 3.280831073123443 13.123324292493772
wye wye 3 0.20460330576630303 0.33831852551664776 3.5429218312829507 14.171687325131803
eks wye 4 0.38139939387114097 0.13418874328430463 4.515588137155445 18.06235254862178
wye pan 5 0.5732889198020006 0.8636244699032729 6.436913389705273 25.747653558821092
</pre></div>
</div>
<p>It can be confusing to modify the stream record while iterating over a copy of it, so instead you might find it simpler to use a local variable in the loop and only update the stream record after the loop:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/small --opprint put &#39;
</span><span class="hll"> sum = 0;
</span><span class="hll"> for (k,v in $*) {
</span><span class="hll"> if (is_numeric(v)) {
</span><span class="hll"> sum += $[k];
</span><span class="hll"> }
</span><span class="hll"> }
</span><span class="hll"> $sum = sum
</span><span class="hll"> &#39;
</span> a b i x y sum
pan pan 1 0.3467901443380824 0.7268028627434533 2.0735930070815356
eks pan 2 0.7586799647899636 0.5221511083334797 3.280831073123443
wye wye 3 0.20460330576630303 0.33831852551664776 3.5429218312829507
eks wye 4 0.38139939387114097 0.13418874328430463 4.515588137155445
wye pan 5 0.5732889198020006 0.8636244699032729 6.436913389705273
</pre></div>
</div>
<p>You can also start iterating on sub-hashmaps of an out-of-stream or local variable; you can loop over nested keys; you can loop over all out-of-stream variables. The bound variables are bound to a copy of the sub-hashmap as it was before the loop started. The sub-hashmap is specified by square-bracketed indices after <code class="docutils literal notranslate"><span class="pre">in</span></code>, and additional deeper indices are bound to loop key-variables. The terminal values are bound to the loop value-variable whenever the keys are not too shallow. The value-variable may refer to a terminal (string, number) or it may be map-valued if the map goes deeper. Example indexing is as follows:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span># Parentheses are optional for single key:
for (k1, v in @a[&quot;b&quot;][&quot;c&quot;]) { ... }
for ((k1), v in @a[&quot;b&quot;][&quot;c&quot;]) { ... }
# Parentheses are required for multiple keys:
for ((k1, k2), v in @a[&quot;b&quot;][&quot;c&quot;]) { ... } # Loop over subhashmap of a variable
for ((k1, k2, k3), v in @a[&quot;b&quot;][&quot;c&quot;]) { ... } # Ditto
for ((k1, k2, k3), v in @a { ... } # Loop over variable starting from basename
for ((k1, k2, k3), v in @* { ... } # Loop over all variables (k1 is bound to basename)
</pre></div>
</div>
<p>Thats confusing in the abstract, so a concrete example is in order. Suppose the out-of-stream variable <code class="docutils literal notranslate"><span class="pre">&#64;myvar</span></code> is populated as follows:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr -n put --jknquoteint -q &#39;
</span><span class="hll"> begin {
</span><span class="hll"> @myvar = {
</span><span class="hll"> 1: 2,
</span><span class="hll"> 3: { 4 : 5 },
</span><span class="hll"> 6: { 7: { 8: 9 } }
</span><span class="hll"> }
</span><span class="hll"> }
</span><span class="hll"> end { dump }
</span><span class="hll"> &#39;
</span> {
&quot;myvar&quot;: {
&quot;1&quot;: 2,
&quot;3&quot;: {
&quot;4&quot;: 5
},
&quot;6&quot;: {
&quot;7&quot;: {
&quot;8&quot;: 9
}
}
}
}
</pre></div>
</div>
<p>Then we can get at various values as follows:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr -n put --jknquoteint -q &#39;
</span><span class="hll"> begin {
</span><span class="hll"> @myvar = {
</span><span class="hll"> 1: 2,
</span><span class="hll"> 3: { 4 : 5 },
</span><span class="hll"> 6: { 7: { 8: 9 } }
</span><span class="hll"> }
</span><span class="hll"> }
</span><span class="hll"> end {
</span><span class="hll"> for (k, v in @myvar) {
</span><span class="hll"> print
</span><span class="hll"> &quot;key=&quot; . k .
</span><span class="hll"> &quot;,valuetype=&quot; . typeof(v);
</span><span class="hll"> }
</span><span class="hll"> }
</span><span class="hll"> &#39;
</span> key=1,valuetype=int
key=3,valuetype=map
key=6,valuetype=map
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr -n put --jknquoteint -q &#39;
</span><span class="hll"> begin {
</span><span class="hll"> @myvar = {
</span><span class="hll"> 1: 2,
</span><span class="hll"> 3: { 4 : 5 },
</span><span class="hll"> 6: { 7: { 8: 9 } }
</span><span class="hll"> }
</span><span class="hll"> }
</span><span class="hll"> end {
</span><span class="hll"> for ((k1, k2), v in @myvar) {
</span><span class="hll"> print
</span><span class="hll"> &quot;key1=&quot; . k1 .
</span><span class="hll"> &quot;,key2=&quot; . k2 .
</span><span class="hll"> &quot;,valuetype=&quot; . typeof(v);
</span><span class="hll"> }
</span><span class="hll"> }
</span><span class="hll"> &#39;
</span> key1=3,key2=4,valuetype=int
key1=6,key2=7,valuetype=map
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr -n put --jknquoteint -q &#39;
</span><span class="hll"> begin {
</span><span class="hll"> @myvar = {
</span><span class="hll"> 1: 2,
</span><span class="hll"> 3: { 4 : 5 },
</span><span class="hll"> 6: { 7: { 8: 9 } }
</span><span class="hll"> }
</span><span class="hll"> }
</span><span class="hll"> end {
</span><span class="hll"> for ((k1, k2), v in @myvar[6]) {
</span><span class="hll"> print
</span><span class="hll"> &quot;key1=&quot; . k1 .
</span><span class="hll"> &quot;,key2=&quot; . k2 .
</span><span class="hll"> &quot;,valuetype=&quot; . typeof(v);
</span><span class="hll"> }
</span><span class="hll"> }
</span><span class="hll"> &#39;
</span> key1=7,key2=8,valuetype=int
</pre></div>
</div>
</div>
<div class="section" id="c-style-triple-for-loops">
<h4>C-style triple-for loops<a class="headerlink" href="#c-style-triple-for-loops" title="Permalink to this headline"></a></h4>
<p>These are supported as follows:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/small --opprint put &#39;
</span><span class="hll"> num suma = 0;
</span><span class="hll"> for (a = 1; a &lt;= NR; a += 1) {
</span><span class="hll"> suma += a;
</span><span class="hll"> }
</span><span class="hll"> $suma = suma;
</span><span class="hll"> &#39;
</span> a b i x y suma
pan pan 1 0.3467901443380824 0.7268028627434533 1
eks pan 2 0.7586799647899636 0.5221511083334797 3
wye wye 3 0.20460330576630303 0.33831852551664776 6
eks wye 4 0.38139939387114097 0.13418874328430463 10
wye pan 5 0.5732889198020006 0.8636244699032729 15
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/small --opprint put &#39;
</span><span class="hll"> num suma = 0;
</span><span class="hll"> num sumb = 0;
</span><span class="hll"> for (num a = 1, num b = 1; a &lt;= NR; a += 1, b *= 2) {
</span><span class="hll"> suma += a;
</span><span class="hll"> sumb += b;
</span><span class="hll"> }
</span><span class="hll"> $suma = suma;
</span><span class="hll"> $sumb = sumb;
</span><span class="hll"> &#39;
</span> a b i x y suma sumb
pan pan 1 0.3467901443380824 0.7268028627434533 1 1
eks pan 2 0.7586799647899636 0.5221511083334797 3 3
wye wye 3 0.20460330576630303 0.33831852551664776 6 7
eks wye 4 0.38139939387114097 0.13418874328430463 10 15
wye pan 5 0.5732889198020006 0.8636244699032729 15 31
</pre></div>
</div>
<p>Notes:</p>
<ul class="simple">
<li><p>In <code class="docutils literal notranslate"><span class="pre">for</span> <span class="pre">(start;</span> <span class="pre">continuation;</span> <span class="pre">update)</span> <span class="pre">{</span> <span class="pre">body</span> <span class="pre">}</span></code>, the start, continuation, and update statements may be empty, single statements, or multiple comma-separated statements. If the continuation is empty (e.g. <code class="docutils literal notranslate"><span class="pre">for(i=1;;i+=1)</span></code>) it defaults to true.</p></li>
<li><p>In particular, you may use <code class="docutils literal notranslate"><span class="pre">$</span></code>-variables and/or <code class="docutils literal notranslate"><span class="pre">&#64;</span></code>-variables in the start, continuation, and/or update steps (as well as the body, of course).</p></li>
<li><p>The typedecls such as <code class="docutils literal notranslate"><span class="pre">int</span></code> or <code class="docutils literal notranslate"><span class="pre">num</span></code> are optional. If a typedecl is provided (for a local variable), it binds a variable scoped to the for-loop regardless of whether a same-name variable is present in outer scope. If a typedecl is not provided, then the variable is scoped to the for-loop if no same-name variable is present in outer scope, or if a same-name variable is present in outer scope then it is modified.</p></li>
<li><p>Miller has no <code class="docutils literal notranslate"><span class="pre">++</span></code> or <code class="docutils literal notranslate"><span class="pre">--</span></code> operators.</p></li>
<li><p>As with all for/if/while statements in Miller, the curly braces are required even if the body is a single statement, or empty.</p></li>
</ul>
</div>
</div>
<div class="section" id="begin-end-blocks">
<h3>Begin/end blocks<a class="headerlink" href="#begin-end-blocks" title="Permalink to this headline"></a></h3>
<p>Miller supports an <code class="docutils literal notranslate"><span class="pre">awk</span></code>-like <code class="docutils literal notranslate"><span class="pre">begin/end</span></code> syntax. The statements in the <code class="docutils literal notranslate"><span class="pre">begin</span></code> block are executed before any input records are read; the statements in the <code class="docutils literal notranslate"><span class="pre">end</span></code> block are executed after the last input record is read. (If you want to execute some statement at the start of each file, not at the start of the first file as with <code class="docutils literal notranslate"><span class="pre">begin</span></code>, you might use a pattern/action block of the form <code class="docutils literal notranslate"><span class="pre">FNR</span> <span class="pre">==</span> <span class="pre">1</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">}</span></code>.) All statements outside of <code class="docutils literal notranslate"><span class="pre">begin</span></code> or <code class="docutils literal notranslate"><span class="pre">end</span></code> are, of course, executed on every input record. Semicolons separate statements inside or outside of begin/end blocks; semicolons are required between begin/end block bodies and any subsequent statement. For example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;
</span><span class="hll"> begin { @sum = 0 };
</span><span class="hll"> @x_sum += $x;
</span><span class="hll"> end { emit @x_sum }
</span><span class="hll"> &#39; ../data/small
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729
a=zee,b=pan,i=6,x=0.5271261600918548,y=0.49322128674835697
a=eks,b=zee,i=7,x=0.6117840605678454,y=0.1878849191181694
a=zee,b=wye,i=8,x=0.5985540091064224,y=0.976181385699006
a=hat,b=wye,i=9,x=0.03144187646093577,y=0.7495507603507059
a=pan,b=wye,i=10,x=0.5026260055412137,y=0.9526183602969864
x_sum=4.536293840335763
</pre></div>
</div>
<p>Since uninitialized out-of-stream variables default to 0 for addition/substraction and 1 for multiplication when they appear on expression right-hand sides (not quite as in <code class="docutils literal notranslate"><span class="pre">awk</span></code>, where theyd default to 0 either way), the above can be written more succinctly as</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;
</span><span class="hll"> @x_sum += $x;
</span><span class="hll"> end { emit @x_sum }
</span><span class="hll"> &#39; ../data/small
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729
a=zee,b=pan,i=6,x=0.5271261600918548,y=0.49322128674835697
a=eks,b=zee,i=7,x=0.6117840605678454,y=0.1878849191181694
a=zee,b=wye,i=8,x=0.5985540091064224,y=0.976181385699006
a=hat,b=wye,i=9,x=0.03144187646093577,y=0.7495507603507059
a=pan,b=wye,i=10,x=0.5026260055412137,y=0.9526183602969864
x_sum=4.536293840335763
</pre></div>
</div>
<p>The <strong>put -q</strong> option is a shorthand which suppresses printing of each output record, with only <code class="docutils literal notranslate"><span class="pre">emit</span></code> statements being output. So to get only summary outputs, one could write</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;
</span><span class="hll"> @x_sum += $x;
</span><span class="hll"> end { emit @x_sum }
</span><span class="hll"> &#39; ../data/small
</span> x_sum=4.536293840335763
</pre></div>
</div>
<p>We can do similarly with multiple out-of-stream variables:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;
</span><span class="hll"> @x_count += 1;
</span><span class="hll"> @x_sum += $x;
</span><span class="hll"> end {
</span><span class="hll"> emit @x_count;
</span><span class="hll"> emit @x_sum;
</span><span class="hll"> }
</span><span class="hll"> &#39; ../data/small
</span> x_count=10
x_sum=4.536293840335763
</pre></div>
</div>
<p>This is of course not much different than</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr stats1 -a count,sum -f x ../data/small
</span> x_count=10,x_sum=4.536293840335763
</pre></div>
</div>
<p>Note that its a syntax error for begin/end blocks to refer to field names (beginning with <code class="docutils literal notranslate"><span class="pre">$</span></code>), since these execute outside the context of input records.</p>
</div>
</div>
<div class="section" id="output-statements">
<h2>Output statements<a class="headerlink" href="#output-statements" title="Permalink to this headline"></a></h2>
<p>You can <strong>output</strong> variable-values or expressions in <strong>five ways</strong>:</p>
<ul class="simple">
<li><p><strong>Assign</strong> them to stream-record fields. For example, <code class="docutils literal notranslate"><span class="pre">$cumulative_sum</span> <span class="pre">=</span> <span class="pre">&#64;sum</span></code>. For another example, <code class="docutils literal notranslate"><span class="pre">$nr</span> <span class="pre">=</span> <span class="pre">NR</span></code> adds a field named <code class="docutils literal notranslate"><span class="pre">nr</span></code> to each output record, containing the value of the built-in variable <code class="docutils literal notranslate"><span class="pre">NR</span></code> as of when that record was ingested.</p></li>
<li><p>Use the <strong>print</strong> or <strong>eprint</strong> keywords which immediately print an expression <em>directly to standard output or standard error</em>, respectively. Note that <code class="docutils literal notranslate"><span class="pre">dump</span></code>, <code class="docutils literal notranslate"><span class="pre">edump</span></code>, <code class="docutils literal notranslate"><span class="pre">print</span></code>, and <code class="docutils literal notranslate"><span class="pre">eprint</span></code> dont output records which participate in <code class="docutils literal notranslate"><span class="pre">then</span></code>-chaining; rather, theyre just immediate prints to stdout/stderr. The <code class="docutils literal notranslate"><span class="pre">printn</span></code> and <code class="docutils literal notranslate"><span class="pre">eprintn</span></code> keywords are the same except that they dont print final newlines. Additionally, you can print to a specified file instead of stdout/stderr.</p></li>
<li><p>Use the <strong>dump</strong> or <strong>edump</strong> keywords, which <em>immediately print all out-of-stream variables as a JSON data structure to the standard output or standard error</em> (respectively).</p></li>
<li><p>Use <strong>tee</strong> which formats the current stream record (not just an arbitrary string as with <strong>print</strong>) to a specific file.</p></li>
<li><p>Use <strong>emit</strong>/<strong>emitp</strong>/<strong>emitf</strong> to send out-of-stream variables current values to the output record stream, e.g. <code class="docutils literal notranslate"><span class="pre">&#64;sum</span> <span class="pre">+=</span> <span class="pre">$x;</span> <span class="pre">emit</span> <span class="pre">&#64;sum</span></code> which produces an extra output record such as <code class="docutils literal notranslate"><span class="pre">sum=3.1648382</span></code>.</p></li>
</ul>
<p>For the first two options you are populating the output-records stream which feeds into the next verb in a <code class="docutils literal notranslate"><span class="pre">then</span></code>-chain (if any), or which otherwise is formatted for output using <code class="docutils literal notranslate"><span class="pre">--o...</span></code> flags.</p>
<p>For the last three options you are sending output directly to standard output, standard error, or a file.</p>
<div class="section" id="print-statements">
<span id="reference-dsl-print-statements"></span><h3>Print statements<a class="headerlink" href="#print-statements" title="Permalink to this headline"></a></h3>
<p>The <code class="docutils literal notranslate"><span class="pre">print</span></code> statement is perhaps self-explanatory, but with a few light caveats:</p>
<ul class="simple">
<li><p>There are four variants: <code class="docutils literal notranslate"><span class="pre">print</span></code> goes to stdout with final newline, <code class="docutils literal notranslate"><span class="pre">printn</span></code> goes to stdout without final newline (you can include one using “n” in your output string), <code class="docutils literal notranslate"><span class="pre">eprint</span></code> goes to stderr with final newline, and <code class="docutils literal notranslate"><span class="pre">eprintn</span></code> goes to stderr without final newline.</p></li>
<li><p>Output goes directly to stdout/stderr, respectively: data produced this way do not go downstream to the next verb in a <code class="docutils literal notranslate"><span class="pre">then</span></code>-chain. (Use <code class="docutils literal notranslate"><span class="pre">emit</span></code> for that.)</p></li>
<li><p>Print statements are for strings (<code class="docutils literal notranslate"><span class="pre">print</span> <span class="pre">&quot;hello&quot;</span></code>), or things which can be made into strings: numbers (<code class="docutils literal notranslate"><span class="pre">print</span> <span class="pre">3</span></code>, <code class="docutils literal notranslate"><span class="pre">print</span> <span class="pre">$a</span> <span class="pre">+</span> <span class="pre">$b</span></code>, or concatenations thereof (<code class="docutils literal notranslate"><span class="pre">print</span> <span class="pre">&quot;a</span> <span class="pre">+</span> <span class="pre">b</span> <span class="pre">=</span> <span class="pre">&quot;</span> <span class="pre">.</span> <span class="pre">($a</span> <span class="pre">+</span> <span class="pre">$b)</span></code>). Maps (in <code class="docutils literal notranslate"><span class="pre">$*</span></code>, map-valued out-of-stream or local variables, and map literals) arent convertible into strings. If you print a map, you get <code class="docutils literal notranslate"><span class="pre">{is-a-map}</span></code> as output. Please use <code class="docutils literal notranslate"><span class="pre">dump</span></code> to print maps.</p></li>
<li><p>You can redirect print output to a file: <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">--from</span> <span class="pre">myfile.dat</span> <span class="pre">put</span> <span class="pre">'print</span> <span class="pre">&gt;</span> <span class="pre">&quot;tap.txt&quot;,</span> <span class="pre">$x'</span></code> <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">--from</span> <span class="pre">myfile.dat</span> <span class="pre">put</span> <span class="pre">'o=$*;</span> <span class="pre">print</span> <span class="pre">&gt;</span> <span class="pre">$a.&quot;.txt&quot;,</span> <span class="pre">$x'</span></code>.</p></li>
<li><p>See also <a class="reference internal" href="#reference-dsl-redirected-output-statements"><span class="std std-ref">Redirected-output statements</span></a> for examples.</p></li>
</ul>
</div>
<div class="section" id="dump-statements">
<span id="reference-dsl-dump-statements"></span><h3>Dump statements<a class="headerlink" href="#dump-statements" title="Permalink to this headline"></a></h3>
<p>The <code class="docutils literal notranslate"><span class="pre">dump</span></code> statement is for printing expressions, including maps, directly to stdout/stderr, respectively:</p>
<ul class="simple">
<li><p>There are two variants: <code class="docutils literal notranslate"><span class="pre">dump</span></code> prints to stdout; <code class="docutils literal notranslate"><span class="pre">edump</span></code> prints to stderr.</p></li>
<li><p>Output goes directly to stdout/stderr, respectively: data produced this way do not go downstream to the next verb in a <code class="docutils literal notranslate"><span class="pre">then</span></code>-chain. (Use <code class="docutils literal notranslate"><span class="pre">emit</span></code> for that.)</p></li>
<li><p>You can use <code class="docutils literal notranslate"><span class="pre">dump</span></code> to output single strings, numbers, or expressions including map-valued data. Map-valued data are printed as JSON. Miller allows string and integer keys in its map literals while JSON allows only string keys, so use <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span> <span class="pre">--jknquoteint</span></code> if you want integer-valued map keys not double-quoted.</p></li>
<li><p>If you use <code class="docutils literal notranslate"><span class="pre">dump</span></code> (or <code class="docutils literal notranslate"><span class="pre">edump</span></code>) with no arguments, you get a JSON structure representing the current values of all out-of-stream variables.</p></li>
<li><p>As with <code class="docutils literal notranslate"><span class="pre">print</span></code>, you can redirect output to files.</p></li>
<li><p>See also <a class="reference internal" href="#reference-dsl-redirected-output-statements"><span class="std std-ref">Redirected-output statements</span></a> for examples.</p></li>
</ul>
</div>
<div class="section" id="tee-statements">
<h3>Tee statements<a class="headerlink" href="#tee-statements" title="Permalink to this headline"></a></h3>
<p>Records produced by a <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span></code> go downstream to the next verb in your <code class="docutils literal notranslate"><span class="pre">then</span></code>-chain, if any, or otherwise to standard output. If you want to additionally copy out records to files, you can do that using <code class="docutils literal notranslate"><span class="pre">tee</span></code>.</p>
<p>The syntax is, by example, <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">--from</span> <span class="pre">myfile.dat</span> <span class="pre">put</span> <span class="pre">'tee</span> <span class="pre">&gt;</span> <span class="pre">&quot;tap.dat&quot;,</span> <span class="pre">$*'</span> <span class="pre">then</span> <span class="pre">sort</span> <span class="pre">-n</span> <span class="pre">index</span></code>. First is <code class="docutils literal notranslate"><span class="pre">tee</span> <span class="pre">&gt;</span></code>, then the filename expression (which can be an expression such as <code class="docutils literal notranslate"><span class="pre">&quot;tap.&quot;.$a.&quot;.dat&quot;</span></code>), then a comma, then <code class="docutils literal notranslate"><span class="pre">$*</span></code>. (Nothing else but <code class="docutils literal notranslate"><span class="pre">$*</span></code> is teeable.)</p>
<p>See also <a class="reference internal" href="#reference-dsl-redirected-output-statements"><span class="std std-ref">Redirected-output statements</span></a> for examples.</p>
</div>
<div class="section" id="redirected-output-statements">
<span id="reference-dsl-redirected-output-statements"></span><h3>Redirected-output statements<a class="headerlink" href="#redirected-output-statements" title="Permalink to this headline"></a></h3>
<p>The <strong>print</strong>, <strong>dump</strong> <strong>tee</strong>, <strong>emitf</strong>, <strong>emit</strong>, and <strong>emitp</strong> keywords all allow you to redirect output to one or more files or pipe-to commands. The filenames/commands are strings which can be constructed using record-dependent values, so you can do things like splitting a table into multiple files, one for each account ID, and so on.</p>
<p>Details:</p>
<ul class="simple">
<li><p>The <code class="docutils literal notranslate"><span class="pre">print</span></code> and <code class="docutils literal notranslate"><span class="pre">dump</span></code> keywords produce output immediately to standard output, or to specified file(s) or pipe-to command if present.</p></li>
</ul>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --help-keyword print
</span> TOD: port mlr_dsl_keyword_usage
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --help-keyword dump
</span> TOD: port mlr_dsl_keyword_usage
</pre></div>
</div>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span></code> sends the current record (possibly modified by the <code class="docutils literal notranslate"><span class="pre">put</span></code> expression) to the output record stream. Records are then input to the following verb in a <code class="docutils literal notranslate"><span class="pre">then</span></code>-chain (if any), else printed to standard output (unless <code class="docutils literal notranslate"><span class="pre">put</span> <span class="pre">-q</span></code>). The <strong>tee</strong> keyword <em>additionally</em> writes the output record to specified file(s) or pipe-to command, or immediately to <code class="docutils literal notranslate"><span class="pre">stdout</span></code>/<code class="docutils literal notranslate"><span class="pre">stderr</span></code>.</p></li>
</ul>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --help-keyword tee
</span> TOD: port mlr_dsl_keyword_usage
</pre></div>
</div>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span></code>s <code class="docutils literal notranslate"><span class="pre">emitf</span></code>, <code class="docutils literal notranslate"><span class="pre">emitp</span></code>, and <code class="docutils literal notranslate"><span class="pre">emit</span></code> send out-of-stream variables to the output record stream. These are then input to the following verb in a <code class="docutils literal notranslate"><span class="pre">then</span></code>-chain (if any), else printed to standard output. When redirected with <code class="docutils literal notranslate"><span class="pre">&gt;</span></code>, <code class="docutils literal notranslate"><span class="pre">&gt;&gt;</span></code>, or <code class="docutils literal notranslate"><span class="pre">|</span></code>, they <em>instead</em> write the out-of-stream variable(s) to specified file(s) or pipe-to command, or immediately to <code class="docutils literal notranslate"><span class="pre">stdout</span></code>/<code class="docutils literal notranslate"><span class="pre">stderr</span></code>.</p></li>
</ul>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --help-keyword emitf
</span> TOD: port mlr_dsl_keyword_usage
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --help-keyword emitp
</span> TOD: port mlr_dsl_keyword_usage
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --help-keyword emit
</span> TOD: port mlr_dsl_keyword_usage
</pre></div>
</div>
</div>
<div class="section" id="emit-statements">
<span id="reference-dsl-emit-statements"></span><h3>Emit statements<a class="headerlink" href="#emit-statements" title="Permalink to this headline"></a></h3>
<p>There are three variants: <code class="docutils literal notranslate"><span class="pre">emitf</span></code>, <code class="docutils literal notranslate"><span class="pre">emit</span></code>, and <code class="docutils literal notranslate"><span class="pre">emitp</span></code>. Keep in mind that out-of-stream variables are a nested, multi-level hashmap (directly viewable as JSON using <code class="docutils literal notranslate"><span class="pre">dump</span></code>), whereas Miller output records are lists of single-level key-value pairs. The three emit variants allow you to control how the multilevel hashmaps are flatten down to output records. You can emit any map-valued expression, including <code class="docutils literal notranslate"><span class="pre">$*</span></code>, map-valued out-of-stream variables, the entire out-of-stream-variable collection <code class="docutils literal notranslate"><span class="pre">&#64;*</span></code>, map-valued local variables, map literals, or map-valued function return values.</p>
<p>Use <strong>emitf</strong> to output several out-of-stream variables side-by-side in the same output record. For <code class="docutils literal notranslate"><span class="pre">emitf</span></code> these mustnt have indexing using <code class="docutils literal notranslate"><span class="pre">&#64;name[...]</span></code>. Example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@count += 1; @x_sum += $x; @y_sum += $y; end { emitf @count, @x_sum, @y_sum}&#39; data/small
</span> count=5,x_sum=2.264761728567491,y_sum=2.585085709781158
</pre></div>
</div>
<p>Use <strong>emit</strong> to output an out-of-stream variable. If its non-indexed youll get a simple key-value pair:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ cat data/small
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@sum += $x; end { dump }&#39; data/small
</span> {
&quot;sum&quot;: 2.264761728567491
}
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@sum += $x; end { emit @sum }&#39; data/small
</span> sum=2.264761728567491
</pre></div>
</div>
<p>If its indexed then use as many names after <code class="docutils literal notranslate"><span class="pre">emit</span></code> as there are indices:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@sum[$a] += $x; end { dump }&#39; data/small
</span> {
&quot;sum&quot;: {
&quot;pan&quot;: 0.3467901443380824,
&quot;eks&quot;: 1.1400793586611044,
&quot;wye&quot;: 0.7778922255683036
}
}
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@sum[$a] += $x; end { emit @sum, &quot;a&quot; }&#39; data/small
</span> a=pan,sum=0.3467901443380824
a=eks,sum=1.1400793586611044
a=wye,sum=0.7778922255683036
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@sum[$a][$b] += $x; end { dump }&#39; data/small
</span> {
&quot;sum&quot;: {
&quot;pan&quot;: {
&quot;pan&quot;: 0.3467901443380824
},
&quot;eks&quot;: {
&quot;pan&quot;: 0.7586799647899636,
&quot;wye&quot;: 0.38139939387114097
},
&quot;wye&quot;: {
&quot;wye&quot;: 0.20460330576630303,
&quot;pan&quot;: 0.5732889198020006
}
}
}
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@sum[$a][$b] += $x; end { emit @sum, &quot;a&quot;, &quot;b&quot; }&#39; data/small
</span> a=pan,b=pan,sum=0.3467901443380824
a=eks,b=pan,sum=0.7586799647899636
a=eks,b=wye,sum=0.38139939387114097
a=wye,b=wye,sum=0.20460330576630303
a=wye,b=pan,sum=0.5732889198020006
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@sum[$a][$b][$i] += $x; end { dump }&#39; data/small
</span> {
&quot;sum&quot;: {
&quot;pan&quot;: {
&quot;pan&quot;: {
&quot;1&quot;: 0.3467901443380824
}
},
&quot;eks&quot;: {
&quot;pan&quot;: {
&quot;2&quot;: 0.7586799647899636
},
&quot;wye&quot;: {
&quot;4&quot;: 0.38139939387114097
}
},
&quot;wye&quot;: {
&quot;wye&quot;: {
&quot;3&quot;: 0.20460330576630303
},
&quot;pan&quot;: {
&quot;5&quot;: 0.5732889198020006
}
}
}
}
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@sum[$a][$b][$i] += $x; end { emit @sum, &quot;a&quot;, &quot;b&quot;, &quot;i&quot; }&#39; data/small
</span> a=pan,b=pan,i=1,sum=0.3467901443380824
a=eks,b=pan,i=2,sum=0.7586799647899636
a=eks,b=wye,i=4,sum=0.38139939387114097
a=wye,b=wye,i=3,sum=0.20460330576630303
a=wye,b=pan,i=5,sum=0.5732889198020006
</pre></div>
</div>
<p>Now for <strong>emitp</strong>: if you have as many names following <code class="docutils literal notranslate"><span class="pre">emit</span></code> as there are levels in the out-of-stream variables hashmap, then <code class="docutils literal notranslate"><span class="pre">emit</span></code> and <code class="docutils literal notranslate"><span class="pre">emitp</span></code> do the same thing. Where they differ is when you dont specify as many names as there are hashmap levels. In this case, Miller needs to flatten multiple map indices down to output-record keys: <code class="docutils literal notranslate"><span class="pre">emitp</span></code> includes full prefixing (hence the <code class="docutils literal notranslate"><span class="pre">p</span></code> in <code class="docutils literal notranslate"><span class="pre">emitp</span></code>) while <code class="docutils literal notranslate"><span class="pre">emit</span></code> takes the deepest hashmap key as the output-record key:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@sum[$a][$b] += $x; end { dump }&#39; data/small
</span> {
&quot;sum&quot;: {
&quot;pan&quot;: {
&quot;pan&quot;: 0.3467901443380824
},
&quot;eks&quot;: {
&quot;pan&quot;: 0.7586799647899636,
&quot;wye&quot;: 0.38139939387114097
},
&quot;wye&quot;: {
&quot;wye&quot;: 0.20460330576630303,
&quot;pan&quot;: 0.5732889198020006
}
}
}
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@sum[$a][$b] += $x; end { emit @sum, &quot;a&quot; }&#39; data/small
</span> a=pan,pan=0.3467901443380824
a=eks,pan=0.7586799647899636,wye=0.38139939387114097
a=wye,wye=0.20460330576630303,pan=0.5732889198020006
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@sum[$a][$b] += $x; end { emit @sum }&#39; data/small
</span> pan.pan=0.3467901443380824,eks.pan=0.7586799647899636,eks.wye=0.38139939387114097,wye.wye=0.20460330576630303,wye.pan=0.5732889198020006
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@sum[$a][$b] += $x; end { emitp @sum, &quot;a&quot; }&#39; data/small
</span> a=pan,sum.pan=0.3467901443380824
a=eks,sum.pan=0.7586799647899636,sum.wye=0.38139939387114097
a=wye,sum.wye=0.20460330576630303,sum.pan=0.5732889198020006
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@sum[$a][$b] += $x; end { emitp @sum }&#39; data/small
</span> sum.pan.pan=0.3467901443380824,sum.eks.pan=0.7586799647899636,sum.eks.wye=0.38139939387114097,sum.wye.wye=0.20460330576630303,sum.wye.pan=0.5732889198020006
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --oxtab put -q &#39;@sum[$a][$b] += $x; end { emitp @sum }&#39; data/small
</span> sum.pan.pan 0.3467901443380824
sum.eks.pan 0.7586799647899636
sum.eks.wye 0.38139939387114097
sum.wye.wye 0.20460330576630303
sum.wye.pan 0.5732889198020006
</pre></div>
</div>
<p>Use <strong>oflatsep</strong> to specify the character which joins multilevel
keys for <code class="docutils literal notranslate"><span class="pre">emitp</span></code> (it defaults to a colon):</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q --oflatsep / &#39;@sum[$a][$b] += $x; end { emitp @sum, &quot;a&quot; }&#39; data/small
</span> a=pan,sum.pan=0.3467901443380824
a=eks,sum.pan=0.7586799647899636,sum.wye=0.38139939387114097
a=wye,sum.wye=0.20460330576630303,sum.pan=0.5732889198020006
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q --oflatsep / &#39;@sum[$a][$b] += $x; end { emitp @sum }&#39; data/small
</span> sum.pan.pan=0.3467901443380824,sum.eks.pan=0.7586799647899636,sum.eks.wye=0.38139939387114097,sum.wye.wye=0.20460330576630303,sum.wye.pan=0.5732889198020006
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --oxtab put -q --oflatsep / &#39;@sum[$a][$b] += $x; end { emitp @sum }&#39; data/small
</span> sum.pan.pan 0.3467901443380824
sum.eks.pan 0.7586799647899636
sum.eks.wye 0.38139939387114097
sum.wye.wye 0.20460330576630303
sum.wye.pan 0.5732889198020006
</pre></div>
</div>
</div>
<div class="section" id="multi-emit-statements">
<h3>Multi-emit statements<a class="headerlink" href="#multi-emit-statements" title="Permalink to this headline"></a></h3>
<p>You can emit <strong>multiple map-valued expressions side-by-side</strong> by
including their names in parentheses:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/medium --opprint put -q &#39;
</span><span class="hll"> @x_count[$a][$b] += 1;
</span><span class="hll"> @x_sum[$a][$b] += $x;
</span><span class="hll"> end {
</span><span class="hll"> for ((a, b), _ in @x_count) {
</span><span class="hll"> @x_mean[a][b] = @x_sum[a][b] / @x_count[a][b]
</span><span class="hll"> }
</span><span class="hll"> emit (@x_sum, @x_count, @x_mean), &quot;a&quot;, &quot;b&quot;
</span><span class="hll"> }
</span><span class="hll"> &#39;
</span> a b x_sum x_count x_mean
pan pan 219.1851288316854 427 0.5133141190437597
pan wye 198.43293070748447 395 0.5023618498923658
pan eks 216.07522773165525 429 0.5036718595143479
pan hat 205.22277621488686 417 0.492140950155604
pan zee 205.09751802331917 413 0.4966041598627583
eks pan 179.96303047250723 371 0.48507555383425127
eks wye 196.9452860713734 407 0.4838950517724162
eks zee 176.8803651584733 357 0.49546320772681596
eks eks 215.91609712937984 413 0.5227992666570941
eks hat 208.783170520597 417 0.5006790659966355
wye wye 185.29584980261419 377 0.49150092785839306
wye pan 195.84790012056564 392 0.4996119901034838
wye hat 212.0331829346132 426 0.4977304763723314
wye zee 194.77404756708714 385 0.5059066170573692
wye eks 204.8129608356315 386 0.5306035254809106
zee pan 202.21380378504267 389 0.5198298297816007
zee wye 233.9913939194868 455 0.5142667998230479
zee eks 190.9617780631925 391 0.4883932942792647
zee zee 206.64063510417319 403 0.5127559183726382
zee hat 191.30000620900935 409 0.46772617655014515
hat wye 208.8830097609959 423 0.49381326184632596
hat zee 196.3494502965293 385 0.5099985721987774
hat eks 189.0067933716193 389 0.48587864619953547
hat hat 182.8535323148762 381 0.47993053101017374
hat pan 168.5538067327806 363 0.4643355557376876
</pre></div>
</div>
<p>What this does is walk through the first out-of-stream variable (<code class="docutils literal notranslate"><span class="pre">&#64;x_sum</span></code> in this example) as usual, then for each keylist found (e.g. <code class="docutils literal notranslate"><span class="pre">pan,wye</span></code>), include the values for the remaining out-of-stream variables (here, <code class="docutils literal notranslate"><span class="pre">&#64;x_count</span></code> and <code class="docutils literal notranslate"><span class="pre">&#64;x_mean</span></code>). You should use this when all out-of-stream variables in the emit statement have <strong>the same shape and the same keylists</strong>.</p>
</div>
<div class="section" id="emit-all-statements">
<h3>Emit-all statements<a class="headerlink" href="#emit-all-statements" title="Permalink to this headline"></a></h3>
<p>Use <strong>emit all</strong> (or <code class="docutils literal notranslate"><span class="pre">emit</span> <span class="pre">&#64;*</span></code> which is synonymous) to output all out-of-stream variables. You can use the following idiom to get various accumulators output side-by-side (reminiscent of <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">stats1</span></code>):</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/small --opprint put -q &#39;@v[$a][$b][&quot;sum&quot;] += $x; @v[$a][$b][&quot;count&quot;] += 1; end{emit @*,&quot;a&quot;,&quot;b&quot;}&#39;
</span> a b pan.sum pan.count
v pan 0.3467901443380824 1
a b pan.sum pan.count wye.sum wye.count
v eks 0.7586799647899636 1 0.38139939387114097 1
a b wye.sum wye.count pan.sum pan.count
v wye 0.20460330576630303 1 0.5732889198020006 1
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/small --opprint put -q &#39;@sum[$a][$b] += $x; @count[$a][$b] += 1; end{emit @*,&quot;a&quot;,&quot;b&quot;}&#39;
</span> a b pan
sum pan 0.3467901443380824
a b pan wye
sum eks 0.7586799647899636 0.38139939387114097
a b wye pan
sum wye 0.20460330576630303 0.5732889198020006
a b pan
count pan 1
a b pan wye
count eks 1 1
a b wye pan
count wye 1 1
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --from data/small --opprint put -q &#39;@sum[$a][$b] += $x; @count[$a][$b] += 1; end{emit (@sum, @count),&quot;a&quot;,&quot;b&quot;}&#39;
</span> a b sum count
pan pan 0.3467901443380824 1
eks pan 0.7586799647899636 1
eks wye 0.38139939387114097 1
wye wye 0.20460330576630303 1
wye pan 0.5732889198020006 1
</pre></div>
</div>
</div>
</div>
<div class="section" id="unset-statements">
<h2>Unset statements<a class="headerlink" href="#unset-statements" title="Permalink to this headline"></a></h2>
<p>You can clear a map key by assigning the empty string as its value: <code class="docutils literal notranslate"><span class="pre">$x=&quot;&quot;</span></code> or <code class="docutils literal notranslate"><span class="pre">&#64;x=&quot;&quot;</span></code>. Using <code class="docutils literal notranslate"><span class="pre">unset</span></code> you can remove the key entirely. Examples:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ cat data/small
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;unset $x, $a&#39; data/small
</span> b=pan,i=1,y=0.7268028627434533
b=pan,i=2,y=0.5221511083334797
b=wye,i=3,y=0.33831852551664776
b=wye,i=4,y=0.13418874328430463
b=pan,i=5,y=0.8636244699032729
</pre></div>
</div>
<p>This can also be done, of course, using <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">cut</span> <span class="pre">-x</span></code>. You can also clear out-of-stream or local variables, at the base name level, or at an indexed sublevel:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@sum[$a][$b] += $x; end { dump; unset @sum; dump }&#39; data/small
</span> {
&quot;sum&quot;: {
&quot;pan&quot;: {
&quot;pan&quot;: 0.3467901443380824
},
&quot;eks&quot;: {
&quot;pan&quot;: 0.7586799647899636,
&quot;wye&quot;: 0.38139939387114097
},
&quot;wye&quot;: {
&quot;wye&quot;: 0.20460330576630303,
&quot;pan&quot;: 0.5732889198020006
}
}
}
{}
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put -q &#39;@sum[$a][$b] += $x; end { dump; unset @sum[&quot;eks&quot;]; dump }&#39; data/small
</span> {
&quot;sum&quot;: {
&quot;pan&quot;: {
&quot;pan&quot;: 0.3467901443380824
},
&quot;eks&quot;: {
&quot;pan&quot;: 0.7586799647899636,
&quot;wye&quot;: 0.38139939387114097
},
&quot;wye&quot;: {
&quot;wye&quot;: 0.20460330576630303,
&quot;pan&quot;: 0.5732889198020006
}
}
}
{
&quot;sum&quot;: {
&quot;pan&quot;: {
&quot;pan&quot;: 0.3467901443380824
},
&quot;wye&quot;: {
&quot;wye&quot;: 0.20460330576630303,
&quot;pan&quot;: 0.5732889198020006
}
}
}
</pre></div>
</div>
<p>If you use <code class="docutils literal notranslate"><span class="pre">unset</span> <span class="pre">all</span></code> (or <code class="docutils literal notranslate"><span class="pre">unset</span> <span class="pre">&#64;*</span></code> which is synonymous), that will unset all out-of-stream variables which have been defined up to that point.</p>
</div>
<div class="section" id="filter-statements">
<h2>Filter statements<a class="headerlink" href="#filter-statements" title="Permalink to this headline"></a></h2>
<p>You can use <code class="docutils literal notranslate"><span class="pre">filter</span></code> within <code class="docutils literal notranslate"><span class="pre">put</span></code>. In fact, the following two are synonymous:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr filter &#39;NR==2 || NR==3&#39; data/small
</span> a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;filter NR==2 || NR==3&#39; data/small
</span> a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776
</pre></div>
</div>
<p>The former, of course, is much easier to type. But the latter allows you to define more complex expressions for the filter, and/or do other things in addition to the filter:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;@running_sum += $x; filter @running_sum &gt; 1.3&#39; data/small
</span> a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr put &#39;$z = $x * $y; filter $z &gt; 0.3&#39; data/small
</span> a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797,z=0.3961455844854848
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729,z=0.4951063394654227
</pre></div>
</div>
</div>
<div class="section" id="built-in-functions-for-filter-and-put-summary">
<h2>Built-in functions for filter and put, summary<a class="headerlink" href="#built-in-functions-for-filter-and-put-summary" title="Permalink to this headline"></a></h2>
<p>mlr: option “list-all-functions-as-table” not recognized.
Please run “mlr help” for usage information.</p>
</div>
<div class="section" id="built-in-functions-for-filter-and-put">
<h2>Built-in functions for filter and put<a class="headerlink" href="#built-in-functions-for-filter-and-put" title="Permalink to this headline"></a></h2>
<p>Each function takes a specific number of arguments, as shown below, except for functions marked as variadic such as <code class="docutils literal notranslate"><span class="pre">min</span></code> and <code class="docutils literal notranslate"><span class="pre">max</span></code>. (The latter compute min and max of any number of numerical arguments.) There is no notion of optional or default-on-absent arguments. All argument-passing is positional rather than by name; arguments are passed by value, not by reference.</p>
<p>You can get a list of all functions using <strong>mlr -F</strong>.</p>
<div class="section" id="reference-dsl-plus">
<span id="id1"></span><h3>+<a class="headerlink" href="#reference-dsl-plus" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">+</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=1,2) Addition as binary operator; unary plus operator.</span>
</pre></div>
</div>
</div>
<div class="section" id="reference-dsl-minus">
<span id="id2"></span><h3>-<a class="headerlink" href="#reference-dsl-minus" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">-</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=1,2) Subtraction as binary operator; unary negation operator.</span>
</pre></div>
</div>
</div>
<div class="section" id="reference-dsl-times">
<span id="id3"></span><h3>*<a class="headerlink" href="#reference-dsl-times" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">*</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=2) Multiplication, with integer*integer overflow to float.</span>
</pre></div>
</div>
</div>
<div class="section" id="id4">
<h3>/<a class="headerlink" href="#id4" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">/</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=2) Division. Integer / integer is floating-point.</span>
</pre></div>
</div>
</div>
<div class="section" id="id6">
<h3>//<a class="headerlink" href="#id6" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">//</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=2) Pythonic integer division, rounding toward negative.</span>
</pre></div>
</div>
</div>
<div class="section" id="reference-dsl-exponentiation">
<span id="id7"></span><h3>**<a class="headerlink" href="#reference-dsl-exponentiation" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">**</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=2) Exponentiation. Same as pow, but as an infix operator.</span>
</pre></div>
</div>
</div>
<div class="section" id="id8">
<span id="id9"></span><h3>.+<a class="headerlink" href="#id8" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">.+</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=2) Addition, with integer-to-integer overflow.</span>
</pre></div>
</div>
</div>
<div class="section" id="id10">
<span id="id11"></span><h3>.-<a class="headerlink" href="#id10" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">.-</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=2) Subtraction, with integer-to-integer overflow.</span>
</pre></div>
</div>
</div>
<div class="section" id="id12">
<span id="id13"></span><h3>.*<a class="headerlink" href="#id12" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">.*</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=2) Multiplication, with integer-to-integer overflow.</span>
</pre></div>
</div>
</div>
<div class="section" id="id14">
<span id="id15"></span><h3>./<a class="headerlink" href="#id14" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">./</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=2) Integer division; not pythonic.</span>
</pre></div>
</div>
</div>
<div class="section" id="id17">
<h3>%<a class="headerlink" href="#id17" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">%</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=2) Remainder; never negative-valued (pythonic).</span>
</pre></div>
</div>
</div>
<div class="section" id="id19">
<h3>~<a class="headerlink" href="#id19" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">~</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=1) Bitwise NOT. Beware &#39;$y=~$x&#39; since =~ is the</span>
<span class="n">regex</span><span class="o">-</span><span class="n">match</span> <span class="n">operator</span><span class="p">:</span> <span class="k">try</span> <span class="s1">&#39;$y = ~$x&#39;</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="id21">
<h3>&amp;<a class="headerlink" href="#id21" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&amp;</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=2) Bitwise AND.</span>
</pre></div>
</div>
</div>
<div class="section" id="reference-dsl-bitwise-or">
<span id="id22"></span><h3>|<a class="headerlink" href="#reference-dsl-bitwise-or" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">|</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=2) Bitwise OR.</span>
</pre></div>
</div>
</div>
<div class="section" id="id24">
<h3>^<a class="headerlink" href="#id24" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">^</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=2) Bitwise XOR.</span>
</pre></div>
</div>
</div>
<div class="section" id="id26">
<h3>&lt;&lt;<a class="headerlink" href="#id26" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;&lt;</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=2) Bitwise left-shift.</span>
</pre></div>
</div>
</div>
<div class="section" id="id28">
<h3>&gt;&gt;<a class="headerlink" href="#id28" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&gt;&gt;</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=2) Bitwise signed right-shift.</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate" id="id29"><div class="highlight"><pre><span></span><span class="go">&gt;&gt;&gt;</span>
<span class="go">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=2) Bitwise unsigned right-shift.</span>
</pre></div>
</div>
</div>
<div class="section" id="id31">
<h3>!<a class="headerlink" href="#id31" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>! (class=boolean #args=1) Logical negation.
</pre></div>
</div>
</div>
<div class="section" id="id33">
<h3>==<a class="headerlink" href="#id33" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">==</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">boolean</span> <span class="c1">#args=2) String/numeric equality. Mixing number and string results in string compare.</span>
</pre></div>
</div>
</div>
<div class="section" id="id34">
<span id="id35"></span><h3>!=<a class="headerlink" href="#id34" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">!=</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">boolean</span> <span class="c1">#args=2) String/numeric inequality. Mixing number and string results in string compare.</span>
</pre></div>
</div>
</div>
<div class="section" id="id37">
<h3>&gt;<a class="headerlink" href="#id37" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&gt;</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">boolean</span> <span class="c1">#args=2) String/numeric greater-than. Mixing number and string results in string compare.</span>
</pre></div>
</div>
</div>
<div class="section" id="id38">
<span id="id39"></span><h3>&gt;=<a class="headerlink" href="#id38" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&gt;=</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">boolean</span> <span class="c1">#args=2) String/numeric greater-than-or-equals. Mixing number and string results in string compare.</span>
</pre></div>
</div>
</div>
<div class="section" id="id41">
<h3>&lt;<a class="headerlink" href="#id41" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">boolean</span> <span class="c1">#args=2) String/numeric less-than. Mixing number and string results in string compare.</span>
</pre></div>
</div>
</div>
<div class="section" id="id42">
<span id="id43"></span><h3>&lt;=<a class="headerlink" href="#id42" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;=</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">boolean</span> <span class="c1">#args=2) String/numeric less-than-or-equals. Mixing number and string results in string compare.</span>
</pre></div>
</div>
</div>
<div class="section" id="id44">
<span id="id45"></span><h3>=~<a class="headerlink" href="#id44" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">=~</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">boolean</span> <span class="c1">#args=2) String (left-hand side) matches regex (right-hand side), e.g. &#39;$name =~ &quot;^a.*b$&quot;&#39;.</span>
</pre></div>
</div>
</div>
<div class="section" id="id46">
<span id="id47"></span><h3>!=~<a class="headerlink" href="#id46" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">!=~</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">boolean</span> <span class="c1">#args=2) String (left-hand side) does not match regex (right-hand side), e.g. &#39;$name !=~ &quot;^a.*b$&quot;&#39;.</span>
</pre></div>
</div>
</div>
<div class="section" id="id49">
<h3>&amp;&amp;<a class="headerlink" href="#id49" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&amp;&amp;</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">boolean</span> <span class="c1">#args=2) Logical AND.</span>
</pre></div>
</div>
</div>
<div class="section" id="id51">
<h3>||<a class="headerlink" href="#id51" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">||</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">boolean</span> <span class="c1">#args=2) Logical OR.</span>
</pre></div>
</div>
</div>
<div class="section" id="id53">
<h3>^^<a class="headerlink" href="#id53" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">^^</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">boolean</span> <span class="c1">#args=2) Logical XOR.</span>
</pre></div>
</div>
</div>
<div class="section" id="id55">
<h3>??<a class="headerlink" href="#id55" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>?? (class=boolean #args=2) Absent-coalesce operator. $a ?? 1 evaluates to 1 if $a isn&#39;t defined in the current record.
</pre></div>
</div>
</div>
<div class="section" id="id57">
<h3>???<a class="headerlink" href="#id57" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>??? (class=boolean #args=2) Absent-coalesce operator. $a ?? 1 evaluates to 1 if $a isn&#39;t defined in the current record, or has empty value.
</pre></div>
</div>
</div>
<div class="section" id="reference-dsl-question-mark-colon">
<span id="id58"></span><h3>?<a class="headerlink" href="#reference-dsl-question-mark-colon" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>?: (class=boolean #args=3) Standard ternary operator.
</pre></div>
</div>
</div>
<div class="section" id="id60">
<h3>.<a class="headerlink" href="#id60" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">.</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=2) String concatenation.</span>
</pre></div>
</div>
</div>
<div class="section" id="abs">
<span id="reference-dsl-abs"></span><h3>abs<a class="headerlink" href="#abs" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nb">abs</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Absolute value.</span>
</pre></div>
</div>
</div>
<div class="section" id="acos">
<span id="reference-dsl-acos"></span><h3>acos<a class="headerlink" href="#acos" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">acos</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Inverse trigonometric cosine.</span>
</pre></div>
</div>
</div>
<div class="section" id="acosh">
<span id="reference-dsl-acosh"></span><h3>acosh<a class="headerlink" href="#acosh" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">acosh</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Inverse hyperbolic cosine.</span>
</pre></div>
</div>
</div>
<div class="section" id="append">
<span id="reference-dsl-append"></span><h3>append<a class="headerlink" href="#append" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">append</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">maps</span><span class="o">/</span><span class="n">arrays</span> <span class="c1">#args=2) Appends second argument to end of first argument, which must be an array.</span>
</pre></div>
</div>
</div>
<div class="section" id="arrayify">
<span id="reference-dsl-arrayify"></span><h3>arrayify<a class="headerlink" href="#arrayify" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">arrayify</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">maps</span><span class="o">/</span><span class="n">arrays</span> <span class="c1">#args=1) Walks through a nested map/array, converting any map with consecutive keys</span>
<span class="s2">&quot;1&quot;</span><span class="p">,</span> <span class="s2">&quot;2&quot;</span><span class="p">,</span> <span class="o">...</span> <span class="n">into</span> <span class="n">an</span> <span class="n">array</span><span class="o">.</span> <span class="n">Useful</span> <span class="n">to</span> <span class="n">wrap</span> <span class="n">the</span> <span class="n">output</span> <span class="n">of</span> <span class="n">unflatten</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asin">
<span id="reference-dsl-asin"></span><h3>asin<a class="headerlink" href="#asin" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asin</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Inverse trigonometric sine.</span>
</pre></div>
</div>
</div>
<div class="section" id="asinh">
<span id="reference-dsl-asinh"></span><h3>asinh<a class="headerlink" href="#asinh" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asinh</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Inverse hyperbolic sine.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-absent">
<span id="reference-dsl-asserting-absent"></span><h3>asserting_absent<a class="headerlink" href="#asserting-absent" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_absent</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_absent on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-array">
<span id="reference-dsl-asserting-array"></span><h3>asserting_array<a class="headerlink" href="#asserting-array" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_array</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_array on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-bool">
<span id="reference-dsl-asserting-bool"></span><h3>asserting_bool<a class="headerlink" href="#asserting-bool" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_bool</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_bool on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-boolean">
<span id="reference-dsl-asserting-boolean"></span><h3>asserting_boolean<a class="headerlink" href="#asserting-boolean" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_boolean</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_boolean on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-empty">
<span id="reference-dsl-asserting-empty"></span><h3>asserting_empty<a class="headerlink" href="#asserting-empty" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_empty</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_empty on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-empty-map">
<span id="reference-dsl-asserting-empty-map"></span><h3>asserting_empty_map<a class="headerlink" href="#asserting-empty-map" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_empty_map</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_empty_map on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-error">
<span id="reference-dsl-asserting-error"></span><h3>asserting_error<a class="headerlink" href="#asserting-error" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_error</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_error on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-float">
<span id="reference-dsl-asserting-float"></span><h3>asserting_float<a class="headerlink" href="#asserting-float" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_float</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_float on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-int">
<span id="reference-dsl-asserting-int"></span><h3>asserting_int<a class="headerlink" href="#asserting-int" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_int</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_int on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-map">
<span id="reference-dsl-asserting-map"></span><h3>asserting_map<a class="headerlink" href="#asserting-map" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_map</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_map on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-nonempty-map">
<span id="reference-dsl-asserting-nonempty-map"></span><h3>asserting_nonempty_map<a class="headerlink" href="#asserting-nonempty-map" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_nonempty_map</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_nonempty_map on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-not-array">
<span id="reference-dsl-asserting-not-array"></span><h3>asserting_not_array<a class="headerlink" href="#asserting-not-array" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_not_array</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_not_array on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-not-empty">
<span id="reference-dsl-asserting-not-empty"></span><h3>asserting_not_empty<a class="headerlink" href="#asserting-not-empty" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_not_empty</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_not_empty on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-not-map">
<span id="reference-dsl-asserting-not-map"></span><h3>asserting_not_map<a class="headerlink" href="#asserting-not-map" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_not_map</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_not_map on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-not-null">
<span id="reference-dsl-asserting-not-null"></span><h3>asserting_not_null<a class="headerlink" href="#asserting-not-null" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_not_null</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_not_null on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-null">
<span id="reference-dsl-asserting-null"></span><h3>asserting_null<a class="headerlink" href="#asserting-null" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_null</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_null on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-numeric">
<span id="reference-dsl-asserting-numeric"></span><h3>asserting_numeric<a class="headerlink" href="#asserting-numeric" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_numeric</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_numeric on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-present">
<span id="reference-dsl-asserting-present"></span><h3>asserting_present<a class="headerlink" href="#asserting-present" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_present</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_present on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="asserting-string">
<span id="reference-dsl-asserting-string"></span><h3>asserting_string<a class="headerlink" href="#asserting-string" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">asserting_string</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Aborts with an error if is_string on the argument returns false,</span>
<span class="k">else</span> <span class="n">returns</span> <span class="n">its</span> <span class="n">argument</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="atan">
<span id="reference-dsl-atan"></span><h3>atan<a class="headerlink" href="#atan" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">atan</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) One-argument arctangent.</span>
</pre></div>
</div>
</div>
<div class="section" id="atan2">
<span id="reference-dsl-atan2"></span><h3>atan2<a class="headerlink" href="#atan2" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">atan2</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=2) Two-argument arctangent.</span>
</pre></div>
</div>
</div>
<div class="section" id="atanh">
<span id="reference-dsl-atanh"></span><h3>atanh<a class="headerlink" href="#atanh" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">atanh</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Inverse hyperbolic tangent.</span>
</pre></div>
</div>
</div>
<div class="section" id="bitcount">
<span id="reference-dsl-bitcount"></span><h3>bitcount<a class="headerlink" href="#bitcount" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">bitcount</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=1) Count of 1-bits.</span>
</pre></div>
</div>
</div>
<div class="section" id="boolean">
<span id="reference-dsl-boolean"></span><h3>boolean<a class="headerlink" href="#boolean" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">boolean</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">conversion</span> <span class="c1">#args=1) Convert int/float/bool/string to boolean.</span>
</pre></div>
</div>
</div>
<div class="section" id="capitalize">
<span id="reference-dsl-capitalize"></span><h3>capitalize<a class="headerlink" href="#capitalize" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">capitalize</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=1) Convert string&#39;s first character to uppercase.</span>
</pre></div>
</div>
</div>
<div class="section" id="cbrt">
<span id="reference-dsl-cbrt"></span><h3>cbrt<a class="headerlink" href="#cbrt" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">cbrt</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Cube root.</span>
</pre></div>
</div>
</div>
<div class="section" id="ceil">
<span id="reference-dsl-ceil"></span><h3>ceil<a class="headerlink" href="#ceil" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceil</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Ceiling: nearest integer at or above.</span>
</pre></div>
</div>
</div>
<div class="section" id="clean-whitespace">
<span id="reference-dsl-clean-whitespace"></span><h3>clean_whitespace<a class="headerlink" href="#clean-whitespace" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">clean_whitespace</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=1) Same as collapse_whitespace and strip.</span>
</pre></div>
</div>
</div>
<div class="section" id="collapse-whitespace">
<span id="reference-dsl-collapse-whitespace"></span><h3>collapse_whitespace<a class="headerlink" href="#collapse-whitespace" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">collapse_whitespace</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=1) Strip repeated whitespace from string.</span>
</pre></div>
</div>
</div>
<div class="section" id="cos">
<span id="reference-dsl-cos"></span><h3>cos<a class="headerlink" href="#cos" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">cos</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Trigonometric cosine.</span>
</pre></div>
</div>
</div>
<div class="section" id="cosh">
<span id="reference-dsl-cosh"></span><h3>cosh<a class="headerlink" href="#cosh" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">cosh</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Hyperbolic cosine.</span>
</pre></div>
</div>
</div>
<div class="section" id="depth">
<span id="reference-dsl-depth"></span><h3>depth<a class="headerlink" href="#depth" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">depth</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">maps</span><span class="o">/</span><span class="n">arrays</span> <span class="c1">#args=1) Prints maximum depth of map/array. Scalars have depth 0.</span>
</pre></div>
</div>
</div>
<div class="section" id="dhms2fsec">
<span id="reference-dsl-dhms2fsec"></span><h3>dhms2fsec<a class="headerlink" href="#dhms2fsec" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">dhms2fsec</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">time</span> <span class="c1">#args=1) Recovers floating-point seconds as in dhms2fsec(&quot;5d18h53m20.250000s&quot;) = 500000.250000</span>
</pre></div>
</div>
</div>
<div class="section" id="dhms2sec">
<span id="reference-dsl-dhms2sec"></span><h3>dhms2sec<a class="headerlink" href="#dhms2sec" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">dhms2sec</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">time</span> <span class="c1">#args=1) Recovers integer seconds as in dhms2sec(&quot;5d18h53m20s&quot;) = 500000</span>
</pre></div>
</div>
</div>
<div class="section" id="erf">
<span id="reference-dsl-erf"></span><h3>erf<a class="headerlink" href="#erf" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">erf</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Error function.</span>
</pre></div>
</div>
</div>
<div class="section" id="erfc">
<span id="reference-dsl-erfc"></span><h3>erfc<a class="headerlink" href="#erfc" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">erfc</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Complementary error function.</span>
</pre></div>
</div>
</div>
<div class="section" id="exp">
<span id="reference-dsl-exp"></span><h3>exp<a class="headerlink" href="#exp" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">exp</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Exponential function e**x.</span>
</pre></div>
</div>
</div>
<div class="section" id="expm1">
<span id="reference-dsl-expm1"></span><h3>expm1<a class="headerlink" href="#expm1" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">expm1</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) e**x - 1.</span>
</pre></div>
</div>
</div>
<div class="section" id="flatten">
<span id="reference-dsl-flatten"></span><h3>flatten<a class="headerlink" href="#flatten" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>flatten (class=maps/arrays #args=3) Flattens multi-level maps to single-level ones. Examples:
flatten(&quot;a&quot;, &quot;.&quot;, {&quot;b&quot;: { &quot;c&quot;: 4 }}) is {&quot;a.b.c&quot; : 4}.
flatten(&quot;&quot;, &quot;.&quot;, {&quot;a&quot;: { &quot;b&quot;: 3 }}) is {&quot;a.b&quot; : 3}.
Two-argument version: flatten($*, &quot;.&quot;) is the same as flatten(&quot;&quot;, &quot;.&quot;, $*).
Useful for nested JSON-like structures for non-JSON file formats like CSV.
</pre></div>
</div>
</div>
<div class="section" id="float">
<span id="reference-dsl-float"></span><h3>float<a class="headerlink" href="#float" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nb">float</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">conversion</span> <span class="c1">#args=1) Convert int/float/bool/string to float.</span>
</pre></div>
</div>
</div>
<div class="section" id="floor">
<span id="reference-dsl-floor"></span><h3>floor<a class="headerlink" href="#floor" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">floor</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Floor: nearest integer at or below.</span>
</pre></div>
</div>
</div>
<div class="section" id="fmtnum">
<span id="reference-dsl-fmtnum"></span><h3>fmtnum<a class="headerlink" href="#fmtnum" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">fmtnum</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">conversion</span> <span class="c1">#args=2) Convert int/float/bool to string using</span>
<span class="n">printf</span><span class="o">-</span><span class="n">style</span> <span class="nb">format</span> <span class="n">string</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">g</span><span class="o">.</span> <span class="s1">&#39;$s = fmtnum($n, &quot;%06lld&quot;)&#39;</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="fsec2dhms">
<span id="reference-dsl-fsec2dhms"></span><h3>fsec2dhms<a class="headerlink" href="#fsec2dhms" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">fsec2dhms</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">time</span> <span class="c1">#args=1) Formats floating-point seconds as in fsec2dhms(500000.25) = &quot;5d18h53m20.250000s&quot;</span>
</pre></div>
</div>
</div>
<div class="section" id="fsec2hms">
<span id="reference-dsl-fsec2hms"></span><h3>fsec2hms<a class="headerlink" href="#fsec2hms" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">fsec2hms</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">time</span> <span class="c1">#args=1) Formats floating-point seconds as in fsec2hms(5000.25) = &quot;01:23:20.250000&quot;</span>
</pre></div>
</div>
</div>
<div class="section" id="get-keys">
<span id="reference-dsl-get-keys"></span><h3>get_keys<a class="headerlink" href="#get-keys" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">get_keys</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">maps</span><span class="o">/</span><span class="n">arrays</span> <span class="c1">#args=1) Returns array of keys of map or array</span>
</pre></div>
</div>
</div>
<div class="section" id="get-values">
<span id="reference-dsl-get-values"></span><h3>get_values<a class="headerlink" href="#get-values" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">get_values</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">maps</span><span class="o">/</span><span class="n">arrays</span> <span class="c1">#args=1) Returns array of keys of map or array -- in the latter case, returns a copy of the array</span>
</pre></div>
</div>
</div>
<div class="section" id="gmt2sec">
<span id="reference-dsl-gmt2sec"></span><h3>gmt2sec<a class="headerlink" href="#gmt2sec" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">gmt2sec</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">time</span> <span class="c1">#args=1) Parses GMT timestamp as integer seconds since the epoch.</span>
</pre></div>
</div>
</div>
<div class="section" id="gsub">
<span id="reference-dsl-gsub"></span><h3>gsub<a class="headerlink" href="#gsub" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">gsub</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=3) Example: &#39;$name=gsub($name, &quot;old&quot;, &quot;new&quot;)&#39; (replace all).</span>
</pre></div>
</div>
</div>
<div class="section" id="haskey">
<span id="reference-dsl-haskey"></span><h3>haskey<a class="headerlink" href="#haskey" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">haskey</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">maps</span><span class="o">/</span><span class="n">arrays</span> <span class="c1">#args=2) True/false if map has/hasn&#39;t key, e.g. &#39;haskey($*, &quot;a&quot;)&#39; or</span>
<span class="s1">&#39;haskey(mymap, mykey)&#39;</span><span class="p">,</span> <span class="ow">or</span> <span class="n">true</span><span class="o">/</span><span class="n">false</span> <span class="k">if</span> <span class="n">array</span> <span class="n">index</span> <span class="ow">is</span> <span class="ow">in</span> <span class="n">bounds</span> <span class="o">/</span> <span class="n">out</span> <span class="n">of</span> <span class="n">bounds</span><span class="o">.</span>
<span class="n">Error</span> <span class="k">if</span> <span class="mi">1</span><span class="n">st</span> <span class="n">argument</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">a</span> <span class="nb">map</span> <span class="ow">or</span> <span class="n">array</span><span class="o">.</span> <span class="n">Note</span> <span class="o">-</span><span class="n">n</span><span class="o">..-</span><span class="mi">1</span> <span class="n">alias</span> <span class="n">to</span> <span class="mf">1.</span><span class="o">.</span><span class="n">n</span> <span class="ow">in</span> <span class="n">Miller</span> <span class="n">arrays</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="hexfmt">
<span id="reference-dsl-hexfmt"></span><h3>hexfmt<a class="headerlink" href="#hexfmt" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">hexfmt</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">conversion</span> <span class="c1">#args=1) Convert int to hex string, e.g. 255 to &quot;0xff&quot;.</span>
</pre></div>
</div>
</div>
<div class="section" id="hms2fsec">
<span id="reference-dsl-hms2fsec"></span><h3>hms2fsec<a class="headerlink" href="#hms2fsec" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">hms2fsec</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">time</span> <span class="c1">#args=1) Recovers floating-point seconds as in hms2fsec(&quot;01:23:20.250000&quot;) = 5000.250000</span>
</pre></div>
</div>
</div>
<div class="section" id="hms2sec">
<span id="reference-dsl-hms2sec"></span><h3>hms2sec<a class="headerlink" href="#hms2sec" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">hms2sec</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">time</span> <span class="c1">#args=1) Recovers integer seconds as in hms2sec(&quot;01:23:20&quot;) = 5000</span>
</pre></div>
</div>
</div>
<div class="section" id="hostname">
<span id="reference-dsl-hostname"></span><h3>hostname<a class="headerlink" href="#hostname" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">hostname</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">system</span> <span class="c1">#args=0) Returns the hostname as a string.</span>
</pre></div>
</div>
</div>
<div class="section" id="int">
<span id="reference-dsl-int"></span><h3>int<a class="headerlink" href="#int" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nb">int</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">conversion</span> <span class="c1">#args=1) Convert int/float/bool/string to int.</span>
</pre></div>
</div>
</div>
<div class="section" id="invqnorm">
<span id="reference-dsl-invqnorm"></span><h3>invqnorm<a class="headerlink" href="#invqnorm" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">invqnorm</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Inverse of normal cumulative distribution function.</span>
<span class="n">Note</span> <span class="n">that</span> <span class="n">invqorm</span><span class="p">(</span><span class="n">urand</span><span class="p">())</span> <span class="ow">is</span> <span class="n">normally</span> <span class="n">distributed</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="is-absent">
<span id="reference-dsl-is-absent"></span><h3>is_absent<a class="headerlink" href="#is-absent" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_absent</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) False if field is present in input, true otherwise</span>
</pre></div>
</div>
</div>
<div class="section" id="is-array">
<span id="reference-dsl-is-array"></span><h3>is_array<a class="headerlink" href="#is-array" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_array</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) True if argument is an array.</span>
</pre></div>
</div>
</div>
<div class="section" id="is-bool">
<span id="reference-dsl-is-bool"></span><h3>is_bool<a class="headerlink" href="#is-bool" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_bool</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) True if field is present with boolean value. Synonymous with is_boolean.</span>
</pre></div>
</div>
</div>
<div class="section" id="is-boolean">
<span id="reference-dsl-is-boolean"></span><h3>is_boolean<a class="headerlink" href="#is-boolean" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_boolean</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) True if field is present with boolean value. Synonymous with is_bool.</span>
</pre></div>
</div>
</div>
<div class="section" id="is-empty">
<span id="reference-dsl-is-empty"></span><h3>is_empty<a class="headerlink" href="#is-empty" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_empty</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) True if field is present in input with empty string value, false otherwise.</span>
</pre></div>
</div>
</div>
<div class="section" id="is-empty-map">
<span id="reference-dsl-is-empty-map"></span><h3>is_empty_map<a class="headerlink" href="#is-empty-map" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_empty_map</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) True if argument is a map which is empty.</span>
</pre></div>
</div>
</div>
<div class="section" id="is-error">
<span id="reference-dsl-is-error"></span><h3>is_error<a class="headerlink" href="#is-error" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_error</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) True if if argument is an error, such as taking string length of an integer.</span>
</pre></div>
</div>
</div>
<div class="section" id="is-float">
<span id="reference-dsl-is-float"></span><h3>is_float<a class="headerlink" href="#is-float" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_float</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) True if field is present with value inferred to be float</span>
</pre></div>
</div>
</div>
<div class="section" id="is-int">
<span id="reference-dsl-is-int"></span><h3>is_int<a class="headerlink" href="#is-int" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_int</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) True if field is present with value inferred to be int</span>
</pre></div>
</div>
</div>
<div class="section" id="is-map">
<span id="reference-dsl-is-map"></span><h3>is_map<a class="headerlink" href="#is-map" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_map</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) True if argument is a map.</span>
</pre></div>
</div>
</div>
<div class="section" id="is-nonempty-map">
<span id="reference-dsl-is-nonempty-map"></span><h3>is_nonempty_map<a class="headerlink" href="#is-nonempty-map" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_nonempty_map</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) True if argument is a map which is non-empty.</span>
</pre></div>
</div>
</div>
<div class="section" id="is-not-array">
<span id="reference-dsl-is-not-array"></span><h3>is_not_array<a class="headerlink" href="#is-not-array" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_not_array</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) True if argument is not an array.</span>
</pre></div>
</div>
</div>
<div class="section" id="is-not-empty">
<span id="reference-dsl-is-not-empty"></span><h3>is_not_empty<a class="headerlink" href="#is-not-empty" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_not_empty</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) False if field is present in input with empty value, true otherwise</span>
</pre></div>
</div>
</div>
<div class="section" id="is-not-map">
<span id="reference-dsl-is-not-map"></span><h3>is_not_map<a class="headerlink" href="#is-not-map" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_not_map</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) True if argument is not a map.</span>
</pre></div>
</div>
</div>
<div class="section" id="is-not-null">
<span id="reference-dsl-is-not-null"></span><h3>is_not_null<a class="headerlink" href="#is-not-null" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_not_null</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) False if argument is null (empty or absent), true otherwise.</span>
</pre></div>
</div>
</div>
<div class="section" id="is-null">
<span id="reference-dsl-is-null"></span><h3>is_null<a class="headerlink" href="#is-null" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_null</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) True if argument is null (empty or absent), false otherwise.</span>
</pre></div>
</div>
</div>
<div class="section" id="is-numeric">
<span id="reference-dsl-is-numeric"></span><h3>is_numeric<a class="headerlink" href="#is-numeric" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_numeric</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) True if field is present with value inferred to be int or float</span>
</pre></div>
</div>
</div>
<div class="section" id="is-present">
<span id="reference-dsl-is-present"></span><h3>is_present<a class="headerlink" href="#is-present" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_present</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) True if field is present in input, false otherwise.</span>
</pre></div>
</div>
</div>
<div class="section" id="is-string">
<span id="reference-dsl-is-string"></span><h3>is_string<a class="headerlink" href="#is-string" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">is_string</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) True if field is present with string (including empty-string) value</span>
</pre></div>
</div>
</div>
<div class="section" id="joink">
<span id="reference-dsl-joink"></span><h3>joink<a class="headerlink" href="#joink" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">joink</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">conversion</span> <span class="c1">#args=2) Makes string from map/array keys. Examples:</span>
<span class="n">joink</span><span class="p">({</span><span class="s2">&quot;a&quot;</span><span class="p">:</span><span class="mi">3</span><span class="p">,</span><span class="s2">&quot;b&quot;</span><span class="p">:</span><span class="mi">4</span><span class="p">,</span><span class="s2">&quot;c&quot;</span><span class="p">:</span><span class="mi">5</span><span class="p">},</span> <span class="s2">&quot;,&quot;</span><span class="p">)</span> <span class="o">=</span> <span class="s2">&quot;a,b,c&quot;</span>
<span class="n">joink</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">],</span> <span class="s2">&quot;,&quot;</span><span class="p">)</span> <span class="o">=</span> <span class="s2">&quot;1,2,3&quot;</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="joinkv">
<span id="reference-dsl-joinkv"></span><h3>joinkv<a class="headerlink" href="#joinkv" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">joinkv</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">conversion</span> <span class="c1">#args=3) Makes string from map/array key-value pairs. Examples:</span>
<span class="n">joinkv</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">],</span> <span class="s2">&quot;=&quot;</span><span class="p">,</span> <span class="s2">&quot;,&quot;</span><span class="p">)</span> <span class="o">=</span> <span class="s2">&quot;1=3,2=4,3=5&quot;</span>
<span class="n">joinkv</span><span class="p">({</span><span class="s2">&quot;a&quot;</span><span class="p">:</span><span class="mi">3</span><span class="p">,</span><span class="s2">&quot;b&quot;</span><span class="p">:</span><span class="mi">4</span><span class="p">,</span><span class="s2">&quot;c&quot;</span><span class="p">:</span><span class="mi">5</span><span class="p">},</span> <span class="s2">&quot;=&quot;</span><span class="p">,</span> <span class="s2">&quot;,&quot;</span><span class="p">)</span> <span class="o">=</span> <span class="s2">&quot;a=3,b=4,c=5&quot;</span>
</pre></div>
</div>
</div>
<div class="section" id="joinv">
<span id="reference-dsl-joinv"></span><h3>joinv<a class="headerlink" href="#joinv" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">joinv</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">conversion</span> <span class="c1">#args=2) Makes string from map/array values.</span>
<span class="n">joinv</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">],</span> <span class="s2">&quot;,&quot;</span><span class="p">)</span> <span class="o">=</span> <span class="s2">&quot;3,4,5&quot;</span>
<span class="n">joinv</span><span class="p">({</span><span class="s2">&quot;a&quot;</span><span class="p">:</span><span class="mi">3</span><span class="p">,</span><span class="s2">&quot;b&quot;</span><span class="p">:</span><span class="mi">4</span><span class="p">,</span><span class="s2">&quot;c&quot;</span><span class="p">:</span><span class="mi">5</span><span class="p">},</span> <span class="s2">&quot;,&quot;</span><span class="p">)</span> <span class="o">=</span> <span class="s2">&quot;3,4,5&quot;</span>
</pre></div>
</div>
</div>
<div class="section" id="json-parse">
<span id="reference-dsl-json-parse"></span><h3>json_parse<a class="headerlink" href="#json-parse" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">json_parse</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">maps</span><span class="o">/</span><span class="n">arrays</span> <span class="c1">#args=1) Converts value from JSON-formatted string.</span>
</pre></div>
</div>
</div>
<div class="section" id="json-stringify">
<span id="reference-dsl-json-stringify"></span><h3>json_stringify<a class="headerlink" href="#json-stringify" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">json_stringify</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">maps</span><span class="o">/</span><span class="n">arrays</span> <span class="c1">#args=1,2) Converts value to JSON-formatted string. Default output is single-line.</span>
<span class="n">With</span> <span class="n">optional</span> <span class="n">second</span> <span class="n">boolean</span> <span class="n">argument</span> <span class="nb">set</span> <span class="n">to</span> <span class="n">true</span><span class="p">,</span> <span class="n">produces</span> <span class="n">multiline</span> <span class="n">output</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="leafcount">
<span id="reference-dsl-leafcount"></span><h3>leafcount<a class="headerlink" href="#leafcount" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">leafcount</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">maps</span><span class="o">/</span><span class="n">arrays</span> <span class="c1">#args=1) Counts total number of terminal values in map/array. For single-level</span>
<span class="nb">map</span><span class="o">/</span><span class="n">array</span><span class="p">,</span> <span class="n">same</span> <span class="k">as</span> <span class="n">length</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="length">
<span id="reference-dsl-length"></span><h3>length<a class="headerlink" href="#length" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">length</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">maps</span><span class="o">/</span><span class="n">arrays</span> <span class="c1">#args=1) Counts number of top-level entries in array/map. Scalars have length 1.</span>
</pre></div>
</div>
</div>
<div class="section" id="log">
<span id="reference-dsl-log"></span><h3>log<a class="headerlink" href="#log" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">log</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Natural (base-e) logarithm.</span>
</pre></div>
</div>
</div>
<div class="section" id="log10">
<span id="reference-dsl-log10"></span><h3>log10<a class="headerlink" href="#log10" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">log10</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Base-10 logarithm.</span>
</pre></div>
</div>
</div>
<div class="section" id="log1p">
<span id="reference-dsl-log1p"></span><h3>log1p<a class="headerlink" href="#log1p" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">log1p</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) log(1-x).</span>
</pre></div>
</div>
</div>
<div class="section" id="logifit">
<span id="reference-dsl-logifit"></span><h3>logifit<a class="headerlink" href="#logifit" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>logifit (class=math #args=3) Given m and b from logistic regression, compute fit:
$yhat=logifit($x,$m,$b).
</pre></div>
</div>
</div>
<div class="section" id="lstrip">
<span id="reference-dsl-lstrip"></span><h3>lstrip<a class="headerlink" href="#lstrip" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">lstrip</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=1) Strip leading whitespace from string.</span>
</pre></div>
</div>
</div>
<div class="section" id="madd">
<span id="reference-dsl-madd"></span><h3>madd<a class="headerlink" href="#madd" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">madd</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=3) a + b mod m (integers)</span>
</pre></div>
</div>
</div>
<div class="section" id="mapdiff">
<span id="reference-dsl-mapdiff"></span><h3>mapdiff<a class="headerlink" href="#mapdiff" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mapdiff</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">maps</span><span class="o">/</span><span class="n">arrays</span> <span class="c1">#args=variadic) With 0 args, returns empty map. With 1 arg, returns copy of arg.</span>
<span class="n">With</span> <span class="mi">2</span> <span class="ow">or</span> <span class="n">more</span><span class="p">,</span> <span class="n">returns</span> <span class="n">copy</span> <span class="n">of</span> <span class="n">arg</span> <span class="mi">1</span> <span class="k">with</span> <span class="nb">all</span> <span class="n">keys</span> <span class="kn">from</span> <span class="nn">any</span> <span class="n">of</span> <span class="n">remaining</span>
<span class="n">argument</span> <span class="n">maps</span> <span class="n">removed</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="mapexcept">
<span id="reference-dsl-mapexcept"></span><h3>mapexcept<a class="headerlink" href="#mapexcept" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mapexcept</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">maps</span><span class="o">/</span><span class="n">arrays</span> <span class="c1">#args=variadic) Returns a map with keys from remaining arguments, if any, unset.</span>
<span class="n">Remaining</span> <span class="n">arguments</span> <span class="n">can</span> <span class="n">be</span> <span class="n">strings</span> <span class="ow">or</span> <span class="n">arrays</span> <span class="n">of</span> <span class="n">string</span><span class="o">.</span>
<span class="n">E</span><span class="o">.</span><span class="n">g</span><span class="o">.</span> <span class="s1">&#39;mapexcept({1:2,3:4,5:6}, 1, 5, 7)&#39;</span> <span class="ow">is</span> <span class="s1">&#39;</span><span class="si">{3:4}</span><span class="s1">&#39;</span>
<span class="ow">and</span> <span class="s1">&#39;mapexcept({1:2,3:4,5:6}, [1, 5, 7])&#39;</span> <span class="ow">is</span> <span class="s1">&#39;</span><span class="si">{3:4}</span><span class="s1">&#39;</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="mapselect">
<span id="reference-dsl-mapselect"></span><h3>mapselect<a class="headerlink" href="#mapselect" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mapselect</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">maps</span><span class="o">/</span><span class="n">arrays</span> <span class="c1">#args=variadic) Returns a map with only keys from remaining arguments set.</span>
<span class="n">Remaining</span> <span class="n">arguments</span> <span class="n">can</span> <span class="n">be</span> <span class="n">strings</span> <span class="ow">or</span> <span class="n">arrays</span> <span class="n">of</span> <span class="n">string</span><span class="o">.</span>
<span class="n">E</span><span class="o">.</span><span class="n">g</span><span class="o">.</span> <span class="s1">&#39;mapselect({1:2,3:4,5:6}, 1, 5, 7)&#39;</span> <span class="ow">is</span> <span class="s1">&#39;{1:2,5:6}&#39;</span>
<span class="ow">and</span> <span class="s1">&#39;mapselect({1:2,3:4,5:6}, [1, 5, 7])&#39;</span> <span class="ow">is</span> <span class="s1">&#39;{1:2,5:6}&#39;</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="mapsum">
<span id="reference-dsl-mapsum"></span><h3>mapsum<a class="headerlink" href="#mapsum" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mapsum</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">maps</span><span class="o">/</span><span class="n">arrays</span> <span class="c1">#args=variadic) With 0 args, returns empty map. With &gt;= 1 arg, returns a map with</span>
<span class="n">key</span><span class="o">-</span><span class="n">value</span> <span class="n">pairs</span> <span class="kn">from</span> <span class="nn">all</span> <span class="n">arguments</span><span class="o">.</span> <span class="n">Rightmost</span> <span class="n">collisions</span> <span class="n">win</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">g</span><span class="o">.</span>
<span class="s1">&#39;mapsum({1:2,3:4},</span><span class="si">{1:5}</span><span class="s1">)&#39;</span> <span class="ow">is</span> <span class="s1">&#39;{1:5,3:4}&#39;</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="max">
<span id="reference-dsl-max"></span><h3>max<a class="headerlink" href="#max" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nb">max</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=variadic) Max of n numbers; null loses.</span>
</pre></div>
</div>
</div>
<div class="section" id="md5">
<span id="reference-dsl-md5"></span><h3>md5<a class="headerlink" href="#md5" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">md5</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">hashing</span> <span class="c1">#args=1) MD5 hash.</span>
</pre></div>
</div>
</div>
<div class="section" id="mexp">
<span id="reference-dsl-mexp"></span><h3>mexp<a class="headerlink" href="#mexp" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mexp</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=3) a ** b mod m (integers)</span>
</pre></div>
</div>
</div>
<div class="section" id="min">
<span id="reference-dsl-min"></span><h3>min<a class="headerlink" href="#min" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nb">min</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=variadic) Min of n numbers; null loses.</span>
</pre></div>
</div>
</div>
<div class="section" id="mmul">
<span id="reference-dsl-mmul"></span><h3>mmul<a class="headerlink" href="#mmul" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mmul</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=3) a * b mod m (integers)</span>
</pre></div>
</div>
</div>
<div class="section" id="msub">
<span id="reference-dsl-msub"></span><h3>msub<a class="headerlink" href="#msub" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">msub</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=3) a - b mod m (integers)</span>
</pre></div>
</div>
</div>
<div class="section" id="os">
<span id="reference-dsl-os"></span><h3>os<a class="headerlink" href="#os" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">os</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">system</span> <span class="c1">#args=0) Returns the operating-system name as a string.</span>
</pre></div>
</div>
</div>
<div class="section" id="pow">
<span id="reference-dsl-pow"></span><h3>pow<a class="headerlink" href="#pow" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nb">pow</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">arithmetic</span> <span class="c1">#args=2) Exponentiation. Same as **, but as a function.</span>
</pre></div>
</div>
</div>
<div class="section" id="qnorm">
<span id="reference-dsl-qnorm"></span><h3>qnorm<a class="headerlink" href="#qnorm" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">qnorm</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Normal cumulative distribution function.</span>
</pre></div>
</div>
</div>
<div class="section" id="regextract">
<span id="reference-dsl-regextract"></span><h3>regextract<a class="headerlink" href="#regextract" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">regextract</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=2) Example: &#39;$name=regextract($name, &quot;[A-Z]{3}[0-9]{2}&quot;)&#39;</span>
</pre></div>
</div>
</div>
<div class="section" id="regextract-or-else">
<span id="reference-dsl-regextract-or-else"></span><h3>regextract_or_else<a class="headerlink" href="#regextract-or-else" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">regextract_or_else</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=3) Example: &#39;$name=regextract_or_else($name, &quot;[A-Z]{3}[0-9]{2}&quot;, &quot;default&quot;)&#39;</span>
</pre></div>
</div>
</div>
<div class="section" id="round">
<span id="reference-dsl-round"></span><h3>round<a class="headerlink" href="#round" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nb">round</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Round to nearest integer.</span>
</pre></div>
</div>
</div>
<div class="section" id="roundm">
<span id="reference-dsl-roundm"></span><h3>roundm<a class="headerlink" href="#roundm" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>roundm (class=math #args=2) Round to nearest multiple of m: roundm($x,$m) is
the same as round($x/$m)*$m.
</pre></div>
</div>
</div>
<div class="section" id="rstrip">
<span id="reference-dsl-rstrip"></span><h3>rstrip<a class="headerlink" href="#rstrip" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">rstrip</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=1) Strip trailing whitespace from string.</span>
</pre></div>
</div>
</div>
<div class="section" id="sec2dhms">
<span id="reference-dsl-sec2dhms"></span><h3>sec2dhms<a class="headerlink" href="#sec2dhms" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sec2dhms</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">time</span> <span class="c1">#args=1) Formats integer seconds as in sec2dhms(500000) = &quot;5d18h53m20s&quot;</span>
</pre></div>
</div>
</div>
<div class="section" id="sec2gmt">
<span id="reference-dsl-sec2gmt"></span><h3>sec2gmt<a class="headerlink" href="#sec2gmt" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sec2gmt</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">time</span> <span class="c1">#args=1,2) Formats seconds since epoch (integer part)</span>
<span class="k">as</span> <span class="n">GMT</span> <span class="n">timestamp</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">g</span><span class="o">.</span> <span class="n">sec2gmt</span><span class="p">(</span><span class="mf">1440768801.7</span><span class="p">)</span> <span class="o">=</span> <span class="s2">&quot;2015-08-28T13:33:21Z&quot;</span><span class="o">.</span>
<span class="n">Leaves</span> <span class="n">non</span><span class="o">-</span><span class="n">numbers</span> <span class="k">as</span><span class="o">-</span><span class="ow">is</span><span class="o">.</span> <span class="n">With</span> <span class="n">second</span> <span class="n">integer</span> <span class="n">argument</span> <span class="n">n</span><span class="p">,</span> <span class="n">includes</span> <span class="n">n</span> <span class="n">decimal</span> <span class="n">places</span>
<span class="k">for</span> <span class="n">the</span> <span class="n">seconds</span> <span class="n">part</span>
</pre></div>
</div>
</div>
<div class="section" id="sec2gmtdate">
<span id="reference-dsl-sec2gmtdate"></span><h3>sec2gmtdate<a class="headerlink" href="#sec2gmtdate" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sec2gmtdate</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">time</span> <span class="c1">#args=1) Formats seconds since epoch (integer part)</span>
<span class="k">as</span> <span class="n">GMT</span> <span class="n">timestamp</span> <span class="k">with</span> <span class="n">year</span><span class="o">-</span><span class="n">month</span><span class="o">-</span><span class="n">date</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">g</span><span class="o">.</span> <span class="n">sec2gmtdate</span><span class="p">(</span><span class="mf">1440768801.7</span><span class="p">)</span> <span class="o">=</span> <span class="s2">&quot;2015-08-28&quot;</span><span class="o">.</span>
<span class="n">Leaves</span> <span class="n">non</span><span class="o">-</span><span class="n">numbers</span> <span class="k">as</span><span class="o">-</span><span class="ow">is</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="sec2hms">
<span id="reference-dsl-sec2hms"></span><h3>sec2hms<a class="headerlink" href="#sec2hms" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sec2hms</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">time</span> <span class="c1">#args=1) Formats integer seconds as in sec2hms(5000) = &quot;01:23:20&quot;</span>
</pre></div>
</div>
</div>
<div class="section" id="sgn">
<span id="reference-dsl-sgn"></span><h3>sgn<a class="headerlink" href="#sgn" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sgn</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) +1, 0, -1 for positive, zero, negative input respectively.</span>
</pre></div>
</div>
</div>
<div class="section" id="sha1">
<span id="reference-dsl-sha1"></span><h3>sha1<a class="headerlink" href="#sha1" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sha1</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">hashing</span> <span class="c1">#args=1) SHA1 hash.</span>
</pre></div>
</div>
</div>
<div class="section" id="sha256">
<span id="reference-dsl-sha256"></span><h3>sha256<a class="headerlink" href="#sha256" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sha256</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">hashing</span> <span class="c1">#args=1) SHA256 hash.</span>
</pre></div>
</div>
</div>
<div class="section" id="sha512">
<span id="reference-dsl-sha512"></span><h3>sha512<a class="headerlink" href="#sha512" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sha512</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">hashing</span> <span class="c1">#args=1) SHA512 hash.</span>
</pre></div>
</div>
</div>
<div class="section" id="sin">
<span id="reference-dsl-sin"></span><h3>sin<a class="headerlink" href="#sin" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sin</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Trigonometric sine.</span>
</pre></div>
</div>
</div>
<div class="section" id="sinh">
<span id="reference-dsl-sinh"></span><h3>sinh<a class="headerlink" href="#sinh" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sinh</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Hyperbolic sine.</span>
</pre></div>
</div>
</div>
<div class="section" id="splita">
<span id="reference-dsl-splita"></span><h3>splita<a class="headerlink" href="#splita" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">splita</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">conversion</span> <span class="c1">#args=2) Splits string into array with type inference. Example:</span>
<span class="n">splita</span><span class="p">(</span><span class="s2">&quot;3,4,5&quot;</span><span class="p">,</span> <span class="s2">&quot;,&quot;</span><span class="p">)</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">]</span>
</pre></div>
</div>
</div>
<div class="section" id="splitax">
<span id="reference-dsl-splitax"></span><h3>splitax<a class="headerlink" href="#splitax" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">splitax</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">conversion</span> <span class="c1">#args=2) Splits string into array without type inference. Example:</span>
<span class="n">splita</span><span class="p">(</span><span class="s2">&quot;3,4,5&quot;</span><span class="p">,</span> <span class="s2">&quot;,&quot;</span><span class="p">)</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;3&quot;</span><span class="p">,</span><span class="s2">&quot;4&quot;</span><span class="p">,</span><span class="s2">&quot;5&quot;</span><span class="p">]</span>
</pre></div>
</div>
</div>
<div class="section" id="splitkv">
<span id="reference-dsl-splitkv"></span><h3>splitkv<a class="headerlink" href="#splitkv" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">splitkv</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">conversion</span> <span class="c1">#args=3) Splits string by separators into map with type inference. Example:</span>
<span class="n">splitkv</span><span class="p">(</span><span class="s2">&quot;a=3,b=4,c=5&quot;</span><span class="p">,</span> <span class="s2">&quot;=&quot;</span><span class="p">,</span> <span class="s2">&quot;,&quot;</span><span class="p">)</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;a&quot;</span><span class="p">:</span><span class="mi">3</span><span class="p">,</span><span class="s2">&quot;b&quot;</span><span class="p">:</span><span class="mi">4</span><span class="p">,</span><span class="s2">&quot;c&quot;</span><span class="p">:</span><span class="mi">5</span><span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="splitkvx">
<span id="reference-dsl-splitkvx"></span><h3>splitkvx<a class="headerlink" href="#splitkvx" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">splitkvx</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">conversion</span> <span class="c1">#args=3) Splits string by separators into map without type inference (keys and</span>
<span class="n">values</span> <span class="n">are</span> <span class="n">strings</span><span class="p">)</span><span class="o">.</span> <span class="n">Example</span><span class="p">:</span>
<span class="n">splitkvx</span><span class="p">(</span><span class="s2">&quot;a=3,b=4,c=5&quot;</span><span class="p">,</span> <span class="s2">&quot;=&quot;</span><span class="p">,</span> <span class="s2">&quot;,&quot;</span><span class="p">)</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;a&quot;</span><span class="p">:</span><span class="s2">&quot;3&quot;</span><span class="p">,</span><span class="s2">&quot;b&quot;</span><span class="p">:</span><span class="s2">&quot;4&quot;</span><span class="p">,</span><span class="s2">&quot;c&quot;</span><span class="p">:</span><span class="s2">&quot;5&quot;</span><span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="splitnv">
<span id="reference-dsl-splitnv"></span><h3>splitnv<a class="headerlink" href="#splitnv" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">splitnv</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">conversion</span> <span class="c1">#args=2) Splits string by separator into integer-indexed map with type inference. Example:</span>
<span class="n">splitnv</span><span class="p">(</span><span class="s2">&quot;a,b,c&quot;</span><span class="p">,</span> <span class="s2">&quot;,&quot;</span><span class="p">)</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;1&quot;</span><span class="p">:</span><span class="s2">&quot;a&quot;</span><span class="p">,</span><span class="s2">&quot;2&quot;</span><span class="p">:</span><span class="s2">&quot;b&quot;</span><span class="p">,</span><span class="s2">&quot;3&quot;</span><span class="p">:</span><span class="s2">&quot;c&quot;</span><span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="splitnvx">
<span id="reference-dsl-splitnvx"></span><h3>splitnvx<a class="headerlink" href="#splitnvx" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">splitnvx</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">conversion</span> <span class="c1">#args=2) Splits string by separator into integer-indexed map without type</span>
<span class="n">inference</span> <span class="p">(</span><span class="n">values</span> <span class="n">are</span> <span class="n">strings</span><span class="p">)</span><span class="o">.</span> <span class="n">Example</span><span class="p">:</span>
<span class="n">splitnvx</span><span class="p">(</span><span class="s2">&quot;3,4,5&quot;</span><span class="p">,</span> <span class="s2">&quot;,&quot;</span><span class="p">)</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;1&quot;</span><span class="p">:</span><span class="s2">&quot;3&quot;</span><span class="p">,</span><span class="s2">&quot;2&quot;</span><span class="p">:</span><span class="s2">&quot;4&quot;</span><span class="p">,</span><span class="s2">&quot;3&quot;</span><span class="p">:</span><span class="s2">&quot;5&quot;</span><span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="sqrt">
<span id="reference-dsl-sqrt"></span><h3>sqrt<a class="headerlink" href="#sqrt" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sqrt</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Square root.</span>
</pre></div>
</div>
</div>
<div class="section" id="ssub">
<span id="reference-dsl-ssub"></span><h3>ssub<a class="headerlink" href="#ssub" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ssub</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=3) Like sub but does no regexing. No characters are special.</span>
</pre></div>
</div>
</div>
<div class="section" id="strftime">
<span id="reference-dsl-strftime"></span><h3>strftime<a class="headerlink" href="#strftime" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">strftime</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">time</span> <span class="c1">#args=2) Formats seconds since the epoch as timestamp, e.g.</span>
<span class="n">strftime</span><span class="p">(</span><span class="mf">1440768801.7</span><span class="p">,</span><span class="s2">&quot;%Y-%m-</span><span class="si">%d</span><span class="s2">T%H:%M:%SZ&quot;</span><span class="p">)</span> <span class="o">=</span> <span class="s2">&quot;2015-08-28T13:33:21Z&quot;</span><span class="p">,</span> <span class="ow">and</span>
<span class="n">strftime</span><span class="p">(</span><span class="mf">1440768801.7</span><span class="p">,</span><span class="s2">&quot;%Y-%m-</span><span class="si">%d</span><span class="s2">T%H:%M:%3SZ&quot;</span><span class="p">)</span> <span class="o">=</span> <span class="s2">&quot;2015-08-28T13:33:21.700Z&quot;</span><span class="o">.</span>
<span class="n">Format</span> <span class="n">strings</span> <span class="n">are</span> <span class="k">as</span> <span class="ow">in</span> <span class="n">the</span> <span class="n">C</span> <span class="n">library</span> <span class="p">(</span><span class="n">please</span> <span class="n">see</span> <span class="s2">&quot;man strftime&quot;</span> <span class="n">on</span> <span class="n">your</span> <span class="n">system</span><span class="p">),</span>
<span class="k">with</span> <span class="n">the</span> <span class="n">Miller</span><span class="o">-</span><span class="n">specific</span> <span class="n">addition</span> <span class="n">of</span> <span class="s2">&quot;%1S&quot;</span> <span class="n">through</span> <span class="s2">&quot;%9S&quot;</span> <span class="n">which</span> <span class="nb">format</span> <span class="n">the</span> <span class="n">seconds</span>
<span class="k">with</span> <span class="mi">1</span> <span class="n">through</span> <span class="mi">9</span> <span class="n">decimal</span> <span class="n">places</span><span class="p">,</span> <span class="n">respectively</span><span class="o">.</span> <span class="p">(</span><span class="s2">&quot;%S&quot;</span> <span class="n">uses</span> <span class="n">no</span> <span class="n">decimal</span> <span class="n">places</span><span class="o">.</span><span class="p">)</span>
<span class="n">See</span> <span class="n">also</span> <span class="n">strftime_local</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="string">
<span id="reference-dsl-string"></span><h3>string<a class="headerlink" href="#string" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">string</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">conversion</span> <span class="c1">#args=1) Convert int/float/bool/string/array/map to string.</span>
</pre></div>
</div>
</div>
<div class="section" id="strip">
<span id="reference-dsl-strip"></span><h3>strip<a class="headerlink" href="#strip" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">strip</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=1) Strip leading and trailing whitespace from string.</span>
</pre></div>
</div>
</div>
<div class="section" id="strlen">
<span id="reference-dsl-strlen"></span><h3>strlen<a class="headerlink" href="#strlen" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">strlen</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=1) String length.</span>
</pre></div>
</div>
</div>
<div class="section" id="strptime">
<span id="reference-dsl-strptime"></span><h3>strptime<a class="headerlink" href="#strptime" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">strptime</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">time</span> <span class="c1">#args=2) strptime: Parses timestamp as floating-point seconds since the epoch,</span>
<span class="n">e</span><span class="o">.</span><span class="n">g</span><span class="o">.</span> <span class="n">strptime</span><span class="p">(</span><span class="s2">&quot;2015-08-28T13:33:21Z&quot;</span><span class="p">,</span><span class="s2">&quot;%Y-%m-</span><span class="si">%d</span><span class="s2">T%H:%M:%SZ&quot;</span><span class="p">)</span> <span class="o">=</span> <span class="mf">1440768801.000000</span><span class="p">,</span>
<span class="ow">and</span> <span class="n">strptime</span><span class="p">(</span><span class="s2">&quot;2015-08-28T13:33:21.345Z&quot;</span><span class="p">,</span><span class="s2">&quot;%Y-%m-</span><span class="si">%d</span><span class="s2">T%H:%M:%SZ&quot;</span><span class="p">)</span> <span class="o">=</span> <span class="mf">1440768801.345000</span><span class="o">.</span>
<span class="n">See</span> <span class="n">also</span> <span class="n">strptime_local</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="sub">
<span id="reference-dsl-sub"></span><h3>sub<a class="headerlink" href="#sub" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sub</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=3) Example: &#39;$name=sub($name, &quot;old&quot;, &quot;new&quot;)&#39; (replace once).</span>
</pre></div>
</div>
</div>
<div class="section" id="substr">
<span id="reference-dsl-substr"></span><h3>substr<a class="headerlink" href="#substr" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">substr</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=3) substr is an alias for substr0. See also substr1. Miller is generally 1-up</span>
<span class="k">with</span> <span class="nb">all</span> <span class="n">array</span> <span class="n">indices</span><span class="p">,</span> <span class="n">but</span><span class="p">,</span> <span class="n">this</span> <span class="ow">is</span> <span class="n">a</span> <span class="n">backward</span><span class="o">-</span><span class="n">compatibility</span> <span class="n">issue</span> <span class="k">with</span> <span class="n">Miller</span> <span class="mi">5</span> <span class="ow">and</span> <span class="n">below</span><span class="o">.</span>
<span class="n">Arrays</span> <span class="n">are</span> <span class="n">new</span> <span class="ow">in</span> <span class="n">Miller</span> <span class="mi">6</span><span class="p">;</span> <span class="n">the</span> <span class="n">substr</span> <span class="n">function</span> <span class="ow">is</span> <span class="n">older</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="substr0">
<span id="reference-dsl-substr0"></span><h3>substr0<a class="headerlink" href="#substr0" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">substr0</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=3) substr0(s,m,n) gives substring of s from 0-up position m to n</span>
<span class="n">inclusive</span><span class="o">.</span> <span class="n">Negative</span> <span class="n">indices</span> <span class="o">-</span><span class="nb">len</span> <span class="o">..</span> <span class="o">-</span><span class="mi">1</span> <span class="n">alias</span> <span class="n">to</span> <span class="mi">0</span> <span class="o">..</span> <span class="nb">len</span><span class="o">-</span><span class="mf">1.</span>
</pre></div>
</div>
</div>
<div class="section" id="substr1">
<span id="reference-dsl-substr1"></span><h3>substr1<a class="headerlink" href="#substr1" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">substr1</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=3) substr1(s,m,n) gives substring of s from 1-up position m to n</span>
<span class="n">inclusive</span><span class="o">.</span> <span class="n">Negative</span> <span class="n">indices</span> <span class="o">-</span><span class="nb">len</span> <span class="o">..</span> <span class="o">-</span><span class="mi">1</span> <span class="n">alias</span> <span class="n">to</span> <span class="mi">1</span> <span class="o">..</span> <span class="nb">len</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="system">
<span id="reference-dsl-system"></span><h3>system<a class="headerlink" href="#system" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">system</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">system</span> <span class="c1">#args=1) Run command string, yielding its stdout minus final carriage return.</span>
</pre></div>
</div>
</div>
<div class="section" id="systime">
<span id="reference-dsl-systime"></span><h3>systime<a class="headerlink" href="#systime" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">systime</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">time</span> <span class="c1">#args=0) help string will go here</span>
</pre></div>
</div>
</div>
<div class="section" id="systimeint">
<span id="reference-dsl-systimeint"></span><h3>systimeint<a class="headerlink" href="#systimeint" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">systimeint</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">time</span> <span class="c1">#args=0) help string will go here</span>
</pre></div>
</div>
</div>
<div class="section" id="tan">
<span id="reference-dsl-tan"></span><h3>tan<a class="headerlink" href="#tan" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">tan</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Trigonometric tangent.</span>
</pre></div>
</div>
</div>
<div class="section" id="tanh">
<span id="reference-dsl-tanh"></span><h3>tanh<a class="headerlink" href="#tanh" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">tanh</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=1) Hyperbolic tangent.</span>
</pre></div>
</div>
</div>
<div class="section" id="tolower">
<span id="reference-dsl-tolower"></span><h3>tolower<a class="headerlink" href="#tolower" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">tolower</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=1) Convert string to lowercase.</span>
</pre></div>
</div>
</div>
<div class="section" id="toupper">
<span id="reference-dsl-toupper"></span><h3>toupper<a class="headerlink" href="#toupper" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">toupper</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=1) Convert string to uppercase.</span>
</pre></div>
</div>
</div>
<div class="section" id="truncate">
<span id="reference-dsl-truncate"></span><h3>truncate<a class="headerlink" href="#truncate" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">truncate</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">string</span> <span class="c1">#args=2) Truncates string first argument to max length of int second argument.</span>
</pre></div>
</div>
</div>
<div class="section" id="typeof">
<span id="reference-dsl-typeof"></span><h3>typeof<a class="headerlink" href="#typeof" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">typeof</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">typing</span> <span class="c1">#args=1) Convert argument to type of argument (e.g. &quot;str&quot;). For debug.</span>
</pre></div>
</div>
</div>
<div class="section" id="unflatten">
<span id="reference-dsl-unflatten"></span><h3>unflatten<a class="headerlink" href="#unflatten" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">unflatten</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">maps</span><span class="o">/</span><span class="n">arrays</span> <span class="c1">#args=2) Reverses flatten. Example:</span>
<span class="n">unflatten</span><span class="p">({</span><span class="s2">&quot;a.b.c&quot;</span> <span class="p">:</span> <span class="mi">4</span><span class="p">},</span> <span class="s2">&quot;.&quot;</span><span class="p">)</span> <span class="ow">is</span> <span class="p">{</span><span class="s2">&quot;a&quot;</span><span class="p">:</span> <span class="s2">&quot;b&quot;</span><span class="p">:</span> <span class="p">{</span> <span class="s2">&quot;c&quot;</span><span class="p">:</span> <span class="mi">4</span> <span class="p">}}}</span><span class="o">.</span>
<span class="n">Useful</span> <span class="k">for</span> <span class="n">nested</span> <span class="n">JSON</span><span class="o">-</span><span class="n">like</span> <span class="n">structures</span> <span class="k">for</span> <span class="n">non</span><span class="o">-</span><span class="n">JSON</span> <span class="n">file</span> <span class="n">formats</span> <span class="n">like</span> <span class="n">CSV</span><span class="o">.</span>
<span class="n">See</span> <span class="n">also</span> <span class="n">arrayify</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="uptime">
<span id="reference-dsl-uptime"></span><h3>uptime<a class="headerlink" href="#uptime" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">uptime</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">time</span> <span class="c1">#args=0) help string will go here</span>
</pre></div>
</div>
</div>
<div class="section" id="urand">
<span id="reference-dsl-urand"></span><h3>urand<a class="headerlink" href="#urand" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">urand</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=0) Floating-point numbers uniformly distributed on the unit interval.</span>
<span class="n">Int</span><span class="o">-</span><span class="n">valued</span> <span class="n">example</span><span class="p">:</span> <span class="s1">&#39;$n=floor(20+urand()*11)&#39;</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="urand32">
<span id="reference-dsl-urand32"></span><h3>urand32<a class="headerlink" href="#urand32" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">urand32</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=0) Integer uniformly distributed 0 and 2**32-1 inclusive.</span>
</pre></div>
</div>
</div>
<div class="section" id="urandint">
<span id="reference-dsl-urandint"></span><h3>urandint<a class="headerlink" href="#urandint" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">urandint</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=2) Integer uniformly distributed between inclusive integer endpoints.</span>
</pre></div>
</div>
</div>
<div class="section" id="urandrange">
<span id="reference-dsl-urandrange"></span><h3>urandrange<a class="headerlink" href="#urandrange" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">urandrange</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">math</span> <span class="c1">#args=2) Floating-point numbers uniformly distributed on the interval [a, b).</span>
</pre></div>
</div>
</div>
<div class="section" id="version">
<span id="reference-dsl-version"></span><h3>version<a class="headerlink" href="#version" title="Permalink to this headline"></a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">version</span> <span class="p">(</span><span class="n">class</span><span class="o">=</span><span class="n">system</span> <span class="c1">#args=0) Returns the Miller version as a string.</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="user-defined-functions-and-subroutines">
<h2>User-defined functions and subroutines<a class="headerlink" href="#user-defined-functions-and-subroutines" title="Permalink to this headline"></a></h2>
<p>As of Miller 5.0.0 you can define your own functions, as well as subroutines.</p>
<div class="section" id="user-defined-functions">
<h3>User-defined functions<a class="headerlink" href="#user-defined-functions" title="Permalink to this headline"></a></h3>
<p>Heres the obligatory example of a recursive function to compute the factorial function:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --opprint --from data/small put &#39;
</span><span class="hll"> func f(n) {
</span><span class="hll"> if (is_numeric(n)) {
</span><span class="hll"> if (n &gt; 0) {
</span><span class="hll"> return n * f(n-1);
</span><span class="hll"> } else {
</span><span class="hll"> return 1;
</span><span class="hll"> }
</span><span class="hll"> }
</span><span class="hll"> # implicitly return absent-null if non-numeric
</span><span class="hll"> }
</span><span class="hll"> $ox = f($x + NR);
</span><span class="hll"> $oi = f($i);
</span><span class="hll"> &#39;
</span> a b i x y ox oi
pan pan 1 0.3467901443380824 0.7268028627434533 0.46705354854811026 1
eks pan 2 0.7586799647899636 0.5221511083334797 3.680838410072862 2
wye wye 3 0.20460330576630303 0.33831852551664776 1.7412511955594865 6
eks wye 4 0.38139939387114097 0.13418874328430463 18.588348778962008 24
wye pan 5 0.5732889198020006 0.8636244699032729 211.38730958519247 120
</pre></div>
</div>
<p>Properties of user-defined functions:</p>
<ul class="simple">
<li><p>Function bodies start with <code class="docutils literal notranslate"><span class="pre">func</span></code> and a parameter list, defined outside of <code class="docutils literal notranslate"><span class="pre">begin</span></code>, <code class="docutils literal notranslate"><span class="pre">end</span></code>, or other <code class="docutils literal notranslate"><span class="pre">func</span></code> or <code class="docutils literal notranslate"><span class="pre">subr</span></code> blocks. (I.e. the Miller DSL has no nested functions.)</p></li>
<li><p>A function (uniqified by its name) may not be redefined: either by redefining a user-defined function, or by redefining a built-in function. However, functions and subroutines have separate namespaces: you can define a subroutine <code class="docutils literal notranslate"><span class="pre">log</span></code> which does not clash with the mathematical <code class="docutils literal notranslate"><span class="pre">log</span></code> function.</p></li>
<li><p>Functions may be defined either before or after use (there is an object-binding/linkage step at startup). More specifically, functions may be either recursive or mutually recursive. Functions may not call subroutines.</p></li>
<li><p>Functions may be defined and called either within <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span></code> or <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span></code>.</p></li>
<li><p>Functions have read access to <code class="docutils literal notranslate"><span class="pre">$</span></code>-variables and <code class="docutils literal notranslate"><span class="pre">&#64;</span></code>-variables but may not modify them. See also <a class="reference internal" href="cookbook.html#cookbook-memoization-with-oosvars"><span class="std std-ref">Memoization with out-of-stream variables</span></a> for an example.</p></li>
<li><p>Argument values may be reassigned: they are not read-only.</p></li>
<li><p>When a return value is not implicitly returned, this results in a return value of absent-null. (In the example above, if there were records for which the argument to <code class="docutils literal notranslate"><span class="pre">f</span></code> is non-numeric, the assignments would be skipped.) See also the section on <a class="reference internal" href="reference.html#reference-null-data"><span class="std std-ref">Null data: empty and absent</span></a>.</p></li>
<li><p>See the section on <a class="reference internal" href="#reference-dsl-local-variables"><span class="std std-ref">Local variables</span></a> for information on scope and extent of arguments, as well as for information on the use of local variables within functions.</p></li>
<li><p>See the section on <a class="reference internal" href="#reference-dsl-expressions-from-files"><span class="std std-ref">Expressions from files</span></a> for information on the use of <code class="docutils literal notranslate"><span class="pre">-f</span></code> and <code class="docutils literal notranslate"><span class="pre">-e</span></code> flags.</p></li>
</ul>
</div>
<div class="section" id="user-defined-subroutines">
<h3>User-defined subroutines<a class="headerlink" href="#user-defined-subroutines" title="Permalink to this headline"></a></h3>
<p>Example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --opprint --from data/small put -q &#39;
</span><span class="hll"> begin {
</span><span class="hll"> @call_count = 0;
</span><span class="hll"> }
</span><span class="hll"> subr s(n) {
</span><span class="hll"> @call_count += 1;
</span><span class="hll"> if (is_numeric(n)) {
</span><span class="hll"> if (n &gt; 1) {
</span><span class="hll"> call s(n-1);
</span><span class="hll"> } else {
</span><span class="hll"> print &quot;numcalls=&quot; . @call_count;
</span><span class="hll"> }
</span><span class="hll"> }
</span><span class="hll"> }
</span><span class="hll"> print &quot;NR=&quot; . NR;
</span><span class="hll"> call s(NR);
</span><span class="hll"> &#39;
</span> NR=1
numcalls=1
NR=2
numcalls=3
NR=3
numcalls=6
NR=4
numcalls=10
NR=5
numcalls=15
</pre></div>
</div>
<p>Properties of user-defined subroutines:</p>
<ul class="simple">
<li><p>Subroutine bodies start with <code class="docutils literal notranslate"><span class="pre">subr</span></code> and a parameter list, defined outside of <code class="docutils literal notranslate"><span class="pre">begin</span></code>, <code class="docutils literal notranslate"><span class="pre">end</span></code>, or other <code class="docutils literal notranslate"><span class="pre">func</span></code> or <code class="docutils literal notranslate"><span class="pre">subr</span></code> blocks. (I.e. the Miller DSL has no nested subroutines.)</p></li>
<li><p>A subroutine (uniqified by its name) may not be redefined. However, functions and subroutines have separate namespaces: you can define a subroutine <code class="docutils literal notranslate"><span class="pre">log</span></code> which does not clash with the mathematical <code class="docutils literal notranslate"><span class="pre">log</span></code> function.</p></li>
<li><p>Subroutines may be defined either before or after use (there is an object-binding/linkage step at startup). More specifically, subroutines may be either recursive or mutually recursive. Subroutines may call functions.</p></li>
<li><p>Subroutines may be defined and called either within <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span></code> or <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span></code>.</p></li>
<li><p>Subroutines have read/write access to <code class="docutils literal notranslate"><span class="pre">$</span></code>-variables and <code class="docutils literal notranslate"><span class="pre">&#64;</span></code>-variables.</p></li>
<li><p>Argument values may be reassigned: they are not read-only.</p></li>
<li><p>See the section on <a class="reference internal" href="#reference-dsl-local-variables"><span class="std std-ref">Local variables</span></a> for information on scope and extent of arguments, as well as for information on the use of local variables within functions.</p></li>
<li><p>See the section on <a class="reference internal" href="#reference-dsl-expressions-from-files"><span class="std std-ref">Expressions from files</span></a> for information on the use of <code class="docutils literal notranslate"><span class="pre">-f</span></code> and <code class="docutils literal notranslate"><span class="pre">-e</span></code> flags.</p></li>
</ul>
</div>
</div>
<div class="section" id="errors-and-transparency">
<span id="reference-dsl-errors-and-transparency"></span><h2>Errors and transparency<a class="headerlink" href="#errors-and-transparency" title="Permalink to this headline"></a></h2>
<p>As soon as you have a programming language, you start having the problem <em>What is my code doing, and why?</em> This includes getting syntax errors which are always annoying as well as the even more annoying problem of a program which parses without syntax error but doesnt do what you expect.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">syntax</span> <span class="pre">error</span></code> message is cryptic: it says <code class="docutils literal notranslate"><span class="pre">syntax</span> <span class="pre">error</span> <span class="pre">at</span> <span class="pre">``</span> <span class="pre">followed</span> <span class="pre">by</span> <span class="pre">the</span> <span class="pre">next</span> <span class="pre">symbol</span> <span class="pre">it</span> <span class="pre">couldn't</span> <span class="pre">parse.</span> <span class="pre">This</span> <span class="pre">is</span> <span class="pre">good,</span> <span class="pre">but</span> <span class="pre">(as</span> <span class="pre">of</span> <span class="pre">5.0.0)</span> <span class="pre">it</span> <span class="pre">doesn't</span> <span class="pre">say</span> <span class="pre">things</span> <span class="pre">like</span> <span class="pre">``syntax</span> <span class="pre">error</span> <span class="pre">at</span> <span class="pre">line</span> <span class="pre">17,</span> <span class="pre">character</span> <span class="pre">22</span></code>. Here are some common causes of syntax errors:</p>
<ul class="simple">
<li><p>Dont forget <code class="docutils literal notranslate"><span class="pre">;</span></code> at end of line, before another statement on the next line.</p></li>
<li><p>Millers DSL lacks the <code class="docutils literal notranslate"><span class="pre">++</span></code> and <code class="docutils literal notranslate"><span class="pre">--</span></code> operators.</p></li>
<li><p>Curly braces are required for the bodies of <code class="docutils literal notranslate"><span class="pre">if</span></code>/<code class="docutils literal notranslate"><span class="pre">while</span></code>/<code class="docutils literal notranslate"><span class="pre">for</span></code> blocks, even when the body is a single statement.</p></li>
</ul>
<p>Now for transparency:</p>
<ul class="simple">
<li><p>As in any language, you can do (see <a class="reference internal" href="#reference-dsl-print-statements"><span class="std std-ref">Print statements</span></a>) <code class="docutils literal notranslate"><span class="pre">print</span></code> (or <code class="docutils literal notranslate"><span class="pre">eprint</span></code> to print to stderr). See also <a class="reference internal" href="#reference-dsl-dump-statements"><span class="std std-ref">Dump statements</span></a> and <a class="reference internal" href="#reference-dsl-emit-statements"><span class="std std-ref">Emit statements</span></a>.</p></li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">-v</span></code> option to <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span></code> and <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">filter</span></code> prints abstract syntax trees for your code. While not all details here will be of interest to everyone, certainly this makes questions such as operator precedence completely unambiguous.</p></li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">-T</span></code> option prints a trace of each statement executed.</p></li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">-t</span></code> and <code class="docutils literal notranslate"><span class="pre">-a</span></code> options show low-level details for the parsing process and for stack-variable-index allocation, respectively. These will likely be of interest to people who enjoy compilers, and probably less useful for a more general audience.</p></li>
<li><p>Please see <a class="reference internal" href="#reference-dsl-type-checking"><span class="std std-ref">Type-checking</span></a> for type declarations and type-assertions you can use to make sure expressions and the data flowing them are evaluating as you expect. I made them optional because one of Millers important use-cases is being able to say simple things like <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span> <span class="pre">'$y</span> <span class="pre">=</span> <span class="pre">$x</span> <span class="pre">+</span> <span class="pre">1'</span> <span class="pre">myfile.dat</span></code> with a minimum of punctuational bric-a-brac but for programs over a few lines I generally find that the more type-specification, the better.</p></li>
</ul>
</div>
<div class="section" id="a-note-on-the-complexity-of-miller-s-expression-language">
<h2>A note on the complexity of Millers expression language<a class="headerlink" href="#a-note-on-the-complexity-of-miller-s-expression-language" title="Permalink to this headline"></a></h2>
<p>One of Millers strengths is its brevity: its much quicker and less error-prone to type <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">stats1</span> <span class="pre">-a</span> <span class="pre">sum</span> <span class="pre">-f</span> <span class="pre">x,y</span> <span class="pre">-g</span> <span class="pre">a,b</span></code> than having to track summation variables as in <code class="docutils literal notranslate"><span class="pre">awk</span></code>, or using Millers out-of-stream variables. And the more language features Millers put-DSL has (for-loops, if-statements, nested control structures, user-defined functions, etc.) then the <em>less</em> powerful it begins to seem: because of the other programming-language features it <em>doesnt</em> have (classes, execptions, and so on).</p>
<p>When I was originally prototyping Miller in 2015, the decision I had was whether to hand-code in a low-level language like C or Rust, with my own hand-rolled DSL, or whether to use a higher-level language (like Python or Lua or Nim) and let the <code class="docutils literal notranslate"><span class="pre">put</span></code> statements be handled by the implementation languages own <code class="docutils literal notranslate"><span class="pre">eval</span></code>: the implementation language would take the place of a DSL. Multiple performance experiments showed me I could get better throughput using the former, by a wide margin. So Miller is Go under the hood with a hand-rolled DSL.</p>
<p>I do want to keep focusing on what Miller is good at concise notation, low latency, and high throughput and not add too much in terms of high-level-language features to the DSL. That said, some sort of customizability is a basic thing to want. As of 4.1.0 we have recursive for/while/if structures on about the same complexity level as <code class="docutils literal notranslate"><span class="pre">awk</span></code>; as of 5.0.0 we have user-defined functions and map-valued variables, again on about the same complexity level as <code class="docutils literal notranslate"><span class="pre">awk</span></code> along with optional type-declaration syntax. While Im excited by these powerful language features, I hope to keep new features beyond 5.0.0 focused on Millers sweet spot which is speed plus simplicity.</p>
</div>
</div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">DSL reference</a><ul>
<li><a class="reference internal" href="#overview">Overview</a></li>
<li><a class="reference internal" href="#syntax">Syntax</a><ul>
<li><a class="reference internal" href="#expression-formatting">Expression formatting</a></li>
<li><a class="reference internal" href="#expressions-from-files">Expressions from files</a></li>
<li><a class="reference internal" href="#semicolons-commas-newlines-and-curly-braces">Semicolons, commas, newlines, and curly braces</a></li>
</ul>
</li>
<li><a class="reference internal" href="#variables">Variables</a><ul>
<li><a class="reference internal" href="#built-in-variables">Built-in variables</a></li>
<li><a class="reference internal" href="#field-names">Field names</a></li>
<li><a class="reference internal" href="#positional-field-names">Positional field names</a></li>
<li><a class="reference internal" href="#out-of-stream-variables">Out-of-stream variables</a></li>
<li><a class="reference internal" href="#indexed-out-of-stream-variables">Indexed out-of-stream variables</a></li>
<li><a class="reference internal" href="#local-variables">Local variables</a></li>
<li><a class="reference internal" href="#map-literals">Map literals</a></li>
<li><a class="reference internal" href="#type-checking">Type-checking</a><ul>
<li><a class="reference internal" href="#type-test-and-type-assertion-expressions">Type-test and type-assertion expressions</a></li>
<li><a class="reference internal" href="#type-declarations-for-local-variables-function-parameter-and-function-return-values">Type-declarations for local variables, function parameter, and function return values</a></li>
</ul>
</li>
<li><a class="reference internal" href="#null-data-empty-and-absent">Null data: empty and absent</a></li>
<li><a class="reference internal" href="#aggregate-variable-assignments">Aggregate variable assignments</a></li>
<li><a class="reference internal" href="#keywords-for-filter-and-put">Keywords for filter and put</a></li>
</ul>
</li>
<li><a class="reference internal" href="#operator-precedence">Operator precedence</a></li>
<li><a class="reference internal" href="#operator-and-function-semantics">Operator and function semantics</a></li>
<li><a class="reference internal" href="#control-structures">Control structures</a><ul>
<li><a class="reference internal" href="#pattern-action-blocks">Pattern-action blocks</a></li>
<li><a class="reference internal" href="#if-statements">If-statements</a></li>
<li><a class="reference internal" href="#while-and-do-while-loops">While and do-while loops</a></li>
<li><a class="reference internal" href="#for-loops">For-loops</a><ul>
<li><a class="reference internal" href="#key-only-for-loops">Key-only for-loops</a></li>
<li><a class="reference internal" href="#key-value-for-loops">Key-value for-loops</a></li>
<li><a class="reference internal" href="#c-style-triple-for-loops">C-style triple-for loops</a></li>
</ul>
</li>
<li><a class="reference internal" href="#begin-end-blocks">Begin/end blocks</a></li>
</ul>
</li>
<li><a class="reference internal" href="#output-statements">Output statements</a><ul>
<li><a class="reference internal" href="#print-statements">Print statements</a></li>
<li><a class="reference internal" href="#dump-statements">Dump statements</a></li>
<li><a class="reference internal" href="#tee-statements">Tee statements</a></li>
<li><a class="reference internal" href="#redirected-output-statements">Redirected-output statements</a></li>
<li><a class="reference internal" href="#emit-statements">Emit statements</a></li>
<li><a class="reference internal" href="#multi-emit-statements">Multi-emit statements</a></li>
<li><a class="reference internal" href="#emit-all-statements">Emit-all statements</a></li>
</ul>
</li>
<li><a class="reference internal" href="#unset-statements">Unset statements</a></li>
<li><a class="reference internal" href="#filter-statements">Filter statements</a></li>
<li><a class="reference internal" href="#built-in-functions-for-filter-and-put-summary">Built-in functions for filter and put, summary</a></li>
<li><a class="reference internal" href="#built-in-functions-for-filter-and-put">Built-in functions for filter and put</a><ul>
<li><a class="reference internal" href="#reference-dsl-plus">+</a></li>
<li><a class="reference internal" href="#reference-dsl-minus">-</a></li>
<li><a class="reference internal" href="#reference-dsl-times">*</a></li>
<li><a class="reference internal" href="#id4">/</a></li>
<li><a class="reference internal" href="#id6">//</a></li>
<li><a class="reference internal" href="#reference-dsl-exponentiation">**</a></li>
<li><a class="reference internal" href="#id8">.+</a></li>
<li><a class="reference internal" href="#id10">.-</a></li>
<li><a class="reference internal" href="#id12">.*</a></li>
<li><a class="reference internal" href="#id14">./</a></li>
<li><a class="reference internal" href="#id17">%</a></li>
<li><a class="reference internal" href="#id19">~</a></li>
<li><a class="reference internal" href="#id21">&amp;</a></li>
<li><a class="reference internal" href="#reference-dsl-bitwise-or">|</a></li>
<li><a class="reference internal" href="#id24">^</a></li>
<li><a class="reference internal" href="#id26">&lt;&lt;</a></li>
<li><a class="reference internal" href="#id28">&gt;&gt;</a></li>
<li><a class="reference internal" href="#id31">!</a></li>
<li><a class="reference internal" href="#id33">==</a></li>
<li><a class="reference internal" href="#id34">!=</a></li>
<li><a class="reference internal" href="#id37">&gt;</a></li>
<li><a class="reference internal" href="#id38">&gt;=</a></li>
<li><a class="reference internal" href="#id41">&lt;</a></li>
<li><a class="reference internal" href="#id42">&lt;=</a></li>
<li><a class="reference internal" href="#id44">=~</a></li>
<li><a class="reference internal" href="#id46">!=~</a></li>
<li><a class="reference internal" href="#id49">&amp;&amp;</a></li>
<li><a class="reference internal" href="#id51">||</a></li>
<li><a class="reference internal" href="#id53">^^</a></li>
<li><a class="reference internal" href="#id55">??</a></li>
<li><a class="reference internal" href="#id57">???</a></li>
<li><a class="reference internal" href="#reference-dsl-question-mark-colon">?</a></li>
<li><a class="reference internal" href="#id60">.</a></li>
<li><a class="reference internal" href="#abs">abs</a></li>
<li><a class="reference internal" href="#acos">acos</a></li>
<li><a class="reference internal" href="#acosh">acosh</a></li>
<li><a class="reference internal" href="#append">append</a></li>
<li><a class="reference internal" href="#arrayify">arrayify</a></li>
<li><a class="reference internal" href="#asin">asin</a></li>
<li><a class="reference internal" href="#asinh">asinh</a></li>
<li><a class="reference internal" href="#asserting-absent">asserting_absent</a></li>
<li><a class="reference internal" href="#asserting-array">asserting_array</a></li>
<li><a class="reference internal" href="#asserting-bool">asserting_bool</a></li>
<li><a class="reference internal" href="#asserting-boolean">asserting_boolean</a></li>
<li><a class="reference internal" href="#asserting-empty">asserting_empty</a></li>
<li><a class="reference internal" href="#asserting-empty-map">asserting_empty_map</a></li>
<li><a class="reference internal" href="#asserting-error">asserting_error</a></li>
<li><a class="reference internal" href="#asserting-float">asserting_float</a></li>
<li><a class="reference internal" href="#asserting-int">asserting_int</a></li>
<li><a class="reference internal" href="#asserting-map">asserting_map</a></li>
<li><a class="reference internal" href="#asserting-nonempty-map">asserting_nonempty_map</a></li>
<li><a class="reference internal" href="#asserting-not-array">asserting_not_array</a></li>
<li><a class="reference internal" href="#asserting-not-empty">asserting_not_empty</a></li>
<li><a class="reference internal" href="#asserting-not-map">asserting_not_map</a></li>
<li><a class="reference internal" href="#asserting-not-null">asserting_not_null</a></li>
<li><a class="reference internal" href="#asserting-null">asserting_null</a></li>
<li><a class="reference internal" href="#asserting-numeric">asserting_numeric</a></li>
<li><a class="reference internal" href="#asserting-present">asserting_present</a></li>
<li><a class="reference internal" href="#asserting-string">asserting_string</a></li>
<li><a class="reference internal" href="#atan">atan</a></li>
<li><a class="reference internal" href="#atan2">atan2</a></li>
<li><a class="reference internal" href="#atanh">atanh</a></li>
<li><a class="reference internal" href="#bitcount">bitcount</a></li>
<li><a class="reference internal" href="#boolean">boolean</a></li>
<li><a class="reference internal" href="#capitalize">capitalize</a></li>
<li><a class="reference internal" href="#cbrt">cbrt</a></li>
<li><a class="reference internal" href="#ceil">ceil</a></li>
<li><a class="reference internal" href="#clean-whitespace">clean_whitespace</a></li>
<li><a class="reference internal" href="#collapse-whitespace">collapse_whitespace</a></li>
<li><a class="reference internal" href="#cos">cos</a></li>
<li><a class="reference internal" href="#cosh">cosh</a></li>
<li><a class="reference internal" href="#depth">depth</a></li>
<li><a class="reference internal" href="#dhms2fsec">dhms2fsec</a></li>
<li><a class="reference internal" href="#dhms2sec">dhms2sec</a></li>
<li><a class="reference internal" href="#erf">erf</a></li>
<li><a class="reference internal" href="#erfc">erfc</a></li>
<li><a class="reference internal" href="#exp">exp</a></li>
<li><a class="reference internal" href="#expm1">expm1</a></li>
<li><a class="reference internal" href="#flatten">flatten</a></li>
<li><a class="reference internal" href="#float">float</a></li>
<li><a class="reference internal" href="#floor">floor</a></li>
<li><a class="reference internal" href="#fmtnum">fmtnum</a></li>
<li><a class="reference internal" href="#fsec2dhms">fsec2dhms</a></li>
<li><a class="reference internal" href="#fsec2hms">fsec2hms</a></li>
<li><a class="reference internal" href="#get-keys">get_keys</a></li>
<li><a class="reference internal" href="#get-values">get_values</a></li>
<li><a class="reference internal" href="#gmt2sec">gmt2sec</a></li>
<li><a class="reference internal" href="#gsub">gsub</a></li>
<li><a class="reference internal" href="#haskey">haskey</a></li>
<li><a class="reference internal" href="#hexfmt">hexfmt</a></li>
<li><a class="reference internal" href="#hms2fsec">hms2fsec</a></li>
<li><a class="reference internal" href="#hms2sec">hms2sec</a></li>
<li><a class="reference internal" href="#hostname">hostname</a></li>
<li><a class="reference internal" href="#int">int</a></li>
<li><a class="reference internal" href="#invqnorm">invqnorm</a></li>
<li><a class="reference internal" href="#is-absent">is_absent</a></li>
<li><a class="reference internal" href="#is-array">is_array</a></li>
<li><a class="reference internal" href="#is-bool">is_bool</a></li>
<li><a class="reference internal" href="#is-boolean">is_boolean</a></li>
<li><a class="reference internal" href="#is-empty">is_empty</a></li>
<li><a class="reference internal" href="#is-empty-map">is_empty_map</a></li>
<li><a class="reference internal" href="#is-error">is_error</a></li>
<li><a class="reference internal" href="#is-float">is_float</a></li>
<li><a class="reference internal" href="#is-int">is_int</a></li>
<li><a class="reference internal" href="#is-map">is_map</a></li>
<li><a class="reference internal" href="#is-nonempty-map">is_nonempty_map</a></li>
<li><a class="reference internal" href="#is-not-array">is_not_array</a></li>
<li><a class="reference internal" href="#is-not-empty">is_not_empty</a></li>
<li><a class="reference internal" href="#is-not-map">is_not_map</a></li>
<li><a class="reference internal" href="#is-not-null">is_not_null</a></li>
<li><a class="reference internal" href="#is-null">is_null</a></li>
<li><a class="reference internal" href="#is-numeric">is_numeric</a></li>
<li><a class="reference internal" href="#is-present">is_present</a></li>
<li><a class="reference internal" href="#is-string">is_string</a></li>
<li><a class="reference internal" href="#joink">joink</a></li>
<li><a class="reference internal" href="#joinkv">joinkv</a></li>
<li><a class="reference internal" href="#joinv">joinv</a></li>
<li><a class="reference internal" href="#json-parse">json_parse</a></li>
<li><a class="reference internal" href="#json-stringify">json_stringify</a></li>
<li><a class="reference internal" href="#leafcount">leafcount</a></li>
<li><a class="reference internal" href="#length">length</a></li>
<li><a class="reference internal" href="#log">log</a></li>
<li><a class="reference internal" href="#log10">log10</a></li>
<li><a class="reference internal" href="#log1p">log1p</a></li>
<li><a class="reference internal" href="#logifit">logifit</a></li>
<li><a class="reference internal" href="#lstrip">lstrip</a></li>
<li><a class="reference internal" href="#madd">madd</a></li>
<li><a class="reference internal" href="#mapdiff">mapdiff</a></li>
<li><a class="reference internal" href="#mapexcept">mapexcept</a></li>
<li><a class="reference internal" href="#mapselect">mapselect</a></li>
<li><a class="reference internal" href="#mapsum">mapsum</a></li>
<li><a class="reference internal" href="#max">max</a></li>
<li><a class="reference internal" href="#md5">md5</a></li>
<li><a class="reference internal" href="#mexp">mexp</a></li>
<li><a class="reference internal" href="#min">min</a></li>
<li><a class="reference internal" href="#mmul">mmul</a></li>
<li><a class="reference internal" href="#msub">msub</a></li>
<li><a class="reference internal" href="#os">os</a></li>
<li><a class="reference internal" href="#pow">pow</a></li>
<li><a class="reference internal" href="#qnorm">qnorm</a></li>
<li><a class="reference internal" href="#regextract">regextract</a></li>
<li><a class="reference internal" href="#regextract-or-else">regextract_or_else</a></li>
<li><a class="reference internal" href="#round">round</a></li>
<li><a class="reference internal" href="#roundm">roundm</a></li>
<li><a class="reference internal" href="#rstrip">rstrip</a></li>
<li><a class="reference internal" href="#sec2dhms">sec2dhms</a></li>
<li><a class="reference internal" href="#sec2gmt">sec2gmt</a></li>
<li><a class="reference internal" href="#sec2gmtdate">sec2gmtdate</a></li>
<li><a class="reference internal" href="#sec2hms">sec2hms</a></li>
<li><a class="reference internal" href="#sgn">sgn</a></li>
<li><a class="reference internal" href="#sha1">sha1</a></li>
<li><a class="reference internal" href="#sha256">sha256</a></li>
<li><a class="reference internal" href="#sha512">sha512</a></li>
<li><a class="reference internal" href="#sin">sin</a></li>
<li><a class="reference internal" href="#sinh">sinh</a></li>
<li><a class="reference internal" href="#splita">splita</a></li>
<li><a class="reference internal" href="#splitax">splitax</a></li>
<li><a class="reference internal" href="#splitkv">splitkv</a></li>
<li><a class="reference internal" href="#splitkvx">splitkvx</a></li>
<li><a class="reference internal" href="#splitnv">splitnv</a></li>
<li><a class="reference internal" href="#splitnvx">splitnvx</a></li>
<li><a class="reference internal" href="#sqrt">sqrt</a></li>
<li><a class="reference internal" href="#ssub">ssub</a></li>
<li><a class="reference internal" href="#strftime">strftime</a></li>
<li><a class="reference internal" href="#string">string</a></li>
<li><a class="reference internal" href="#strip">strip</a></li>
<li><a class="reference internal" href="#strlen">strlen</a></li>
<li><a class="reference internal" href="#strptime">strptime</a></li>
<li><a class="reference internal" href="#sub">sub</a></li>
<li><a class="reference internal" href="#substr">substr</a></li>
<li><a class="reference internal" href="#substr0">substr0</a></li>
<li><a class="reference internal" href="#substr1">substr1</a></li>
<li><a class="reference internal" href="#system">system</a></li>
<li><a class="reference internal" href="#systime">systime</a></li>
<li><a class="reference internal" href="#systimeint">systimeint</a></li>
<li><a class="reference internal" href="#tan">tan</a></li>
<li><a class="reference internal" href="#tanh">tanh</a></li>
<li><a class="reference internal" href="#tolower">tolower</a></li>
<li><a class="reference internal" href="#toupper">toupper</a></li>
<li><a class="reference internal" href="#truncate">truncate</a></li>
<li><a class="reference internal" href="#typeof">typeof</a></li>
<li><a class="reference internal" href="#unflatten">unflatten</a></li>
<li><a class="reference internal" href="#uptime">uptime</a></li>
<li><a class="reference internal" href="#urand">urand</a></li>
<li><a class="reference internal" href="#urand32">urand32</a></li>
<li><a class="reference internal" href="#urandint">urandint</a></li>
<li><a class="reference internal" href="#urandrange">urandrange</a></li>
<li><a class="reference internal" href="#version">version</a></li>
</ul>
</li>
<li><a class="reference internal" href="#user-defined-functions-and-subroutines">User-defined functions and subroutines</a><ul>
<li><a class="reference internal" href="#user-defined-functions">User-defined functions</a></li>
<li><a class="reference internal" href="#user-defined-subroutines">User-defined subroutines</a></li>
</ul>
</li>
<li><a class="reference internal" href="#errors-and-transparency">Errors and transparency</a></li>
<li><a class="reference internal" href="#a-note-on-the-complexity-of-miller-s-expression-language">A note on the complexity of Millers expression language</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="reference-verbs.html"
title="previous chapter">Verbs reference</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="manpage.html"
title="next chapter">Manpage</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/reference-dsl-overview.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="manpage.html" title="Manpage"
>next</a> |</li>
<li class="right" >
<a href="reference-verbs.html" title="Verbs reference"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Miller 6.0.0-alpha documentation</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">DSL reference</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2020, John Kerl.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
</div>
</body>
</html>