2 eval - evaluate a string
13 For eval(str), the value of str is to be a string that could be the body
14 of the definition of a function f(). This string may declare local
15 variables and include keywords (while, for, ...) other than the
16 reserved keywords (define, show, help, read, write, show, cd) intended
17 for interactive use or for reading from a file.
19 If str is the empty string "", eval(str) returns the null value.
21 The call to eval(str) may return a value by explicit use of a return
22 statement: "return;" returns the null value, "return expr;" returns the
23 value of expr. If execution reaches the end of str and the
24 value on the execution stack is not null, eval(str) returns that value;
25 otherwise eval(str) returns the most recently saved value.
27 Each time eval(str) is called, a temporary function is compiled from
28 the commands in str, and if there are no syntax errors, this function
29 is then evaluated. If str contains syntax errors, eval(str) displays
30 the scanerror messages and returns the value error(49).
33 ; str1 = "2 + 3"; print eval(str1);
36 ; i = 10; str2 = "local i = 0; 7; while (i++ < 5) print i^2,:;"
37 ; print i, eval(str2), i
40 (The print statements in str2 return the null value, so execution of
41 eval(str2) ends by returning the saved value 7. The global variable
49 The string str in eval(str) should not include a call to itself as in
53 For this str, eval(str) causes an "Evaluation stack depth exceeded" error.
54 Similarly, if str1 = "2 + eval(str2)", str2 should not include a call
61 command, expression, define, prompt
63 ## Copyright (C) 1999 Landon Curt Noll
65 ## Calc is open software; you can redistribute it and/or modify it under
66 ## the terms of the version 2.1 of the GNU Lesser General Public License
67 ## as published by the Free Software Foundation.
69 ## Calc is distributed in the hope that it will be useful, but WITHOUT
70 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
71 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
72 ## Public License for more details.
74 ## A copy of version 2.1 of the GNU Lesser General Public License is
75 ## distributed with calc under the filename COPYING-LGPL. You should have
76 ## received a copy with calc; if not, write to Free Software Foundation, Inc.
77 ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
79 ## @(#) $Revision: 30.1 $
80 ## @(#) $Id: eval,v 30.1 2007/03/16 11:10:42 chongo Exp $
81 ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/eval,v $
83 ## Under source code control: 1995/12/18 03:30:59
84 ## File existed as early as: 1995
86 ## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
87 ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/