3 This is a sequence of any the following command formats, where
4 each command is terminated by a semicolon or newline. Long command
5 lines can be extended by using a back-slash followed by a newline
6 character. When this is done, the prompt shows a double angle
7 bracket to indicate that the line is still in progress. Certain
8 cases will automatically prompt for more input in a similar manner,
9 even without the back-slash. The most common case for this is when
10 a function is being defined, but is not yet completed.
12 Each command sequence terminates only on an end of file. In
13 addition, commands can consist of expression sequences, which are
14 described in the next section.
19 define function(params) { body }
20 define function(params) = expression
22 This first form defines a full function which can consist
23 of declarations followed by many statements which implement
26 The second form defines a simple function which calculates
27 the specified expression value from the specified parameters.
28 The expression cannot be a statement. However, the comma
29 and question mark operators can be useful. Examples of
32 define sumcubes(a, b) = a^3 + b^3
33 define pimod(a) = a % pi()
34 define printnum(a, n, p)
37 print a: "^": n, "=", a^n;
39 print a: "^": n, "mod", p, "=", pmod(a,n,p);
51 This reads definitions from the specified calc resource filename.
53 In the 1st and 2nd forms, if var is a global variable string
54 value, then the value of that variable is used as a filename.
56 The following is equivalent to read lucas.cal or read "lucas.cal":
58 global var = "lucas.cal";
61 In the 3rd or 4th forms, the filename argument is treated
62 as a literal string, not a variable. In these forms, the
63 name can be quoted if desired.
65 The calculator uses the CALCPATH environment variable to
66 search through the specified directories for the filename,
67 similarly to the use of the PATH environment variable.
68 If CALCPATH is not defined, then a default path which is
69 usually ":/usr/local/lib/calc" is used.
71 The ".cal" extension is defaulted for input files, so that
72 if "filename" is not found, then "filename.cal" is then
73 searched for. The contents of the filename are command
74 sequences which can consist of expressions to evaluate or
75 functions to define, just like at the top level command level.
77 When -once is given, the read command acts like the regular
78 read expect that it will ignore filename if is has been
81 The read -once form is particularly useful in a resource
82 file that needs to read a 2nd resource file. By using the
83 READ -once command, one will not reread that 2nd resource
84 file, nor will once risk entering into a infinite READ loop
85 (where that 2nd resource file directly or indirectly does
86 a READ of the first resource file).
88 If the -m mode disallows opening of files for reading,
89 this command will be disabled.
97 This writes the values of all global variables to the
98 specified filename, in such a way that the file can be
99 later read in order to recreate the variable values.
100 For speed reasons, values are written as hex fractions.
101 This command currently only saves simple types, so that
102 matrices, lists, and objects are not saved. Function
103 definitions are also not saved.
105 In the 1st form, if var is a global variable string
106 value, then the value of that variable is used as a filename.
108 The following is equivalent to write dump.out or
111 global var = "dump.out";
114 In the 2nd form, the filename argument is treated as a literal
115 string, not a variable. In this form, the name can be quoted
118 If the -m mode disallows opening of files for writing,
119 this command will be disabled.
129 The action of these commands depends on where they are used.
130 At the interactive level, they will cause calc it edit.
131 This is the normal way to leave the calculator. In any
132 other use, they will stop the current calculation as if
133 an error had occurred.
135 If a string is given, then the string is printed as the reason
136 for quitting, otherwise a general quit message is printed.
137 The routine name and line number which executed the quit is
138 also printed in either case.
140 Exit is an alias for quit.
142 Quit is useful when a routine detects invalid arguments,
143 in order to stop a calculation cleanly. For example,
144 for a square root routine, an error can be given if the
145 supplied parameter was a negative number, as in:
150 quit "non-numeric argument";
152 quit "Negative argument";
156 See 'more information about abort and quit' below for
165 This command behaves like QUIT except that it will attempt
166 to return to the interactive level if permitted, otherwise
169 See 'more information about abort and quit' below for
173 change current directory
174 ------------------------
178 Change the current directory to 'dir'. If 'dir' is ommitted,
179 change the current directory to the home directory, if $HOME
180 is set in the environment.
187 This command displays some information where 'item' is
188 one of the following:
190 blocks unfreed named blocks
191 builtin built in functions
192 config config parameters and values
193 constants cache of numeric constants
194 custom custom functions if calc -C was used
195 errors new error-values created
196 files open files, file position and sizes
197 function user-defined functions
198 globaltypes global variables
199 objfunctions possible object functions
200 objtypes defined objects
201 opcodes func internal opcodes for function `func'
202 sizes size in octets of calc value types
203 realglobals numeric global variables
204 statics unscoped static variables
205 numbers calc number cache
206 redcdata REDC data defined
207 strings calc string cache
208 literals calc literal cache
210 Only the first 4 characters of item are examined, so:
224 This displays a help related to 'name' or general
225 help of none is given.
227 In the 1st form, if var is a global variable string
228 value, then the value of that variable is used as a name.
230 The following is equivalent to help command or help "command":
232 global var = "command";
235 In the 2nd form, the filename argument is treated as a literal
236 string, not a variable. In this form, the name can be quoted
242 more information about abort and quit
243 =====================================
245 Consider the following calc file called myfile.cal:
247 print "start of myfile.cal";
248 define q() {quit "quit from q()"; print "end of q()"}
249 define a() {abort "abort from a()"}
251 {print "start #1"; if (x > 1) q()} print "after #1";
252 {print "start #2"; if (x > 1) a()} print "after #2";
253 {print "start #3"; if (x > 1) quit "quit from 3rd statement"}
254 print "end of myfile.cal";
270 The QUIT within the q() function prevented the ``end of q()''
271 statement from being evaluated. This QUIT command caused
272 control to be returned to just after the place where q()
275 Notice that unlike QUIT, the ABORT inside function a() halts
276 the processing of statements from the input source (myfile.cal).
277 Because calc was not interactive, ABORT causes calc to exit.
292 ; <==== calc interactive prompt
294 because the '-i' calc causes ABORT to drop into an
295 interactive prompt. However typing a QUIT or ABORT
296 at the interactive prompt level will always calc to exit,
297 even when calc is invoked with '-i'.
299 Also observe that both of these commands:
301 cat myfile.cal | calc
302 cat myfile.cal | calc -i
314 The ABORT inside function a() halts the processing of statements
315 from the input source (standard input). Because standard input
316 is not a terminal, using '-i' does not force it to drop into
317 an interactive prompt.
319 If one were to type in the contents of myfile.cal interactively,
322 ; print "start of myfile.cal";
324 ; define q() {quit "quit from q()"; print "end of q()"}
326 ; define a() {abort "abort from a()"}
329 ; {print "start #1"; if (x > 1) q()} print "after #1";
333 ; {print "start #2"; if (x > 1) a()} print "after #2";
336 ; {print "start #3"; if (x > 1) quit "quit from 3rd statement"}
338 quit from 3rd statement
340 The ABORT from within the a() function returned control to
341 the interactive level.
343 The QUIT (after the if (x > 1) ...) will cause calc to exit
344 because it was given at the interactive prompt level.
348 Also see the help topic:
350 statement flow control and declaration statements
351 usage how to invoke the calc command and calc -options
353 ## Copyright (C) 1999-2006 Landon Curt Noll
355 ## Calc is open software; you can redistribute it and/or modify it under
356 ## the terms of the version 2.1 of the GNU Lesser General Public License
357 ## as published by the Free Software Foundation.
359 ## Calc is distributed in the hope that it will be useful, but WITHOUT
360 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
361 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
362 ## Public License for more details.
364 ## A copy of version 2.1 of the GNU Lesser General Public License is
365 ## distributed with calc under the filename COPYING-LGPL. You should have
366 ## received a copy with calc; if not, write to Free Software Foundation, Inc.
367 ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
369 ## @(#) $Revision: 30.1 $
370 ## @(#) $Id: command,v 30.1 2007/03/16 11:10:42 chongo Exp $
371 ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/command,v $
373 ## Under source code control: 1991/07/21 04:37:17
374 ## File existed as early as: 1991
376 ## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
377 ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/