Add "const" function, which is the inverse of "nonconst"

This commit is contained in:
Dianne Skoll
2025-05-23 08:47:12 -04:00
parent 1df8b12e71
commit 0ec43d570c
5 changed files with 15 additions and 3 deletions

View File

@@ -164,7 +164,7 @@
(defconst remind-builtin-functions
(sort
(list "_" "abs" "access" "adawn" "adusk" "ampm" "ansicolor" "args" "asc"
"baseyr" "catch" "catcherr" "char" "choose" "coerce" "columns" "current" "date"
"baseyr" "catch" "catcherr" "char" "choose" "coerce" "columns" "const" "current" "date"
"datepart" "datetime" "dawn" "day" "daysinmon" "defined" "dosubst"
"dusk" "easterdate" "escape" "eval" "evaltrig" "filedate" "filedatetime"
"filedir" "filename" "getenv" "hebdate" "hebday" "hebmon" "hebyear"

View File

@@ -3038,7 +3038,7 @@ Equivalent to \fBday(trigdate())\fR.
.B $Tm (read-only)
Equivalent to \fBmonnum(trigdate())\fR.
.TP
.B $Tu (read-only)
.B $Tu (read-only, DATE type)
Equivalent to \fBtriguntil()\fR.
.TP
.B $Tw (read-only)
@@ -3400,7 +3400,12 @@ characters occupy two columns. \fBcolumns(str)\fR takes all of that
into account. Note that if \fBRemind\fR was compiled without Unicode support,
\fBcolumns(str)\fR returns a type mismatch error.
.RE
.TP
.B const(x_arg)
Evaluates \fIarg\fR and returns it, but also ensures that the result
is marked "constant". Use with caution; incorrect use could result
in unwanted reminders being purged in Purge Mode. See also the section
"NON-CONSTANT EXPRESSIONS"
.TP
.B current()
Returns the current date and time as a DATETIME object. This may be the

View File

@@ -568,6 +568,10 @@ eval_builtin(expr_node *node, Value *locals, Value *ans, int *nonconst)
/* All went well; copy the result destructively */
(*ans) = info.retval;
/* Special case of const cunction */
if (!strcmp(f->name, "const")) {
*nonconst = 0;
}
/* Don't allow retval to be destroyed! */
info.retval.type = ERR_TYPE;
}

View File

@@ -258,6 +258,7 @@ BuiltinFunc Func[] = {
{ "choose", 2, NO_MAX, 1, NULL, FChoose }, /*NEW-STYLE*/
{ "coerce", 2, 2, 1, FCoerce, NULL },
{ "columns", 0, 1, 0, FColumns, NULL },
{ "const", 1, 1, 1, FNonconst, NULL },
{ "current", 0, 0, 0, FCurrent, NULL },
{ "date", 3, 3, 1, FDate, NULL },
{ "datepart", 1, 1, 1, FDatepart, NULL },

View File

@@ -20253,6 +20253,7 @@ Timed
Untimed
Purge Test
../tests/purge_dir/f3.rem(62): Attempt to redefine built-in function: `const'
../tests/purge_dir/f3.rem(76): `/': Division by zero
../tests/purge_dir/f3.rem(76): `/': Division by zero
F1
@@ -24460,6 +24461,7 @@ char
choose
coerce
columns
const
current
date
datepart