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
21 This first form defines a full function which can consist
22 of declarations followed by many statements which implement
25 The second form defines a simple function which calculates
26 the specified expression value from the specified parameters.
27 The expression cannot be a statement. However, the comma
28 and question mark operators can be useful. Examples of
31 define sumcubes(a, b) = a^3 + b^3
32 define pimod(a) = a % pi()
33 define printnum(a, n, p)
36 print a: "^": n, "=", a^n;
38 print a: "^": n, "mod", p, "=", pmod(a,n,p);
47 This reads definitions from the specified calc resource filename.
49 The name can be quoted if desired. The calculator uses the
50 CALCPATH environment variable to search through the specified
51 directories for the filename, similarly to the use of the
52 PATH environment variable. If CALCPATH is not defined,
53 then a default path which is usually ":/usr/local/lib/calc"
56 The ".cal" extension is defaulted for input files, so that
57 if "filename" is not found, then "filename.cal" is then
58 searched for. The contents of the filename are command
59 sequences which can consist of expressions to evaluate or
60 functions to define, just like at the top level command level.
62 When -once is given, the read command acts like the regular
63 read expect that it will ignore filename if is has been
66 The read -once form is particularly useful in a resource
67 file that needs to read a 2nd resource file. By using the
68 READ -once command, one will not reread that 2nd resource
69 file, nor will once risk entering into a infinite READ loop
70 (where that 2nd resource file directly or indirectly does
71 a READ of the first resource file).
73 If the -m mode disallows opening of files for reading,
74 this command will be disabled.
80 This writes the values of all global variables to the
81 specified filename, in such a way that the file can be
82 later read in order to recreate the variable values.
83 For speed reasons, values are written as hex fractions.
84 This command currently only saves simple types, so that
85 matrices, lists, and objects are not saved. Function
86 definitions are also not saved.
88 If the -m mode disallows opening of files for writing,
89 this command will be disabled.
98 The action of these commands depends on where they are used.
99 At the interactive level, they will cause calc it edit.
100 This is the normal way to leave the calculator. In any
101 other use, they will stop the current calculation as if
102 an error had occurred.
104 If a string is given, then the string is printed as the reason
105 for quitting, otherwise a general quit message is printed.
106 The routine name and line number which executed the quit is
107 also printed in either case.
109 Exit is an alias for quit.
111 Quit is useful when a routine detects invalid arguments,
112 in order to stop a calculation cleanly. For example,
113 for a square root routine, an error can be given if the
114 supplied parameter was a negative number, as in:
119 quit "non-numeric argument";
121 quit "Negative argument";
125 See 'more information about abort and quit' below for
134 This command behaves like QUIT except that it will attempt
135 to return to the interactive level if permitted, otherwise
138 See 'more information about abort and quit' below for
142 change current directory
143 ------------------------
146 Change the current directory to 'dir'. If 'dir' is ommitted,
147 change the current directory to the home directory, if $HOME
148 is set in the environment.
154 This command displays some information where 'item' is
155 one of the following:
157 blocks unfreed named blocks
158 builtin built in functions
159 config config parameters and values
160 constants cache of numeric constants
161 custom custom functions if calc -C was used
162 errors new error-values created
163 files open files, file position and sizes
164 function user-defined functions
165 globaltypes global variables
166 objfunctions possible object functions
167 objtypes defined objects
168 opcodes func internal opcodes for function `func'
169 sizes size in octets of calc value types
170 realglobals numeric global variables
171 statics unscoped static variables
172 numbers calc number cache
173 redcdata REDC data defined
174 strings calc string cache
175 literals calc literal cache
177 Only the first 4 characters of item are examined, so:
190 This displays a help related to 'name' or general
191 help of none is given.
197 more information about abort and quit
198 =====================================
200 Consider the following calc file called myfile.cal:
202 print "start of myfile.cal";
203 define q() {quit "quit from q()"; print "end of q()"}
204 define a() {abort "abort from a()"}
206 {print "start #1"; if (x > 1) q()} print "after #1";
207 {print "start #2"; if (x > 1) a()} print "after #2";
208 {print "start #3"; if (x > 1) quit "quit from 3rd statement"}
209 print "end of myfile.cal";
225 The QUIT within the q() function prevented the ``end of q()''
226 statement from being evaluated. This QUIT command caused
227 control to be returned to just after the place where q()
230 Notice that unlike QUIT, the ABORT inside function a() halts
231 the processing of statements from the input source (myfile.cal).
232 Because calc was not interactive, ABORT causes calc to exit.
247 > <==== calc interactive prompt
249 because the '-i' calc causes ABORT to drop into an
250 interactive prompt. However typing a QUIT or ABORT
251 at the interactive prompt level will always calc to exit,
252 even when calc is invoked with '-i'.
254 Also observe that both of these commands:
256 cat myfile.cal | calc
257 cat myfile.cal | calc -i
269 The ABORT inside function a() halts the processing of statements
270 from the input source (standard input). Because standard input
271 is not a terminal, using '-i' does not force it to drop into
272 an interactive prompt.
274 If one were to type in the contents of myfile.cal interactively,
277 > print "start of myfile.cal";
279 > define q() {quit "quit from q()"; print "end of q()"}
281 > define a() {abort "abort from a()"}
284 > {print "start #1"; if (x > 1) q()} print "after #1";
288 > {print "start #2"; if (x > 1) a()} print "after #2";
291 > {print "start #3"; if (x > 1) quit "quit from 3rd statement"}
293 quit from 3rd statement
295 The ABORT from within the a() function returned control to
296 the interactive level.
298 The QUIT (after the if (x > 1) ...) will cause calc to exit
299 because it was given at the interactive prompt level.
305 Also see the help topic:
307 statement flow control and declaration statements
308 usage how to invoke the calc command and calc -options