mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Some folks might think: “you still use RCS”?!? And we will say, hey, at least we switched from SCCS to RCS back in … I think it was around 1994 ... at least we are keeping up! :-) :-) :-) Logs say that SCCS version 18 became RCS version 19 on 1994 March 18. RCS served us well. But now it is time to move on. And so we are switching to git. Calc releases produce a lot of file changes. In the 125 releases of calc since 1996, when I started managing calc releases, there have been 15473 file mods!
84 lines
2.8 KiB
Plaintext
84 lines
2.8 KiB
Plaintext
NAME
|
|
eval - evaluate a string
|
|
|
|
SYNOPSIS
|
|
eval(str)
|
|
|
|
TYPES
|
|
str string
|
|
|
|
return any
|
|
|
|
DESCRIPTION
|
|
For eval(str), the value of str is to be a string that could be the body
|
|
of the definition of a function f(). This string may declare local
|
|
variables and include keywords (while, for, ...) other than the
|
|
reserved keywords (define, show, help, read, write, show, cd) intended
|
|
for interactive use or for reading from a file.
|
|
|
|
If str is the empty string "", eval(str) returns the null value.
|
|
|
|
The call to eval(str) may return a value by explicit use of a return
|
|
statement: "return;" returns the null value, "return expr;" returns the
|
|
value of expr. If execution reaches the end of str and the
|
|
value on the execution stack is not null, eval(str) returns that value;
|
|
otherwise eval(str) returns the most recently saved value.
|
|
|
|
Each time eval(str) is called, a temporary function is compiled from
|
|
the commands in str, and if there are no syntax errors, this function
|
|
is then evaluated. If str contains syntax errors, eval(str) displays
|
|
the scanerror messages and returns the value error(49).
|
|
|
|
EXAMPLE
|
|
; str1 = "2 + 3"; print eval(str1);
|
|
5
|
|
|
|
; i = 10; str2 = "local i = 0; 7; while (i++ < 5) print i^2,:;"
|
|
; print i, eval(str2), i
|
|
10 1 4 9 16 25 7 10
|
|
|
|
(The print statements in str2 return the null value, so execution of
|
|
eval(str2) ends by returning the saved value 7. The global variable
|
|
i is unchanged.)
|
|
|
|
; eval("2 + ");
|
|
Missing expression
|
|
49
|
|
|
|
LIMITS
|
|
The string str in eval(str) should not include a call to itself as in
|
|
|
|
str = "2 + eval(str)"
|
|
|
|
For this str, eval(str) causes an "Evaluation stack depth exceeded" error.
|
|
Similarly, if str1 = "2 + eval(str2)", str2 should not include a call
|
|
to eval(str1), etc.
|
|
|
|
LINK LIBRARY
|
|
none
|
|
|
|
SEE ALSO
|
|
command, expression, define, prompt
|
|
|
|
## Copyright (C) 1999 Landon Curt Noll
|
|
##
|
|
## Calc is open software; you can redistribute it and/or modify it under
|
|
## the terms of the version 2.1 of the GNU Lesser General Public License
|
|
## as published by the Free Software Foundation.
|
|
##
|
|
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
|
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
|
## Public License for more details.
|
|
##
|
|
## A copy of version 2.1 of the GNU Lesser General Public License is
|
|
## distributed with calc under the filename COPYING-LGPL. You should have
|
|
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
##
|
|
## Under source code control: 1995/12/18 03:30:59
|
|
## File existed as early as: 1995
|
|
##
|
|
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
|
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|