diff --git a/c/draft-release-notes.md b/c/draft-release-notes.md index 983fc98f5..6a9828bc2 100644 --- a/c/draft-release-notes.md +++ b/c/draft-release-notes.md @@ -20,6 +20,8 @@ for those times when you want integer overflow. an alias for `--nidx --fs tab`, and `mlr -t` is an alias for `mlr --tsvlite`. +* The mathematical constants pi and e have been renamed from `PI` and `E` to `M_PI` and `M_E`, respectively. (It's annoying to get a syntax error when you try to define a variable named `E` in the DSL, when `A` through `D` work just fine.) This is a backward incompatibility, but not enough of us to justify calling this release Miller 6.0.0. + ## Documentation: * As noted diff --git a/c/dsl/function_manager.c b/c/dsl/function_manager.c index e19541562..e0ce8c58b 100644 --- a/c/dsl/function_manager.c +++ b/c/dsl/function_manager.c @@ -559,7 +559,7 @@ void fmgr_function_usage(fmgr_t* pfmgr, FILE* output_stream, char* function_name fprintf(output_stream, "numbers of the form \"%s --seed 123456789\" or \"%s --seed 0xcafefeed\".\n", MLR_GLOBALS.bargv0, MLR_GLOBALS.bargv0); fprintf(output_stream, "Miller's built-in variables are NF, NR, FNR, FILENUM, and FILENAME (awk-like)\n"); - fprintf(output_stream, "along with the mathematical constants PI and E.\n"); + fprintf(output_stream, "along with the mathematical constants M_PI and M_E.\n"); } } diff --git a/c/dsl/mlr_dsl_cst_keywords.c b/c/dsl/mlr_dsl_cst_keywords.c index 1b84d5b82..fa7ddb73b 100644 --- a/c/dsl/mlr_dsl_cst_keywords.c +++ b/c/dsl/mlr_dsl_cst_keywords.c @@ -7,6 +7,20 @@ // ---------------------------------------------------------------- typedef void keyword_usage_func_t(FILE* ostream); +static keyword_usage_func_t mlr_dsl_ENV_keyword_usage; +static keyword_usage_func_t mlr_dsl_FILENAME_keyword_usage; +static keyword_usage_func_t mlr_dsl_FILENUM_keyword_usage; +static keyword_usage_func_t mlr_dsl_FNR_keyword_usage; +static keyword_usage_func_t mlr_dsl_IFS_keyword_usage; +static keyword_usage_func_t mlr_dsl_IPS_keyword_usage; +static keyword_usage_func_t mlr_dsl_IRS_keyword_usage; +static keyword_usage_func_t mlr_dsl_M_E_keyword_usage; +static keyword_usage_func_t mlr_dsl_M_PI_keyword_usage; +static keyword_usage_func_t mlr_dsl_NF_keyword_usage; +static keyword_usage_func_t mlr_dsl_NR_keyword_usage; +static keyword_usage_func_t mlr_dsl_OFS_keyword_usage; +static keyword_usage_func_t mlr_dsl_OPS_keyword_usage; +static keyword_usage_func_t mlr_dsl_ORS_keyword_usage; static keyword_usage_func_t mlr_dsl_all_keyword_usage; static keyword_usage_func_t mlr_dsl_begin_keyword_usage; static keyword_usage_func_t mlr_dsl_bool_keyword_usage; @@ -46,20 +60,6 @@ static keyword_usage_func_t mlr_dsl_true_keyword_usage; static keyword_usage_func_t mlr_dsl_unset_keyword_usage; static keyword_usage_func_t mlr_dsl_var_keyword_usage; static keyword_usage_func_t mlr_dsl_while_keyword_usage; -static keyword_usage_func_t mlr_dsl_E_keyword_usage; -static keyword_usage_func_t mlr_dsl_ENV_keyword_usage; -static keyword_usage_func_t mlr_dsl_FILENAME_keyword_usage; -static keyword_usage_func_t mlr_dsl_FILENUM_keyword_usage; -static keyword_usage_func_t mlr_dsl_FNR_keyword_usage; -static keyword_usage_func_t mlr_dsl_IFS_keyword_usage; -static keyword_usage_func_t mlr_dsl_IPS_keyword_usage; -static keyword_usage_func_t mlr_dsl_IRS_keyword_usage; -static keyword_usage_func_t mlr_dsl_NF_keyword_usage; -static keyword_usage_func_t mlr_dsl_NR_keyword_usage; -static keyword_usage_func_t mlr_dsl_OFS_keyword_usage; -static keyword_usage_func_t mlr_dsl_OPS_keyword_usage; -static keyword_usage_func_t mlr_dsl_ORS_keyword_usage; -static keyword_usage_func_t mlr_dsl_PI_keyword_usage; // ---------------------------------------------------------------- typedef struct _keyword_usage_entry_t { @@ -108,7 +108,6 @@ static keyword_usage_entry_t KEYWORD_USAGE_TABLE[] = { { "unset", mlr_dsl_unset_keyword_usage }, { "var", mlr_dsl_var_keyword_usage }, { "while", mlr_dsl_while_keyword_usage }, - { "E", mlr_dsl_E_keyword_usage }, { "ENV", mlr_dsl_ENV_keyword_usage }, { "FILENAME", mlr_dsl_FILENAME_keyword_usage }, { "FILENUM", mlr_dsl_FILENUM_keyword_usage }, @@ -116,12 +115,13 @@ static keyword_usage_entry_t KEYWORD_USAGE_TABLE[] = { { "IFS", mlr_dsl_IFS_keyword_usage }, { "IPS", mlr_dsl_IPS_keyword_usage }, { "IRS", mlr_dsl_IRS_keyword_usage }, + { "M_E", mlr_dsl_M_E_keyword_usage }, + { "M_PI", mlr_dsl_M_PI_keyword_usage }, { "NF", mlr_dsl_NF_keyword_usage }, { "NR", mlr_dsl_NR_keyword_usage }, { "OFS", mlr_dsl_OFS_keyword_usage }, { "OPS", mlr_dsl_OPS_keyword_usage }, { "ORS", mlr_dsl_ORS_keyword_usage }, - { "PI", mlr_dsl_PI_keyword_usage }, }; static int KEYWORD_USAGE_TABLE_SIZE = sizeof(KEYWORD_USAGE_TABLE)/sizeof(KEYWORD_USAGE_TABLE[0]); @@ -562,12 +562,6 @@ static void mlr_dsl_while_keyword_usage(FILE* ostream) { ); } -static void mlr_dsl_E_keyword_usage(FILE *ostream) { - fprintf(ostream, - "E: the mathematical constant.\n" - ); -} - static void mlr_dsl_ENV_keyword_usage(FILE *ostream) { fprintf(ostream, "ENV: access to environment variables by name, e.g. '$home = ENV[\"HOME\"]'\n" @@ -614,6 +608,18 @@ static void mlr_dsl_IRS_keyword_usage(FILE *ostream) { ); } +static void mlr_dsl_M_E_keyword_usage(FILE *ostream) { + fprintf(ostream, + "M_E: the mathematical constant e.\n" + ); +} + +static void mlr_dsl_M_PI_keyword_usage(FILE *ostream) { + fprintf(ostream, + "M_PI: the mathematical constant pi.\n" + ); +} + static void mlr_dsl_NF_keyword_usage(FILE *ostream) { fprintf(ostream, "NF: evaluates to the number of fields in the current record.\n" @@ -647,9 +653,3 @@ static void mlr_dsl_ORS_keyword_usage(FILE *ostream) { ); } -static void mlr_dsl_PI_keyword_usage(FILE *ostream) { - fprintf(ostream, - "PI: the mathematical constant.\n" - ); -} - diff --git a/c/dsl/rval_expr_evaluators.c b/c/dsl/rval_expr_evaluators.c index 233630853..b0c92e3c9 100644 --- a/c/dsl/rval_expr_evaluators.c +++ b/c/dsl/rval_expr_evaluators.c @@ -771,7 +771,7 @@ mv_t rval_evaluator_PI_func(void* pvstate, variables_t* pvars) { static void rval_evaluator_PI_free(rval_evaluator_t* pevaluator) { free(pevaluator); } -rval_evaluator_t* rval_evaluator_alloc_from_PI() { +rval_evaluator_t* rval_evaluator_alloc_from_M_PI() { rval_evaluator_t* pevaluator = mlr_malloc_or_die(sizeof(rval_evaluator_t)); pevaluator->pvstate = NULL; pevaluator->pprocess_func = rval_evaluator_PI_func; @@ -786,7 +786,7 @@ mv_t rval_evaluator_E_func(void* pvstate, variables_t* pvars) { static void rval_evaluator_E_free(rval_evaluator_t* pevaluator) { free(pevaluator); } -rval_evaluator_t* rval_evaluator_alloc_from_E() { +rval_evaluator_t* rval_evaluator_alloc_from_M_E() { rval_evaluator_t* pevaluator = mlr_malloc_or_die(sizeof(rval_evaluator_t)); pevaluator->pvstate = NULL; pevaluator->pprocess_func = rval_evaluator_E_func; @@ -901,8 +901,8 @@ rval_evaluator_t* rval_evaluator_alloc_from_context_variable(char* variable_name } else if (streq(variable_name, "FNR")) { return rval_evaluator_alloc_from_FNR(); } else if (streq(variable_name, "FILENAME")) { return rval_evaluator_alloc_from_FILENAME(); } else if (streq(variable_name, "FILENUM")) { return rval_evaluator_alloc_from_FILENUM(); - } else if (streq(variable_name, "PI")) { return rval_evaluator_alloc_from_PI(); - } else if (streq(variable_name, "E")) { return rval_evaluator_alloc_from_E(); + } else if (streq(variable_name, "M_PI")) { return rval_evaluator_alloc_from_M_PI(); + } else if (streq(variable_name, "M_E")) { return rval_evaluator_alloc_from_M_E(); } else if (streq(variable_name, "IPS")) { return rval_evaluator_alloc_from_IPS(); } else if (streq(variable_name, "IFS")) { return rval_evaluator_alloc_from_IFS(); } else if (streq(variable_name, "IRS")) { return rval_evaluator_alloc_from_IRS(); diff --git a/c/mapping/mapper_put_or_filter.c b/c/mapping/mapper_put_or_filter.c index cbbf0ff3a..5b02663ac 100644 --- a/c/mapping/mapper_put_or_filter.c +++ b/c/mapping/mapper_put_or_filter.c @@ -220,7 +220,7 @@ static void shared_usage(FILE* o, char* argv0, char* verb) { fprintf(o, "Please use a dollar sign for field names and double-quotes for string\n"); fprintf(o, "literals. If field names have special characters such as \".\" then you might\n"); fprintf(o, "use braces, e.g. '${field.name}'. Miller built-in variables are\n"); - fprintf(o, "NF NR FNR FILENUM FILENAME PI E, and ENV[\"namegoeshere\"] to access environment\n"); + fprintf(o, "NF NR FNR FILENUM FILENAME M_PI M_E, and ENV[\"namegoeshere\"] to access environment\n"); fprintf(o, "variables. The environment-variable name may be an expression, e.g. a field\n"); fprintf(o, "value.\n"); fprintf(o, "\n"); diff --git a/c/parsing/ex1_lexer.l b/c/parsing/ex1_lexer.l index 9e89d45ae..039453f7c 100644 --- a/c/parsing/ex1_lexer.l +++ b/c/parsing/ex1_lexer.l @@ -425,11 +425,11 @@ false { *yyextra = ex_ast_node_alloc(yytext, MD_AST_NODE_TYPE_CONTEXT_VARIABLE); return MD_TOKEN_CONTEXT_VARIABLE; } -"PI" { +"M_PI" { *yyextra = ex_ast_node_alloc(yytext, MD_AST_NODE_TYPE_CONTEXT_VARIABLE); return MD_TOKEN_CONTEXT_VARIABLE; } -"E" { +"M_E" { *yyextra = ex_ast_node_alloc(yytext, MD_AST_NODE_TYPE_CONTEXT_VARIABLE); return MD_TOKEN_CONTEXT_VARIABLE; } diff --git a/c/parsing/mlr_dsl_lexer.l b/c/parsing/mlr_dsl_lexer.l index 5f1bba5f0..8d1798a76 100644 --- a/c/parsing/mlr_dsl_lexer.l +++ b/c/parsing/mlr_dsl_lexer.l @@ -550,11 +550,11 @@ *yyextra = mlr_dsl_ast_node_alloc(yytext, MD_AST_NODE_TYPE_CONTEXT_VARIABLE); return MD_TOKEN_CONTEXT_VARIABLE; } -"PI" { +"M_PI" { *yyextra = mlr_dsl_ast_node_alloc(yytext, MD_AST_NODE_TYPE_CONTEXT_VARIABLE); return MD_TOKEN_CONTEXT_VARIABLE; } -"E" { +"M_E" { *yyextra = mlr_dsl_ast_node_alloc(yytext, MD_AST_NODE_TYPE_CONTEXT_VARIABLE); return MD_TOKEN_CONTEXT_VARIABLE; } diff --git a/doc/content-for-reference-dsl.html b/doc/content-for-reference-dsl.html index 651b54705..5ac24c592 100644 --- a/doc/content-for-reference-dsl.html +++ b/doc/content-for-reference-dsl.html @@ -173,7 +173,7 @@ POKI_CARDIFY{{mlr put 'if ($x == 1) { }' # This no-op is syntactically acceptabl

Miller has the following kinds of variables:

Built-in variables such as NF, NF, -FILENAME, PI, and E. These are all capital letters +FILENAME, M_PI, and M_E. These are all capital letters and are read-only (although some of them change value from one record to another). @@ -209,8 +209,8 @@ defined by Miller.

Namely, Miller supports the following five built-in variables for filter and put, all awk-inspired: NF, NR, FNR, FILENUM, and -FILENAME, as well as the mathematical constants PI and -E. Lastly, the ENV hashmap allows read access to environment +FILENAME, as well as the mathematical constants M_PI and +M_E. Lastly, the ENV hashmap allows read access to environment variables, e.g. ENV["HOME"] or ENV["foo_".$hostname]. POKI_RUN_COMMAND{{mlr filter 'FNR == 2' data/small*}}HERE diff --git a/doc/manpage.html b/doc/manpage.html index 9ea173b7f..3dba7f251 100644 --- a/doc/manpage.html +++ b/doc/manpage.html @@ -677,7 +677,7 @@ VERBS Please use a dollar sign for field names and double-quotes for string literals. If field names have special characters such as "." then you might use braces, e.g. '${field.name}'. Miller built-in variables are - NF NR FNR FILENUM FILENAME PI E, and ENV["namegoeshere"] to access environment + NF NR FNR FILENUM FILENAME M_PI M_E, and ENV["namegoeshere"] to access environment variables. The environment-variable name may be an expression, e.g. a field value. @@ -1013,7 +1013,7 @@ VERBS Please use a dollar sign for field names and double-quotes for string literals. If field names have special characters such as "." then you might use braces, e.g. '${field.name}'. Miller built-in variables are - NF NR FNR FILENUM FILENAME PI E, and ENV["namegoeshere"] to access environment + NF NR FNR FILENUM FILENAME M_PI M_E, and ENV["namegoeshere"] to access environment variables. The environment-variable name may be an expression, e.g. a field value. @@ -2232,9 +2232,6 @@ KEYWORDS FOR PUT AND FILTER while: introduces a while loop, or with "do", introduces a do-while loop. The body statements must be wrapped in curly braces. - E - E: the mathematical constant. - ENV ENV: access to environment variables by name, e.g. '$home = ENV["HOME"]' @@ -2260,6 +2257,12 @@ KEYWORDS FOR PUT AND FILTER or to LF or CRLF from the input data if in autodetect mode (which is the default). + M_E + M_E: the mathematical constant e. + + M_PI + M_PI: the mathematical constant pi. + NF NF: evaluates to the number of fields in the current record. @@ -2278,9 +2281,6 @@ KEYWORDS FOR PUT AND FILTER or to LF or CRLF from the input data if in autodetect mode (which is the default). - PI - PI: the mathematical constant. - AUTHOR Miller is written by John Kerl <kerl.john.r@gmail.com>. @@ -2294,7 +2294,7 @@ SEE ALSO - 2017-11-18 MILLER(1) + 2017-12-19 MILLER(1)

diff --git a/doc/manpage.txt b/doc/manpage.txt index 756057060..c14364f87 100644 --- a/doc/manpage.txt +++ b/doc/manpage.txt @@ -483,7 +483,7 @@ VERBS Please use a dollar sign for field names and double-quotes for string literals. If field names have special characters such as "." then you might use braces, e.g. '${field.name}'. Miller built-in variables are - NF NR FNR FILENUM FILENAME PI E, and ENV["namegoeshere"] to access environment + NF NR FNR FILENUM FILENAME M_PI M_E, and ENV["namegoeshere"] to access environment variables. The environment-variable name may be an expression, e.g. a field value. @@ -819,7 +819,7 @@ VERBS Please use a dollar sign for field names and double-quotes for string literals. If field names have special characters such as "." then you might use braces, e.g. '${field.name}'. Miller built-in variables are - NF NR FNR FILENUM FILENAME PI E, and ENV["namegoeshere"] to access environment + NF NR FNR FILENUM FILENAME M_PI M_E, and ENV["namegoeshere"] to access environment variables. The environment-variable name may be an expression, e.g. a field value. @@ -2038,9 +2038,6 @@ KEYWORDS FOR PUT AND FILTER while: introduces a while loop, or with "do", introduces a do-while loop. The body statements must be wrapped in curly braces. - E - E: the mathematical constant. - ENV ENV: access to environment variables by name, e.g. '$home = ENV["HOME"]' @@ -2066,6 +2063,12 @@ KEYWORDS FOR PUT AND FILTER or to LF or CRLF from the input data if in autodetect mode (which is the default). + M_E + M_E: the mathematical constant e. + + M_PI + M_PI: the mathematical constant pi. + NF NF: evaluates to the number of fields in the current record. @@ -2084,9 +2087,6 @@ KEYWORDS FOR PUT AND FILTER or to LF or CRLF from the input data if in autodetect mode (which is the default). - PI - PI: the mathematical constant. - AUTHOR Miller is written by John Kerl . @@ -2100,4 +2100,4 @@ SEE ALSO - 2017-11-18 MILLER(1) + 2017-12-19 MILLER(1) diff --git a/doc/mlr.1 b/doc/mlr.1 index d0c57ad8b..30c88bf0f 100644 --- a/doc/mlr.1 +++ b/doc/mlr.1 @@ -2,12 +2,12 @@ .\" Title: mlr .\" Author: [see the "AUTHOR" section] .\" Generator: ./mkman.rb -.\" Date: 2017-11-18 +.\" Date: 2017-12-19 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" -.TH "MILLER" "1" "2017-11-18" "\ \&" "\ \&" +.TH "MILLER" "1" "2017-12-19" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * Portability definitions .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -642,7 +642,7 @@ Other options: Please use a dollar sign for field names and double-quotes for string literals. If field names have special characters such as "." then you might use braces, e.g. '${field.name}'. Miller built-in variables are -NF NR FNR FILENUM FILENAME PI E, and ENV["namegoeshere"] to access environment +NF NR FNR FILENUM FILENAME M_PI M_E, and ENV["namegoeshere"] to access environment variables. The environment-variable name may be an expression, e.g. a field value. @@ -1068,7 +1068,7 @@ Other options: Please use a dollar sign for field names and double-quotes for string literals. If field names have special characters such as "." then you might use braces, e.g. '${field.name}'. Miller built-in variables are -NF NR FNR FILENUM FILENAME PI E, and ENV["namegoeshere"] to access environment +NF NR FNR FILENUM FILENAME M_PI M_E, and ENV["namegoeshere"] to access environment variables. The environment-variable name may be an expression, e.g. a field value. @@ -3538,15 +3538,6 @@ The body statements must be wrapped in curly braces. .fi .if n \{\ .RE -.SS "E" -.if n \{\ -.RS 0 -.\} -.nf -E: the mathematical constant. -.fi -.if n \{\ -.RE .SS "ENV" .if n \{\ .RS 0 @@ -3614,6 +3605,24 @@ the default). .fi .if n \{\ .RE +.SS "M_E" +.if n \{\ +.RS 0 +.\} +.nf +M_E: the mathematical constant e. +.fi +.if n \{\ +.RE +.SS "M_PI" +.if n \{\ +.RS 0 +.\} +.nf +M_PI: the mathematical constant pi. +.fi +.if n \{\ +.RE .SS "NF" .if n \{\ .RS 0 @@ -3662,15 +3671,6 @@ the default). .fi .if n \{\ .RE -.SS "PI" -.if n \{\ -.RS 0 -.\} -.nf -PI: the mathematical constant. -.fi -.if n \{\ -.RE .SH "AUTHOR" .sp Miller is written by John Kerl . diff --git a/doc/reference-dsl.html b/doc/reference-dsl.html index 05a821fc4..37ec4b0f5 100644 --- a/doc/reference-dsl.html +++ b/doc/reference-dsl.html @@ -796,7 +796,7 @@ mlr put 'if ($x == 1) { }' # This no-op is syntactically acceptable

Miller has the following kinds of variables:

Built-in variables such as NF, NF, -FILENAME, PI, and E. These are all capital letters +FILENAME, M_PI, and M_E. These are all capital letters and are read-only (although some of them change value from one record to another). @@ -832,8 +832,8 @@ defined by Miller.

Namely, Miller supports the following five built-in variables for filter and put, all awk-inspired: NF, NR, FNR, FILENUM, and -FILENAME, as well as the mathematical constants PI and -E. Lastly, the ENV hashmap allows read access to environment +FILENAME, as well as the mathematical constants M_PI and +M_E. Lastly, the ENV hashmap allows read access to environment variables, e.g. ENV["HOME"] or ENV["foo_".$hostname].

@@ -2007,8 +2007,6 @@ Examples: 'var a=1', 'var xyz=""' while: introduces a while loop, or with "do", introduces a do-while loop. The body statements must be wrapped in curly braces. -E: the mathematical constant. - ENV: access to environment variables by name, e.g. '$home = ENV["HOME"]' FILENAME: evaluates to the name of the current file being processed. @@ -2027,6 +2025,10 @@ IRS: evaluates to the input record separator from the command line, or to LF or CRLF from the input data if in autodetect mode (which is the default). +M_E: the mathematical constant e. + +M_PI: the mathematical constant pi. + NF: evaluates to the number of fields in the current record. NR: evaluates to the number of the current record over all files @@ -2039,8 +2041,6 @@ OPS: evaluates to the output pair separator from the command line. ORS: evaluates to the output record separator from the command line, or to LF or CRLF from the input data if in autodetect mode (which is the default). - -PI: the mathematical constant.

diff --git a/doc/reference-verbs.html b/doc/reference-verbs.html index 4aeeeb439..ac926f4a8 100644 --- a/doc/reference-verbs.html +++ b/doc/reference-verbs.html @@ -980,7 +980,7 @@ Other options: Please use a dollar sign for field names and double-quotes for string literals. If field names have special characters such as "." then you might use braces, e.g. '${field.name}'. Miller built-in variables are -NF NR FNR FILENUM FILENAME PI E, and ENV["namegoeshere"] to access environment +NF NR FNR FILENUM FILENAME M_PI M_E, and ENV["namegoeshere"] to access environment variables. The environment-variable name may be an expression, e.g. a field value. @@ -2262,7 +2262,7 @@ Other options: Please use a dollar sign for field names and double-quotes for string literals. If field names have special characters such as "." then you might use braces, e.g. '${field.name}'. Miller built-in variables are -NF NR FNR FILENUM FILENAME PI E, and ENV["namegoeshere"] to access environment +NF NR FNR FILENUM FILENAME M_PI M_E, and ENV["namegoeshere"] to access environment variables. The environment-variable name may be an expression, e.g. a field value.