mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
88 lines
2.9 KiB
Plaintext
88 lines
2.9 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.
|
|
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
|
##
|
|
## @(#) $Revision: 29.1 $
|
|
## @(#) $Id: eval,v 29.1 1999/12/14 09:15:48 chongo Exp $
|
|
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/eval,v $
|
|
##
|
|
## Under source code control: 1995/12/18 03:30:59
|
|
## File existed as early as: 1995
|
|
##
|
|
## chongo <was here> /\oo/\ http://reality.sgi.com/chongo/
|
|
## Share and enjoy! :-) http://reality.sgi.com/chongo/tech/comp/calc/
|