Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat empty like absent in + - * #1371

Merged
merged 6 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -3634,5 +3634,5 @@ MILLER(1) MILLER(1)



2023-08-26 MILLER(1)
2023-08-27 MILLER(1)
</pre>
2 changes: 1 addition & 1 deletion docs/src/manpage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3613,4 +3613,4 @@ MILLER(1) MILLER(1)



2023-08-26 MILLER(1)
2023-08-27 MILLER(1)
4 changes: 4 additions & 0 deletions docs/src/missings.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a,x,z,w
red,7,,
green,,242,zdatsyg
blue,9,,
5 changes: 5 additions & 0 deletions docs/src/missings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{ "a": "red", "x": 7 },
{ "a": "green", "z": 242, "w": "zdatsyg" },
{ "a": "blue", "x": 9 }
]
68 changes: 58 additions & 10 deletions docs/src/reference-main-null-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ a=1,b=8
x=9,b=10
</pre>

* Functions/operators which have one or more *empty* arguments produce empty output: e.g.
* Most functions/operators which have one or more *empty* arguments produce empty output: e.g.

<pre class="pre-highlight-in-pair">
<b>echo 'x=2,y=3' | mlr put '$a=$x+$y'</b>
Expand All @@ -106,7 +106,7 @@ x=2,y=3,a=5
<b>echo 'x=,y=3' | mlr put '$a=$x+$y'</b>
</pre>
<pre class="pre-non-highlight-in-pair">
x=,y=3,a=
x=,y=3,a=3
</pre>

<pre class="pre-highlight-in-pair">
Expand All @@ -125,6 +125,55 @@ with the exception that the `min` and `max` functions are special: if one argume
x=,y=3,a=3,b=
</pre>

Likewise, empty works like 0 for addition and subtraction, and multiplication:

<pre class="pre-highlight-in-pair">
<b>echo 'x=,y=3' | mlr put '$a = $x + $y; $b = $x - $y; $c = $x * $y'</b>
</pre>
<pre class="pre-non-highlight-in-pair">
x=,y=3,a=3,b=-3,c=3
</pre>

This is intended to follow the arithmetic rule for absent data (explained next). In particular:

* For file formats allowing for heterogeneity in keys, e.g. JSON, you should be able to keep a running sum of some field, say `$x`. If a given record doesn't have `$x`, then `$x` will be absent for that record, and the sum should simply continue.
* For CSV and TSV, which don't allow for hetrogeneity in keys, the _only_ way a value can be missing is to be empty. Here, if a given record doesn't have `$x`, then `$x` will be empty for that record, and the sum should simply continue.

<pre class="pre-highlight-in-pair">
<b>cat missings.json</b>
</pre>
<pre class="pre-non-highlight-in-pair">
[
{ "a": "red", "x": 7 },
{ "a": "green", "z": 242, "w": "zdatsyg" },
{ "a": "blue", "x": 9 }
]
</pre>

<pre class="pre-highlight-in-pair">
<b>mlr --ijson --from missings.json put -q 'begin { @sum = 0 } @sum += $x; end { print @sum }'</b>
</pre>
<pre class="pre-non-highlight-in-pair">
16
</pre>

<pre class="pre-highlight-in-pair">
<b>cat missings.csv</b>
</pre>
<pre class="pre-non-highlight-in-pair">
a,x,z,w
red,7,,
green,,242,zdatsyg
blue,9,,
</pre>

<pre class="pre-highlight-in-pair">
<b>mlr --icsv --from missings.csv put -q 'begin { @sum = 0 } @sum += $x; end { print @sum }'</b>
</pre>
<pre class="pre-non-highlight-in-pair">
16
</pre>

* Functions of *absent* variables (e.g. `mlr put '$y = log10($nonesuch)'`) evaluate to absent, and arithmetic/bitwise/boolean operators with both operands being absent evaluate to absent. Arithmetic operators with one absent operand return the other operand. More specifically, absent values act like zero for addition/subtraction, and one for multiplication: Furthermore, **any expression which evaluates to absent is not stored in the left-hand side of an assignment statement**:

<pre class="pre-highlight-in-pair">
Expand All @@ -145,8 +194,6 @@ x=2,y=3,a=2,b=3

The reasoning is as follows:

* Empty values are explicit in the data so they should explicitly affect accumulations: `mlr put '@sum += $x'` should accumulate numeric `x` values into the sum but an empty `x`, when encountered in the input data stream, should make the sum non-numeric. To work around this you can use the `is_not_null` function as follows: `mlr put 'is_not_null($x) { @sum += $x }'`

* Absent stream-record values should not break accumulations, since Miller by design handles heterogeneous data: the running `@sum` in `mlr put '@sum += $x'` should not be invalidated for records which have no `x`.

* Absent out-of-stream-variable values are precisely what allow you to write `mlr put '@sum += $x'`. Otherwise you would have to write `mlr put 'begin{@sum = 0}; @sum += $x'` -- which is tolerable -- but for `mlr put 'begin{...}; @sum[$a][$b] += $x'` you'd have to pre-initialize `@sum` for all values of `$a` and `$b` in your input data stream, which is intolerable.
Expand Down Expand Up @@ -198,10 +245,11 @@ If you're interested in a formal description of how empty and absent fields part
<b>mlr help type-arithmetic-info</b>
</pre>
<pre class="pre-non-highlight-in-pair">
(+) | 1 2.5 (absent) (error)
------ + ------ ------ ------ ------
1 | 2 3.5 1 (error)
2.5 | 3.5 5 2.5 (error)
(absent) | 1 2.5 (absent) (error)
(error) | (error) (error) (error) (error)
(+) | 1 2.5 (empty) (absent) (error)
------ + ------ ------ ------ ------ ------
1 | 2 3.5 1 1 (error)
2.5 | 3.5 5 2.5 2.5 (error)
(empty) | 1 2.5 (empty) (absent) (error)
(absent) | 1 2.5 (absent) (absent) (error)
(error) | (error) (error) (error) (error) (error)
</pre>
31 changes: 28 additions & 3 deletions docs/src/reference-main-null-data.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ GENMD-RUN-COMMAND
mlr sort -nr a data/sort-null.dat
GENMD-EOF

* Functions/operators which have one or more *empty* arguments produce empty output: e.g.
* Most functions/operators which have one or more *empty* arguments produce empty output: e.g.

GENMD-RUN-COMMAND
echo 'x=2,y=3' | mlr put '$a=$x+$y'
Expand All @@ -54,6 +54,33 @@ GENMD-RUN-COMMAND
echo 'x=,y=3' | mlr put '$a=min($x,$y);$b=max($x,$y)'
GENMD-EOF

Likewise, empty works like 0 for addition and subtraction, and multiplication:

GENMD-RUN-COMMAND
echo 'x=,y=3' | mlr put '$a = $x + $y; $b = $x - $y; $c = $x * $y'
GENMD-EOF

This is intended to follow the arithmetic rule for absent data (explained next). In particular:

* For file formats allowing for heterogeneity in keys, e.g. JSON, you should be able to keep a running sum of some field, say `$x`. If a given record doesn't have `$x`, then `$x` will be absent for that record, and the sum should simply continue.
* For CSV and TSV, which don't allow for hetrogeneity in keys, the _only_ way a value can be missing is to be empty. Here, if a given record doesn't have `$x`, then `$x` will be empty for that record, and the sum should simply continue.

GENMD-RUN-COMMAND
cat missings.json
GENMD-EOF

GENMD-RUN-COMMAND
mlr --ijson --from missings.json put -q 'begin { @sum = 0 } @sum += $x; end { print @sum }'
GENMD-EOF

GENMD-RUN-COMMAND
cat missings.csv
GENMD-EOF

GENMD-RUN-COMMAND
mlr --icsv --from missings.csv put -q 'begin { @sum = 0 } @sum += $x; end { print @sum }'
GENMD-EOF

* Functions of *absent* variables (e.g. `mlr put '$y = log10($nonesuch)'`) evaluate to absent, and arithmetic/bitwise/boolean operators with both operands being absent evaluate to absent. Arithmetic operators with one absent operand return the other operand. More specifically, absent values act like zero for addition/subtraction, and one for multiplication: Furthermore, **any expression which evaluates to absent is not stored in the left-hand side of an assignment statement**:

GENMD-RUN-COMMAND
Expand All @@ -68,8 +95,6 @@ GENMD-EOF

The reasoning is as follows:

* Empty values are explicit in the data so they should explicitly affect accumulations: `mlr put '@sum += $x'` should accumulate numeric `x` values into the sum but an empty `x`, when encountered in the input data stream, should make the sum non-numeric. To work around this you can use the `is_not_null` function as follows: `mlr put 'is_not_null($x) { @sum += $x }'`

* Absent stream-record values should not break accumulations, since Miller by design handles heterogeneous data: the running `@sum` in `mlr put '@sum += $x'` should not be invalidated for records which have no `x`.

* Absent out-of-stream-variable values are precisely what allow you to write `mlr put '@sum += $x'`. Otherwise you would have to write `mlr put 'begin{@sum = 0}; @sum += $x'` -- which is tolerable -- but for `mlr put 'begin{...}; @sum[$a][$b] += $x'` you'd have to pre-initialize `@sum` for all values of `$a` and `$b` in your input data stream, which is intolerable.
Expand Down
4 changes: 4 additions & 0 deletions docs/src/split_circle.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
color,shape,flag,k,index,quantity,rate
red,circle,true,3,16,13.8103,2.9010
yellow,circle,true,8,73,63.9785,4.2370
yellow,circle,true,9,87,63.5058,8.3350
5 changes: 5 additions & 0 deletions docs/src/split_square.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
color,shape,flag,k,index,quantity,rate
red,square,true,2,15,79.2778,0.0130
red,square,false,4,48,77.5542,7.4670
red,square,false,6,64,77.1991,9.5310
purple,square,false,10,91,72.3735,8.2430
4 changes: 4 additions & 0 deletions docs/src/split_triangle.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
color,shape,flag,k,index,quantity,rate
yellow,triangle,true,1,11,43.6498,9.8870
purple,triangle,false,5,51,81.2290,8.5910
purple,triangle,false,7,65,80.1405,5.8240
52 changes: 26 additions & 26 deletions internal/pkg/bifs/arithmetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/*INT */ _1u___,
/*FLOAT */ _1u___,
/*BOOL */ _erro1,
/*VOID */ _void1,
/*VOID */ _zero1,
/*STRING */ _erro1,
/*ARRAY */ _absn1,
/*MAP */ _absn1,
Expand Down Expand Up @@ -43,7 +43,7 @@
/*INT */ uneg_i_i,
/*FLOAT */ uneg_f_f,
/*BOOL */ _erro1,
/*VOID */ _void1,
/*VOID */ _zero1,
/*STRING */ _erro1,
/*ARRAY */ _absn1,
/*MAP */ _absn1,
Expand Down Expand Up @@ -97,11 +97,11 @@
}

var plus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{
// . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT
/*INT */ {plus_n_ii, plus_f_if, _erro, _void, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*FLOAT */ {plus_f_fi, plus_f_ff, _erro, _void, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
// . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT
/*INT */ {plus_n_ii, plus_f_if, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*FLOAT */ {plus_f_fi, plus_f_ff, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro},
/*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn},
/*VOID */ {_2___, _2___, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn},
/*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro},
/*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn},
/*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn},
Expand Down Expand Up @@ -155,11 +155,11 @@
}

var minus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{
// . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT
/*INT */ {minus_n_ii, minus_f_if, _erro, _void, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*FLOAT */ {minus_f_fi, minus_f_ff, _erro, _void, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
// . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT
/*INT */ {minus_n_ii, minus_f_if, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*FLOAT */ {minus_f_fi, minus_f_ff, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro},
/*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn},
/*VOID */ {_n2__, _n2__, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn},
/*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro},
/*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn},
/*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn},
Expand Down Expand Up @@ -229,11 +229,11 @@
}

var times_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{
// . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT
/*INT */ {times_n_ii, times_f_if, _erro, _void, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*FLOAT */ {times_f_fi, times_f_ff, _erro, _void, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
// . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT
/*INT */ {times_n_ii, times_f_if, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*FLOAT */ {times_f_fi, times_f_ff, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro},
/*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn},
/*VOID */ {_2___, _2___, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn},
/*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro},
/*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn},
/*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn},
Expand Down Expand Up @@ -389,11 +389,11 @@
}

var dot_plus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{
// . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT
/*INT */ {dotplus_i_ii, dotplus_f_if, _erro, _void, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*FLOAT */ {dotplus_f_fi, dotplus_f_ff, _erro, _void, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
// . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT
/*INT */ {dotplus_i_ii, dotplus_f_if, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*FLOAT */ {dotplus_f_fi, dotplus_f_ff, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro},
/*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn},
/*VOID */ {_2___, _2___, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn},
/*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro},
/*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn},
/*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn},
Expand Down Expand Up @@ -425,11 +425,11 @@
}

var dotminus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{
// . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT
/*INT */ {dotminus_i_ii, dotminus_f_if, _erro, _void, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*FLOAT */ {dotminus_f_fi, dotminus_f_ff, _erro, _void, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
// . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT
/*INT */ {dotminus_i_ii, dotminus_f_if, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*FLOAT */ {dotminus_f_fi, dotminus_f_ff, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro},
/*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn},
/*VOID */ {_n2__, _n2__, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn},
/*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro},
/*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn},
/*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn},
Expand Down Expand Up @@ -461,11 +461,11 @@
}

var dottimes_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{
// . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT
/*INT */ {dottimes_i_ii, dottimes_f_if, _erro, _void, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*FLOAT */ {dottimes_f_fi, dottimes_f_ff, _erro, _void, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
// . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT
/*INT */ {dottimes_i_ii, dottimes_f_if, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*FLOAT */ {dottimes_f_fi, dottimes_f_ff, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___},
/*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro},
/*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn},
/*VOID */ {_n2__, _n2__, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn},
/*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro},
/*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn},
/*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn},
Expand Down Expand Up @@ -881,9 +881,9 @@
// Do the bulk arithmetic on native ints not Mlrvals, to avoid unnecessary allocation.
retval := lib.UTF8Strlen(mlrvals[0].OriginalString())
for i, _ := range mlrvals {
clen := lib.UTF8Strlen(mlrvals[i].OriginalString())

Check failure on line 884 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan

Check failure on line 884 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan
if clen < retval {

Check failure on line 885 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan

Check failure on line 885 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan
retval = clen

Check failure on line 886 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan

Check failure on line 886 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan
}
}
return mlrval.FromInt(retval)
Expand All @@ -896,9 +896,9 @@
// Do the bulk arithmetic on native ints not Mlrvals, to avoid unnecessary allocation.
retval := lib.UTF8Strlen(m.Head.Value.OriginalString())
for pe := m.Head.Next; pe != nil; pe = pe.Next {
clen := lib.UTF8Strlen(pe.Value.OriginalString())

Check failure on line 899 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan

Check failure on line 899 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan
if clen < retval {

Check failure on line 900 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan

Check failure on line 900 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan
retval = clen

Check failure on line 901 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan

Check failure on line 901 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan
}
}
return mlrval.FromInt(retval)
Expand Down Expand Up @@ -1043,9 +1043,9 @@
// Do the bulk arithmetic on native ints not Mlrvals, to avoid unnecessary allocation.
retval := lib.UTF8Strlen(mlrvals[0].OriginalString())
for i, _ := range mlrvals {
clen := lib.UTF8Strlen(mlrvals[i].OriginalString())

Check failure on line 1046 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan

Check failure on line 1046 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan
if clen > retval {

Check failure on line 1047 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan

Check failure on line 1047 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan
retval = clen

Check failure on line 1048 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan

Check failure on line 1048 in internal/pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan
}
}
return mlrval.FromInt(retval)
Expand Down
5 changes: 5 additions & 0 deletions internal/pkg/bifs/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ func _zero1(input1 *mlrval.Mlrval) *mlrval.Mlrval {
return mlrval.FromInt(0)
}

// Return one (unary)
func __one1(input1 *mlrval.Mlrval) *mlrval.Mlrval {
return mlrval.FromInt(1)
}

// Return null (unary)
func _null1(input1 *mlrval.Mlrval) *mlrval.Mlrval {
return mlrval.NULL
Expand Down
15 changes: 13 additions & 2 deletions internal/pkg/terminals/help/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ func helpTypeArithmeticInfo() {
mlrvals := []*mlrval.Mlrval{
mlrval.FromInt(1),
mlrval.FromFloat(2.5),
mlrval.VOID,
mlrval.ABSENT,
mlrval.ERROR,
}
Expand All @@ -497,17 +498,27 @@ func helpTypeArithmeticInfo() {
fmt.Printf("%-10s |", "(+)")
} else if i == -1 {
fmt.Printf("%-10s +", "------")
} else if mlrvals[i].IsVoid() {
fmt.Printf("%-10s |", "(empty)")
} else {
fmt.Printf("%-10s |", mlrvals[i].String())
}
for j := 0; j < n; j++ {
if i == -2 {
fmt.Printf(" %-10s", mlrvals[j].String())
if mlrvals[j].IsVoid() {
fmt.Printf("%-10s", "(empty)")
} else {
fmt.Printf(" %-10s", mlrvals[j].String())
}
} else if i == -1 {
fmt.Printf(" %-10s", "------")
} else {
sum := bifs.BIF_plus_binary(mlrvals[i], mlrvals[j])
fmt.Printf(" %-10s", sum.String())
if sum.IsVoid() {
fmt.Printf(" %-10s", "(empty)")
} else {
fmt.Printf(" %-10s", sum.String())
}
}
}
fmt.Println()
Expand Down
2 changes: 1 addition & 1 deletion man/manpage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3613,4 +3613,4 @@ MILLER(1) MILLER(1)



2023-08-26 MILLER(1)
2023-08-27 MILLER(1)
4 changes: 2 additions & 2 deletions man/mlr.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: mlr
.\" Author: [see the "AUTHOR" section]
.\" Generator: ./mkman.rb
.\" Date: 2023-08-26
.\" Date: 2023-08-27
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "MILLER" "1" "2023-08-26" "\ \&" "\ \&"
.TH "MILLER" "1" "2023-08-27" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Portability definitions
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions test/cases/dsl-absent-empty/0009/expout
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
x=1,y=2,z=3
x=1,y=,z=
x=,y=2,z=
x=1,y=,z=1
x=,y=2,z=2
x=,y=,z=
a=1,y=2,z=2
a=1,y=
Expand Down
Loading
Loading