Introduce "FSET - f(args) expr" syntax to define a function and suppress any "redefined function" warnings.

This commit is contained in:
Dianne Skoll
2025-05-28 14:40:46 -04:00
parent 516b9c81b3
commit 71d2da19a8
4 changed files with 38 additions and 7 deletions

View File

@@ -5076,7 +5076,18 @@ function, the command fails with an error message and does nothing.
If you define a user-defined function and then later on redefine it,
\fBRemind\fR will issue a warning. If you do not want this warning,
then use \fBFUNSET\fR to remove the existing definition before you
redefine the function.
redefine the function. Alternatively, you can use a "-" token before
the function name to suppress "redefined function" warnings, as in the
following example:
.PP
.nf
FSET - f(x) 2*x
# You must have space before and after the "-"
# This will NOT work:
# FSET -f(x) 2*x
.fi
.PP
to define a function and suppress any "redefined function" warning.
.PP
.SH PRECISE SCHEDULING
.PP

View File

@@ -181,12 +181,31 @@ int DoFset(ParsePtr p)
Var *locals = NULL;
Var local_array[MAX_FUNC_ARGS];
int orig_namelen;
int suppress_redefined_function_warning = 0;
int ch;
DynamicBuffer buf;
DBufInit(&buf);
ch = ParseNonSpaceChar(p, &r, 1);
if (r) {
return r;
}
if (ch == '-') {
r = ParseToken(p, &buf);
if (strcmp(DBufValue(&buf), "-")) {
DBufFree(&buf);
return E_PARSE_ERR;
}
suppress_redefined_function_warning = 1;
DBufFree(&buf);
}
/* Get the function name */
if ( (r=ParseIdentifier(p, &buf)) ) return r;
if ( (r=ParseIdentifier(p, &buf)) ) {
return r;
}
if (*DBufValue(&buf) == '$') {
DBufFree(&buf);
return E_BAD_ID;
@@ -222,8 +241,10 @@ int DoFset(ParsePtr p)
return OK;
}
/* Warn about redefinition */
Wprint(tr("Function `%s' redefined: previously defined at %s(%s)"),
existing->name, existing->filename, line_range(existing->lineno_start, existing->lineno));
if (!suppress_redefined_function_warning) {
Wprint(tr("Function `%s' redefined: previously defined at %s(%s)"),
existing->name, existing->filename, line_range(existing->lineno_start, existing->lineno));
}
}
/* Should be followed by '(' */

View File

@@ -800,8 +800,7 @@ Leaving UserFN _ofunc(1991-02-28) => 0
../tests/test.rem(224): Trig = Thursday, 28 February, 1991
# omitfunc ignores local/global omits
fset _ofunc(x) 0
../tests/test.rem(227): Function `_ofunc' redefined: previously defined at ../tests/test.rem(222)
fset - _ofunc(x) 0
OMIT 1 March
OMIT 2 March 1991
REM 1 March OMIT Sun OMITFUNC _ofunc AFTER MSG Should trigger 1 March

View File

@@ -224,7 +224,7 @@ REM 1 March OMITFUNC _ofunc AFTER MSG OmitFunc Test
REM 8 March OMITFUNC _ofunc -1 MSG OmitFunc Test 2
# omitfunc ignores local/global omits
fset _ofunc(x) 0
fset - _ofunc(x) 0
OMIT 1 March
OMIT 2 March 1991
REM 1 March OMIT Sun OMITFUNC _ofunc AFTER MSG Should trigger 1 March