mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Release calc version 2.12.0.3
This commit is contained in:
28
help/address
28
help/address
@@ -38,7 +38,7 @@ DESCRIPTION
|
||||
&X with that component or element depends only on the continued existence
|
||||
of the matrix or object. For example, after
|
||||
|
||||
> mat A[3]
|
||||
; mat A[3]
|
||||
|
||||
the addresses &A[0], &A[1], &A[2] locate the three elements
|
||||
of the matrix specified by A until another value is assigned to A, etc.
|
||||
@@ -60,15 +60,15 @@ DESCRIPTION
|
||||
results refer to octets in the same block or existing components of the
|
||||
same matrix or object. For example, immediately after
|
||||
|
||||
> mat A[10]
|
||||
> p = &A[5]
|
||||
; mat A[10]
|
||||
; p = &A[5]
|
||||
|
||||
it is permitted to use expressions like p + 4, p - 5, p++ .
|
||||
|
||||
Strings defined literally have fixed addresses, e.g., after
|
||||
|
||||
> p = &"abc"
|
||||
> A = "abc"
|
||||
; p = &"abc"
|
||||
; A = "abc"
|
||||
|
||||
the address &*A of the value of A will be equal to p.
|
||||
|
||||
@@ -78,7 +78,7 @@ DESCRIPTION
|
||||
be useable only while the variables retain these defined values.
|
||||
For example, after
|
||||
|
||||
> B = C = strcat("a", "bc");
|
||||
; B = C = strcat("a", "bc");
|
||||
|
||||
&*B and &*C will be different. If p is defined by p = &*B, p should
|
||||
not be used after a new value is assigned to B, or B ceases to exist,
|
||||
@@ -91,9 +91,9 @@ DESCRIPTION
|
||||
so long as the number remains associated with at least one function or
|
||||
lvalue. For example, after
|
||||
|
||||
> x = 27;
|
||||
> y = 3 * 9;
|
||||
> define f(a) = 27 + a;
|
||||
; x = 27;
|
||||
; y = 3 * 9;
|
||||
; define f(a) = 27 + a;
|
||||
|
||||
the three occurrences of 27 have the same address which may be displayed
|
||||
by any of &27, &*x, &*y and &f(0). If x and y are assigned
|
||||
@@ -109,13 +109,13 @@ DESCRIPTION
|
||||
non-zero value for a will be assigned to different addresses as can be
|
||||
seen from printing &*A, &*B, &*C after
|
||||
|
||||
> A = f(2); B = f(2); C = f(2);
|
||||
; A = f(2); B = f(2); C = f(2);
|
||||
|
||||
(the case of f(0) is exceptional since 27 + 0 simply copies the 27
|
||||
rather than creating a new number value). Here it is clearly more
|
||||
efficient to use
|
||||
|
||||
> A = B = C = f(2);
|
||||
; A = B = C = f(2);
|
||||
|
||||
which, not only performs the addition in f() only once, but stores the
|
||||
number values for A, B and C at the same address.
|
||||
@@ -160,7 +160,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
dereference, isptr
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -176,8 +176,8 @@ SEE ALSO
|
||||
## 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.4 $
|
||||
## @(#) $Id: address,v 29.4 2006/05/07 07:25:46 chongo Exp $
|
||||
## @(#) $Revision: 29.5 $
|
||||
## @(#) $Id: address,v 29.5 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/address,v $
|
||||
##
|
||||
## Under source code control: 1997/09/06 20:03:34
|
||||
|
57
help/blkcpy
57
help/blkcpy
@@ -19,7 +19,7 @@ TYPES
|
||||
DESCRIPTION
|
||||
A call to:
|
||||
|
||||
blkcpy(dst, src, num, dsi, ssi)
|
||||
blkcpy(dst, src, num, dsi, ssi)
|
||||
|
||||
attempts to copy 'num' consecutive items (octets or values) starting
|
||||
from the source item 'src' with index 'ssi'. By default, 'num'
|
||||
@@ -27,7 +27,7 @@ DESCRIPTION
|
||||
|
||||
A call to:
|
||||
|
||||
copy(src, dst, ssi, num, dsi)
|
||||
copy(src, dst, ssi, num, dsi)
|
||||
|
||||
does the same thing, but with a different arg order.
|
||||
|
||||
@@ -40,30 +40,30 @@ DESCRIPTION
|
||||
|
||||
The following pairs of source-type, destination-type are permitted:
|
||||
|
||||
block to
|
||||
int
|
||||
block
|
||||
matrix
|
||||
file
|
||||
block to
|
||||
int
|
||||
block
|
||||
matrix
|
||||
file
|
||||
|
||||
matrix to
|
||||
block
|
||||
matrix
|
||||
list
|
||||
matrix to
|
||||
block
|
||||
matrix
|
||||
list
|
||||
|
||||
string to
|
||||
block
|
||||
file
|
||||
string to
|
||||
block
|
||||
file
|
||||
|
||||
list to
|
||||
list
|
||||
matrix
|
||||
list to
|
||||
list
|
||||
matrix
|
||||
|
||||
file to
|
||||
block
|
||||
file to
|
||||
block
|
||||
|
||||
int to
|
||||
block
|
||||
int to
|
||||
block
|
||||
|
||||
In the above table, int refers to integer values. However if a
|
||||
rational value is supplied, only the numerator is copied.
|
||||
@@ -79,11 +79,11 @@ DESCRIPTION
|
||||
sufficient memory allocated for the copying. For example, to copy
|
||||
a matrix M of size 100 to a newly created list, one may use:
|
||||
|
||||
L = makelist(100);
|
||||
copy(M, L);
|
||||
; L = makelist(100);
|
||||
; copy(M, L);
|
||||
or:
|
||||
L = makelist(100);
|
||||
blkcpy(L, M);
|
||||
; L = makelist(100);
|
||||
; blkcpy(L, M);
|
||||
|
||||
For copying from a block B (named or unnamed), the total number of octets
|
||||
available for copying is taken to the the datalen for that block,
|
||||
@@ -114,7 +114,6 @@ EXAMPLE
|
||||
; B
|
||||
chunksize = 256, maxsize = 256, datalen = 4
|
||||
01020304
|
||||
>
|
||||
; blkcpy(B,A)
|
||||
; B
|
||||
chunksize = 256, maxsize = 256, datalen = 8
|
||||
@@ -191,7 +190,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
blk, mat, file, list, str
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -207,8 +206,8 @@ SEE ALSO
|
||||
## 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.3 $
|
||||
## @(#) $Id: blkcpy,v 29.3 2006/05/07 07:25:46 chongo Exp $
|
||||
## @(#) $Revision: 29.4 $
|
||||
## @(#) $Id: blkcpy,v 29.4 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/blkcpy,v $
|
||||
##
|
||||
## Under source code control: 1997/04/05 14:08:50
|
||||
|
@@ -13,9 +13,9 @@ DESCRIPTION
|
||||
may occur when activity is resumed by an fg command after a ctrl-Z
|
||||
interrupt, or by any of the three commands:
|
||||
|
||||
> !stty echo
|
||||
> !stty -cbreak
|
||||
> !stty echo -cbreak
|
||||
; !stty echo
|
||||
; !stty -cbreak
|
||||
; !stty echo -cbreak
|
||||
|
||||
EXAMPLE
|
||||
; calc_tty();
|
||||
@@ -26,7 +26,7 @@ LIBRARY
|
||||
SEE ALSO
|
||||
none
|
||||
|
||||
## Copyright (C) 2000 Ernest Bowen
|
||||
## Copyright (C) 2000-2006 Ernest Bowen
|
||||
##
|
||||
## 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
|
||||
@@ -42,8 +42,8 @@ SEE ALSO
|
||||
## 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.2 $
|
||||
## @(#) $Id: calc_tty,v 29.2 2006/05/07 07:25:46 chongo Exp $
|
||||
## @(#) $Revision: 29.3 $
|
||||
## @(#) $Id: calc_tty,v 29.3 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/calc_tty,v $
|
||||
##
|
||||
## Under source code control: 2000/12/14 01:33:00
|
||||
|
296
help/command
296
help/command
@@ -19,26 +19,26 @@ Command sequence
|
||||
define function(params) { body }
|
||||
define function(params) = expression
|
||||
|
||||
This first form defines a full function which can consist
|
||||
of declarations followed by many statements which implement
|
||||
the function.
|
||||
This first form defines a full function which can consist
|
||||
of declarations followed by many statements which implement
|
||||
the function.
|
||||
|
||||
The second form defines a simple function which calculates
|
||||
the specified expression value from the specified parameters.
|
||||
The expression cannot be a statement. However, the comma
|
||||
and question mark operators can be useful. Examples of
|
||||
simple functions are:
|
||||
The second form defines a simple function which calculates
|
||||
the specified expression value from the specified parameters.
|
||||
The expression cannot be a statement. However, the comma
|
||||
and question mark operators can be useful. Examples of
|
||||
simple functions are:
|
||||
|
||||
define sumcubes(a, b) = a^3 + b^3
|
||||
define pimod(a) = a % pi()
|
||||
define printnum(a, n, p)
|
||||
{
|
||||
if (p == 0) {
|
||||
print a: "^": n, "=", a^n;
|
||||
} else {
|
||||
print a: "^": n, "mod", p, "=", pmod(a,n,p);
|
||||
}
|
||||
define sumcubes(a, b) = a^3 + b^3
|
||||
define pimod(a) = a % pi()
|
||||
define printnum(a, n, p)
|
||||
{
|
||||
if (p == 0) {
|
||||
print a: "^": n, "=", a^n;
|
||||
} else {
|
||||
print a: "^": n, "mod", p, "=", pmod(a,n,p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
read calc commands
|
||||
@@ -48,45 +48,45 @@ Command sequence
|
||||
read filename
|
||||
read -once filename
|
||||
|
||||
This reads definitions from the specified calc resource filename.
|
||||
This reads definitions from the specified calc resource filename.
|
||||
|
||||
In the 1st and 2nd forms, if var is a global variable string
|
||||
value, then the value of that variable is used as a filename.
|
||||
In the 1st and 2nd forms, if var is a global variable string
|
||||
value, then the value of that variable is used as a filename.
|
||||
|
||||
The following is equivalent to read lucas.cal or read "lucas.cal":
|
||||
The following is equivalent to read lucas.cal or read "lucas.cal":
|
||||
|
||||
global var = "lucas.cal";
|
||||
read $var;
|
||||
global var = "lucas.cal";
|
||||
read $var;
|
||||
|
||||
In the 3rd or 4th forms, the filename argument is treated
|
||||
as a literal string, not a variable. In these forms, the
|
||||
name can be quoted if desired.
|
||||
In the 3rd or 4th forms, the filename argument is treated
|
||||
as a literal string, not a variable. In these forms, the
|
||||
name can be quoted if desired.
|
||||
|
||||
The calculator uses the CALCPATH environment variable to
|
||||
search through the specified directories for the filename,
|
||||
similarly to the use of the PATH environment variable.
|
||||
If CALCPATH is not defined, then a default path which is
|
||||
usually ":/usr/local/lib/calc" is used.
|
||||
The calculator uses the CALCPATH environment variable to
|
||||
search through the specified directories for the filename,
|
||||
similarly to the use of the PATH environment variable.
|
||||
If CALCPATH is not defined, then a default path which is
|
||||
usually ":/usr/local/lib/calc" is used.
|
||||
|
||||
The ".cal" extension is defaulted for input files, so that
|
||||
if "filename" is not found, then "filename.cal" is then
|
||||
searched for. The contents of the filename are command
|
||||
sequences which can consist of expressions to evaluate or
|
||||
functions to define, just like at the top level command level.
|
||||
The ".cal" extension is defaulted for input files, so that
|
||||
if "filename" is not found, then "filename.cal" is then
|
||||
searched for. The contents of the filename are command
|
||||
sequences which can consist of expressions to evaluate or
|
||||
functions to define, just like at the top level command level.
|
||||
|
||||
When -once is given, the read command acts like the regular
|
||||
read expect that it will ignore filename if is has been
|
||||
previously read.
|
||||
When -once is given, the read command acts like the regular
|
||||
read expect that it will ignore filename if is has been
|
||||
previously read.
|
||||
|
||||
The read -once form is particularly useful in a resource
|
||||
file that needs to read a 2nd resource file. By using the
|
||||
READ -once command, one will not reread that 2nd resource
|
||||
file, nor will once risk entering into a infinite READ loop
|
||||
(where that 2nd resource file directly or indirectly does
|
||||
a READ of the first resource file).
|
||||
The read -once form is particularly useful in a resource
|
||||
file that needs to read a 2nd resource file. By using the
|
||||
READ -once command, one will not reread that 2nd resource
|
||||
file, nor will once risk entering into a infinite READ loop
|
||||
(where that 2nd resource file directly or indirectly does
|
||||
a READ of the first resource file).
|
||||
|
||||
If the -m mode disallows opening of files for reading,
|
||||
this command will be disabled.
|
||||
If the -m mode disallows opening of files for reading,
|
||||
this command will be disabled.
|
||||
|
||||
|
||||
write calc commands
|
||||
@@ -94,29 +94,29 @@ Command sequence
|
||||
write $var
|
||||
write filename
|
||||
|
||||
This writes the values of all global variables to the
|
||||
specified filename, in such a way that the file can be
|
||||
later read in order to recreate the variable values.
|
||||
For speed reasons, values are written as hex fractions.
|
||||
This command currently only saves simple types, so that
|
||||
matrices, lists, and objects are not saved. Function
|
||||
definitions are also not saved.
|
||||
This writes the values of all global variables to the
|
||||
specified filename, in such a way that the file can be
|
||||
later read in order to recreate the variable values.
|
||||
For speed reasons, values are written as hex fractions.
|
||||
This command currently only saves simple types, so that
|
||||
matrices, lists, and objects are not saved. Function
|
||||
definitions are also not saved.
|
||||
|
||||
In the 1st form, if var is a global variable string
|
||||
value, then the value of that variable is used as a filename.
|
||||
In the 1st form, if var is a global variable string
|
||||
value, then the value of that variable is used as a filename.
|
||||
|
||||
The following is equivalent to write dump.out or
|
||||
write "dump.out":
|
||||
The following is equivalent to write dump.out or
|
||||
write "dump.out":
|
||||
|
||||
global var = "dump.out";
|
||||
write $var;
|
||||
global var = "dump.out";
|
||||
write $var;
|
||||
|
||||
In the 2nd form, the filename argument is treated as a literal
|
||||
string, not a variable. In this form, the name can be quoted
|
||||
if desired.
|
||||
In the 2nd form, the filename argument is treated as a literal
|
||||
string, not a variable. In this form, the name can be quoted
|
||||
if desired.
|
||||
|
||||
If the -m mode disallows opening of files for writing,
|
||||
this command will be disabled.
|
||||
If the -m mode disallows opening of files for writing,
|
||||
this command will be disabled.
|
||||
|
||||
|
||||
quit or exit
|
||||
@@ -126,36 +126,35 @@ Command sequence
|
||||
exit
|
||||
exit string
|
||||
|
||||
The action of these commands depends on where they are used.
|
||||
At the interactive level, they will cause calc it edit.
|
||||
This is the normal way to leave the calculator. In any
|
||||
other use, they will stop the current calculation as if
|
||||
an error had occurred.
|
||||
The action of these commands depends on where they are used.
|
||||
At the interactive level, they will cause calc it edit.
|
||||
This is the normal way to leave the calculator. In any
|
||||
other use, they will stop the current calculation as if
|
||||
an error had occurred.
|
||||
|
||||
If a string is given, then the string is printed as the reason
|
||||
for quitting, otherwise a general quit message is printed.
|
||||
The routine name and line number which executed the quit is
|
||||
also printed in either case.
|
||||
If a string is given, then the string is printed as the reason
|
||||
for quitting, otherwise a general quit message is printed.
|
||||
The routine name and line number which executed the quit is
|
||||
also printed in either case.
|
||||
|
||||
Exit is an alias for quit.
|
||||
Exit is an alias for quit.
|
||||
|
||||
Quit is useful when a routine detects invalid arguments,
|
||||
in order to stop a calculation cleanly. For example,
|
||||
for a square root routine, an error can be given if the
|
||||
supplied parameter was a negative number, as in:
|
||||
Quit is useful when a routine detects invalid arguments,
|
||||
in order to stop a calculation cleanly. For example,
|
||||
for a square root routine, an error can be given if the
|
||||
supplied parameter was a negative number, as in:
|
||||
|
||||
define mysqrt(n)
|
||||
{
|
||||
if (! isnum(n))
|
||||
quit "non-numeric argument";
|
||||
if (n < 0)
|
||||
quit "Negative argument";
|
||||
return sqrt(n);
|
||||
}
|
||||
|
||||
See 'more information about abort and quit' below for
|
||||
more information.
|
||||
define mysqrt(n)
|
||||
{
|
||||
if (! isnum(n))
|
||||
quit "non-numeric argument";
|
||||
if (n < 0)
|
||||
quit "Negative argument";
|
||||
return sqrt(n);
|
||||
}
|
||||
|
||||
See 'more information about abort and quit' below for
|
||||
more information.
|
||||
|
||||
|
||||
abort
|
||||
@@ -163,12 +162,12 @@ Command sequence
|
||||
abort
|
||||
abort string
|
||||
|
||||
This command behaves like QUIT except that it will attempt
|
||||
to return to the interactive level if permitted, otherwise
|
||||
calc exit.
|
||||
This command behaves like QUIT except that it will attempt
|
||||
to return to the interactive level if permitted, otherwise
|
||||
calc exit.
|
||||
|
||||
See 'more information about abort and quit' below for
|
||||
more information.
|
||||
See 'more information about abort and quit' below for
|
||||
more information.
|
||||
|
||||
|
||||
change current directory
|
||||
@@ -176,45 +175,45 @@ Command sequence
|
||||
cd
|
||||
cd dir
|
||||
|
||||
Change the current directory to 'dir'. If 'dir' is ommitted,
|
||||
change the current directory to the home directory, if $HOME
|
||||
is set in the environment.
|
||||
Change the current directory to 'dir'. If 'dir' is ommitted,
|
||||
change the current directory to the home directory, if $HOME
|
||||
is set in the environment.
|
||||
|
||||
|
||||
show information
|
||||
----------------
|
||||
show item
|
||||
|
||||
This command displays some information where 'item' is
|
||||
one of the following:
|
||||
This command displays some information where 'item' is
|
||||
one of the following:
|
||||
|
||||
blocks unfreed named blocks
|
||||
builtin built in functions
|
||||
config config parameters and values
|
||||
constants cache of numeric constants
|
||||
custom custom functions if calc -C was used
|
||||
errors new error-values created
|
||||
files open files, file position and sizes
|
||||
function user-defined functions
|
||||
globaltypes global variables
|
||||
objfunctions possible object functions
|
||||
objtypes defined objects
|
||||
opcodes func internal opcodes for function `func'
|
||||
sizes size in octets of calc value types
|
||||
realglobals numeric global variables
|
||||
statics unscoped static variables
|
||||
numbers calc number cache
|
||||
redcdata REDC data defined
|
||||
strings calc string cache
|
||||
literals calc literal cache
|
||||
blocks unfreed named blocks
|
||||
builtin built in functions
|
||||
config config parameters and values
|
||||
constants cache of numeric constants
|
||||
custom custom functions if calc -C was used
|
||||
errors new error-values created
|
||||
files open files, file position and sizes
|
||||
function user-defined functions
|
||||
globaltypes global variables
|
||||
objfunctions possible object functions
|
||||
objtypes defined objects
|
||||
opcodes func internal opcodes for function `func'
|
||||
sizes size in octets of calc value types
|
||||
realglobals numeric global variables
|
||||
statics unscoped static variables
|
||||
numbers calc number cache
|
||||
redcdata REDC data defined
|
||||
strings calc string cache
|
||||
literals calc literal cache
|
||||
|
||||
Only the first 4 characters of item are examined, so:
|
||||
Only the first 4 characters of item are examined, so:
|
||||
|
||||
show globals
|
||||
show global
|
||||
show glob
|
||||
show globals
|
||||
show global
|
||||
show glob
|
||||
|
||||
do the same thing.
|
||||
do the same thing.
|
||||
|
||||
|
||||
calc help
|
||||
@@ -222,25 +221,24 @@ Command sequence
|
||||
help $var
|
||||
help name
|
||||
|
||||
This displays a help related to 'name' or general
|
||||
help of none is given.
|
||||
This displays a help related to 'name' or general
|
||||
help of none is given.
|
||||
|
||||
In the 1st form, if var is a global variable string
|
||||
value, then the value of that variable is used as a name.
|
||||
In the 1st form, if var is a global variable string
|
||||
value, then the value of that variable is used as a name.
|
||||
|
||||
The following is equivalent to help command or help "command":
|
||||
The following is equivalent to help command or help "command":
|
||||
|
||||
global var = "command";
|
||||
help $var;
|
||||
global var = "command";
|
||||
help $var;
|
||||
|
||||
In the 2nd form, the filename argument is treated as a literal
|
||||
string, not a variable. In this form, the name can be quoted
|
||||
if desired.
|
||||
In the 2nd form, the filename argument is treated as a literal
|
||||
string, not a variable. In this form, the name can be quoted
|
||||
if desired.
|
||||
|
||||
|
||||
=-=
|
||||
|
||||
|
||||
more information about abort and quit
|
||||
=====================================
|
||||
|
||||
@@ -291,7 +289,7 @@ Command sequence
|
||||
after statment #1
|
||||
start statment #2
|
||||
abort from a()
|
||||
> <==== calc interactive prompt
|
||||
; <==== calc interactive prompt
|
||||
|
||||
because the '-i' calc causes ABORT to drop into an
|
||||
interactive prompt. However typing a QUIT or ABORT
|
||||
@@ -321,21 +319,21 @@ Command sequence
|
||||
If one were to type in the contents of myfile.cal interactively,
|
||||
calc will produce:
|
||||
|
||||
> print "start of myfile.cal";
|
||||
; print "start of myfile.cal";
|
||||
start of myfile.cal
|
||||
> define q() {quit "quit from q()"; print "end of q()"}
|
||||
; define q() {quit "quit from q()"; print "end of q()"}
|
||||
q() defined
|
||||
> define a() {abort "abort from a()"}
|
||||
; define a() {abort "abort from a()"}
|
||||
a() defined
|
||||
> x = 3;
|
||||
> {print "start #1"; if (x > 1) q()} print "after #1";
|
||||
; x = 3;
|
||||
; {print "start #1"; if (x > 1) q()} print "after #1";
|
||||
start statment #1
|
||||
quit from q()
|
||||
after statment #1
|
||||
> {print "start #2"; if (x > 1) a()} print "after #2";
|
||||
; {print "start #2"; if (x > 1) a()} print "after #2";
|
||||
start statment #2
|
||||
abort from a()
|
||||
> {print "start #3"; if (x > 1) quit "quit from 3rd statement"}
|
||||
; {print "start #3"; if (x > 1) quit "quit from 3rd statement"}
|
||||
start #3
|
||||
quit from 3rd statement
|
||||
|
||||
@@ -345,16 +343,14 @@ Command sequence
|
||||
The QUIT (after the if (x > 1) ...) will cause calc to exit
|
||||
because it was given at the interactive prompt level.
|
||||
|
||||
|
||||
=-=
|
||||
|
||||
|
||||
Also see the help topic:
|
||||
|
||||
statement flow control and declaration statements
|
||||
usage how to invoke the calc command and calc -options
|
||||
statement flow control and declaration statements
|
||||
usage how to invoke the calc command and calc -options
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -370,8 +366,8 @@ Command sequence
|
||||
## 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.3 $
|
||||
## @(#) $Id: command,v 29.3 2006/05/20 10:01:33 chongo Exp $
|
||||
## @(#) $Revision: 29.5 $
|
||||
## @(#) $Id: command,v 29.5 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/command,v $
|
||||
##
|
||||
## Under source code control: 1991/07/21 04:37:17
|
||||
|
195
help/config
195
help/config
@@ -1,12 +1,24 @@
|
||||
Configuration parameters
|
||||
NAME
|
||||
config - configuration parameters
|
||||
|
||||
Configuration parameters affect how the calculator performs certain
|
||||
SYNOPSIS
|
||||
config(parameter [,value])
|
||||
|
||||
TYPES
|
||||
parameter string
|
||||
value int, string, config state
|
||||
|
||||
return config state
|
||||
|
||||
DESCRIPTION
|
||||
The config() builtin affects how the calculator performs certain
|
||||
operations. Among features that are controlled by these parameters
|
||||
are the accuracy of some calculations, the displayed format of results,
|
||||
the choice from possible alternative algorithms, and whether or not
|
||||
debugging information is displayed. The parameters are
|
||||
read or set using the "config" built-in function; they remain in effect
|
||||
until their values are changed by a config or equivalent instruction.
|
||||
|
||||
The following parameters can be specified:
|
||||
|
||||
"all" all configuration values listed below
|
||||
@@ -53,6 +65,7 @@ Configuration parameters
|
||||
"compile_custom" TRUE=>calc was compiled with custom functions
|
||||
"allow_custom" TRUE=>custom functions are enabled
|
||||
"version" Read-only calc version
|
||||
"baseb" bits in calculation base, a read-only value
|
||||
|
||||
The "all" config value allows one to save/restore the configuration
|
||||
set of values. The return of:
|
||||
@@ -120,9 +133,6 @@ Configuration parameters
|
||||
config("tilde", 0) disable roundoff tilde printing
|
||||
config("tab", "off") disable leading tab printing
|
||||
|
||||
|
||||
Detailed config descriptions
|
||||
|
||||
=-=
|
||||
|
||||
config("trace", bitflag)
|
||||
@@ -254,16 +264,36 @@ Detailed config descriptions
|
||||
runs in a time of O(N^2). The second method is a recursive and
|
||||
complicated method which runs in a time of O(N^1.585). The argument
|
||||
for these parameters is the number of binary words at which the
|
||||
second algorithm begins to be used. The minimum value is 2, and
|
||||
second algorithm begins to be used. The minimum value is 2, and
|
||||
the maximum value is very large. If 2 is used, then the recursive
|
||||
algorithm is used all the way down to single digits, which becomes
|
||||
slow since the recursion overhead is high. If a number such as
|
||||
1000000 is used, then the recursive algorithm is never used, causing
|
||||
calculations for large numbers to slow down. For a typical example
|
||||
on a 386, the two algorithms are about equal in speed for a value
|
||||
of 20, which is about 100 decimal digits. A value of zero resets
|
||||
the parameter back to its default value. Usually there is no need
|
||||
to change these parameters.
|
||||
1000000 is used, then the recursive algorithm is almost never used,
|
||||
causing calculations for large numbers to slow down.
|
||||
|
||||
Units refer to internal calculation digits where each digit
|
||||
is BASEB bits in length. The value of BASEB is returned by
|
||||
config("baseb").
|
||||
|
||||
The default value for config("sq2") is 3388. This default was
|
||||
established on a 1.8GHz AMD 32-bit CPU of ~3406 BogoMIPS when
|
||||
the two algorithms are about equal in speed. For that CPU test,
|
||||
config("baseb") was 32. This means that by default numbers up to
|
||||
(3388*32)+31 = 108447 bits in length (< 32645 decinal digits) use
|
||||
the 1st algorithm, for squaring.
|
||||
|
||||
The default value for config("mul2") is 1780. This default was
|
||||
established on a 1.8GHz AMD 32-bit CPU of ~3406 BogoMIPS when
|
||||
the two algorithms are about equal in speed. For that CPU test,
|
||||
config("baseb") was 32. This means that by default numbers up to
|
||||
(1779*32)+31 = 56927 bits in length (< 17137 decinal digits) use
|
||||
the 1st algorithm, for multiplication.
|
||||
|
||||
A value of zero resets the parameter back to their default values.
|
||||
|
||||
The value of 1 and values < 0 are reserved for future use.
|
||||
|
||||
Usually there is no need to change these parameters.
|
||||
|
||||
=-=
|
||||
|
||||
@@ -277,6 +307,23 @@ Detailed config descriptions
|
||||
which avoids divisions. The argument for pow2 is the size of the
|
||||
modulus at which the second algorithm begins to be used.
|
||||
|
||||
Units refer to internal calculation digits where each digit
|
||||
is BASEB bits in length. The value of BASEB is returned by
|
||||
config("baseb").
|
||||
|
||||
The default value for config("pow2") is 176. This default was
|
||||
established on a 1.8GHz AMD 32-bit CPU of ~3406 BogoMIPS when
|
||||
the two algorithms are about equal in speed. For that CPU test,
|
||||
config("baseb") was 32. This means that by default numbers up to
|
||||
(176*32)+31 = 5663 bits in length (< 1704 decinal digits) use the
|
||||
1st algorithm, for calculating powers modulo another number.
|
||||
|
||||
A value of zero resets the parameter back to their default values.
|
||||
|
||||
The value of 1 and values < 0 are reserved for future use.
|
||||
|
||||
Usually there is no need to change these parameters.
|
||||
|
||||
=-=
|
||||
|
||||
config("redc2", int)
|
||||
@@ -289,6 +336,23 @@ Detailed config descriptions
|
||||
O(N^1.585). The argument for redc2 is the size of the modulus at
|
||||
which the second algorithm begins to be used.
|
||||
|
||||
Units refer to internal calculation digits where each digit
|
||||
is BASEB bits in length. The value of BASEB is returned by
|
||||
config("baseb").
|
||||
|
||||
The default value for config("redc2") is 220. This default was
|
||||
established as 5/4 (the historical ratio of config("pow2") to
|
||||
config("pow2")) of the config("pow2") value. This means that if
|
||||
config("baseb") is 32, then by default numbers up to (220*32)+31 =
|
||||
7071 bits in length (< 2128 decinal digits) use the REDC algorithm,
|
||||
for calculating powers modulo another number.
|
||||
|
||||
A value of zero resets the parameter back to their default values.
|
||||
|
||||
The value of 1 and values < 0 are reserved for future use.
|
||||
|
||||
Usually there is no need to change these parameters.
|
||||
|
||||
=-=
|
||||
|
||||
config("tilde", boolean)
|
||||
@@ -560,11 +624,12 @@ Detailed config descriptions
|
||||
3 During execution, allow calc standard resource files
|
||||
to output additional debugging information.
|
||||
|
||||
The value for config("resource_debug") in both oldstd and newstd is 3,
|
||||
but if calc is invoked with the -d flag, its initial value is zero.
|
||||
Thus, if calc is started without the -d flag, until config("resource_debug")
|
||||
is changed, a message will be output when a function is defined
|
||||
either interactively or during the reading of a file.
|
||||
The value for config("resource_debug") in both oldstd and newstd
|
||||
is 3, but if calc is invoked with the -d flag, its initial value
|
||||
is zero. Thus, if calc is started without the -d flag, until
|
||||
config("resource_debug") is changed, a message will be output when
|
||||
a function is defined either interactively or during the reading of
|
||||
a file.
|
||||
|
||||
The name config("lib_debug") is equivalent to config("resource_debug")
|
||||
and is included for backward compatibility.
|
||||
@@ -601,7 +666,7 @@ Detailed config descriptions
|
||||
A quit of abort without an argument does not display a message when
|
||||
invoked at the interactive level.
|
||||
|
||||
By deafult, "verbose_quit" is false.
|
||||
By default, "verbose_quit" is false.
|
||||
|
||||
=-=
|
||||
|
||||
@@ -756,7 +821,95 @@ Detailed config descriptions
|
||||
|
||||
This config parameter is read-only and cannot be set.
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
=-=
|
||||
|
||||
config("baseb") <== NOTE: This is a read-only config value
|
||||
|
||||
Returns the number of bits in the fundamental base in which
|
||||
internal calculations are performed. For example, a value of
|
||||
32 means that calc will perform many internal calculations in
|
||||
base 2^32 with digits that are 32 bits in length.
|
||||
|
||||
For libcalc programmers, this is the value of BASEB as defined
|
||||
in the zmath.h header file.
|
||||
|
||||
This config parameter is read-only and cannot be set.
|
||||
|
||||
EXAMPLE
|
||||
; current_cfg = config("all");
|
||||
; config("tilde", off),;
|
||||
; config("calc_debug", 15),;
|
||||
; config("all") == current_cfg
|
||||
0
|
||||
; config("all", current_cfg),;
|
||||
; config("all") == current_cfg
|
||||
1
|
||||
|
||||
; config("version")
|
||||
"2.12.0"
|
||||
|
||||
; config("all")
|
||||
mode "real"
|
||||
mode2 "off"
|
||||
display 20
|
||||
epsilon 0.00000000000000000001
|
||||
trace 0
|
||||
maxprint 16
|
||||
mul2 20
|
||||
sq2 20
|
||||
pow2 40
|
||||
redc2 50
|
||||
tilde 1
|
||||
tab 1
|
||||
quomod 0
|
||||
quo 2
|
||||
mod 0
|
||||
sqrt 24
|
||||
appr 24
|
||||
cfappr 0
|
||||
cfsim 8
|
||||
outround 24
|
||||
round 24
|
||||
leadzero 1
|
||||
fullzero 0
|
||||
maxscan 20
|
||||
prompt "; "
|
||||
more ";; "
|
||||
blkmaxprint 256
|
||||
blkverbose 0
|
||||
blkbase "hexadecimal"
|
||||
blkfmt "hd_style"
|
||||
resource_debug 3
|
||||
lib_debug 3
|
||||
calc_debug 0
|
||||
user_debug 0
|
||||
verbose_quit 0
|
||||
ctrl_d "virgin_eof"
|
||||
program "calc"
|
||||
basename "calc"
|
||||
windows 0
|
||||
cygwin 0
|
||||
compile_custom 1
|
||||
allow_custom 0
|
||||
version "2.12.0"
|
||||
baseb 32
|
||||
|
||||
; display()
|
||||
20
|
||||
; config("display", 50),;
|
||||
; display()
|
||||
50
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LINK LIBRARY
|
||||
n/a
|
||||
|
||||
SEE ALSO
|
||||
usage, custom, custom_cal, usage, epsilon, display
|
||||
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -772,8 +925,8 @@ Detailed config descriptions
|
||||
## 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.10 $
|
||||
## @(#) $Id: config,v 29.10 2004/07/27 23:45:52 chongo Exp $
|
||||
## @(#) $Revision: 29.15 $
|
||||
## @(#) $Id: config,v 29.15 2006/06/11 07:22:05 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/config,v $
|
||||
##
|
||||
## Under source code control: 1991/07/21 04:37:17
|
||||
|
56
help/define
56
help/define
@@ -30,17 +30,17 @@ DESCRIPTION
|
||||
For example, suppose a function f and a global variable A have been
|
||||
defined by:
|
||||
|
||||
define f(x) = (x = 3);
|
||||
global mat A[3];
|
||||
; define f(x) = (x = 3);
|
||||
; global mat A[3];
|
||||
|
||||
If g() is a function that evaluates to 2:
|
||||
|
||||
f(A[g()]);
|
||||
; f(A[g()]);
|
||||
|
||||
assigns the value of A[2] to the parameter x and then assigns the
|
||||
value 3 to x:
|
||||
|
||||
f(`A[g()]);
|
||||
; f(`A[g()]);
|
||||
|
||||
has essentially the effect of assigning A[2] as an lvalue to x and
|
||||
then assigning the value 3 to A[2]. (Very old versions of calc
|
||||
@@ -79,7 +79,7 @@ DESCRIPTION
|
||||
|
||||
If the expr is omitted from an expression definition, as in:
|
||||
|
||||
define h() = ;
|
||||
; define h() = ;
|
||||
|
||||
any call to the function will evaluate the arguments and return the
|
||||
null value.
|
||||
@@ -105,11 +105,11 @@ DESCRIPTION
|
||||
|
||||
After fname has been defined, the definition may be removed by the command:
|
||||
|
||||
undefine fname
|
||||
; undefine fname
|
||||
|
||||
The definitions of all user-defined functions may be removed by:
|
||||
|
||||
undefine *
|
||||
; undefine *
|
||||
|
||||
If bit 0 of config("resource_debug") is set and the define command is
|
||||
at interactive level, a message saying that fname has been defined
|
||||
@@ -120,8 +120,8 @@ DESCRIPTION
|
||||
The identifiers used for the parameters in a function definition do
|
||||
not form part of the completed definition. For example,
|
||||
|
||||
define f(a,b) = a + b;
|
||||
define g(alpha, beta) = alpha + beta;
|
||||
; define f(a,b) = a + b;
|
||||
; define g(alpha, beta) = alpha + beta;
|
||||
|
||||
result in identical code for the functions f, g.
|
||||
|
||||
@@ -129,8 +129,8 @@ DESCRIPTION
|
||||
function are displayed on completion of its definition, parameters
|
||||
being specified by names used in the definition. For example:
|
||||
|
||||
> config("trace", 8),
|
||||
> define f(a,b) = a + b
|
||||
; config("trace", 8),
|
||||
; define f(a,b) = a + b
|
||||
0: PARAMADDR a
|
||||
2: PARAMADDR b
|
||||
4: ADD
|
||||
@@ -140,7 +140,7 @@ DESCRIPTION
|
||||
The opcodes may also be displayed later using the show opcodes command;
|
||||
parameters will be specified by indices instead of by names. For example:
|
||||
|
||||
> show opco f
|
||||
; show opco f
|
||||
0: PARAMADDR 0
|
||||
2: PARAMADDR 1
|
||||
4: ADD
|
||||
@@ -168,19 +168,19 @@ DESCRIPTION
|
||||
EXAMPLE
|
||||
; define f(a,b) = 2*a + b;
|
||||
; define g(alpha, beta)
|
||||
>> {
|
||||
>> local a, pi2;
|
||||
>>
|
||||
>> pi2 = 2 * pi();
|
||||
>> a = sin(alpha % pi2);
|
||||
>> if (a > 0.0) {
|
||||
>> return a*beta;
|
||||
>> }
|
||||
>> if (beta > 0.0) {
|
||||
>> a *= cos(-beta % pi2);
|
||||
>> }
|
||||
>> return a;
|
||||
>> }
|
||||
;; {
|
||||
;; local a, pi2;
|
||||
;;
|
||||
;; pi2 = 2 * pi();
|
||||
;; a = sin(alpha % pi2);
|
||||
;; if (a > 0.0) {
|
||||
;; return a*beta;
|
||||
;; }
|
||||
;; if (beta > 0.0) {
|
||||
;; a *= cos(-beta % pi2);
|
||||
;; }
|
||||
;; return a;
|
||||
;; }
|
||||
|
||||
LIMITS
|
||||
The number of arguments in a function-call cannot exceed 100.
|
||||
@@ -191,7 +191,7 @@ LIBRARY
|
||||
SEE ALSO
|
||||
param, variable, undefine, show
|
||||
|
||||
## Copyright (C) 2000 David I. Bell, Landon Curt Noll and Ernest Bowen
|
||||
## Copyright (C) 2000-2006 David I. Bell, Landon Curt Noll and Ernest Bowen
|
||||
##
|
||||
## 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
|
||||
@@ -207,8 +207,8 @@ SEE ALSO
|
||||
## 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.4 $
|
||||
## @(#) $Id: define,v 29.4 2006/05/07 07:25:46 chongo Exp $
|
||||
## @(#) $Revision: 29.5 $
|
||||
## @(#) $Id: define,v 29.5 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/define,v $
|
||||
##
|
||||
##
|
||||
|
@@ -33,16 +33,17 @@ DESCRIPTION
|
||||
structure rather than the structure identified by X. For example,
|
||||
suppose B has been created by
|
||||
|
||||
mat B[3] = {1,2,3}
|
||||
; mat B[3] = {1,2,3}
|
||||
|
||||
then
|
||||
A = *B = {4,5,6}
|
||||
|
||||
; A = *B = {4,5,6}
|
||||
|
||||
will assign the values 4,5,6 to the elements of a copy of B, which
|
||||
will then become the value of A, so that the values of A and B will
|
||||
be different. On the other hand,
|
||||
|
||||
A = B = {4,5,6}
|
||||
; A = B = {4,5,6}
|
||||
|
||||
will result in A and B having the same value.
|
||||
|
||||
@@ -51,9 +52,9 @@ DESCRIPTION
|
||||
The * operator may be iterated with suitable sequences of pointer-valued
|
||||
lvalues. For example, after
|
||||
|
||||
> global a, b, c;
|
||||
> b = &a;
|
||||
> c = &b;
|
||||
; global a, b, c;
|
||||
; b = &a;
|
||||
; c = &b;
|
||||
|
||||
**c returns the lvalue a; ***c returns the value of a.
|
||||
|
||||
@@ -81,7 +82,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
address, isptr
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -97,8 +98,8 @@ SEE ALSO
|
||||
## 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.3 $
|
||||
## @(#) $Id: dereference,v 29.3 2006/05/07 07:25:46 chongo Exp $
|
||||
## @(#) $Revision: 29.4 $
|
||||
## @(#) $Id: dereference,v 29.4 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/dereference,v $
|
||||
##
|
||||
## Under source code control: 1997/09/06 20:03:34
|
||||
|
28
help/digit
28
help/digit
@@ -28,11 +28,11 @@ DESCRIPTION
|
||||
left of the "decimal" point; the digit d_n at position n contributes
|
||||
additively d_n * b^n to the value of x. For example,
|
||||
|
||||
d_2 d_1 d_0 . d_-1 d_-2
|
||||
; d_2 d_1 d_0 . d_-1 d_-2
|
||||
|
||||
represents the number
|
||||
|
||||
d_2 * b^2 + d_1 * b + d0 + d_-1 * b^-1 + d_-2 * b^-2
|
||||
; d_2 * b^2 + d_1 * b + d0 + d_-1 * b^-1 + d_-2 * b^-2
|
||||
|
||||
The sequence of digits has to be infinite if den(x) has a prime factor
|
||||
which is not a factor of the base b. In cases where the representation
|
||||
@@ -53,30 +53,30 @@ DESCRIPTION
|
||||
With base-b digits for x as explained above, the integer whose base-b
|
||||
representation is
|
||||
|
||||
b_n+k-1 b_n_k-2 ... b_n,
|
||||
; b_n+k-1 b_n_k-2 ... b_n,
|
||||
|
||||
i.e. the k digits with last digit b_n, is given by
|
||||
|
||||
digit(b^-r * x, q, b^k)
|
||||
; digit(b^-r * x, q, b^k)
|
||||
|
||||
if r and q satisfy n = q * b + r.
|
||||
|
||||
|
||||
EXAMPLE
|
||||
> a = 123456.789
|
||||
> for (n = 6; n >= -6; n++) print digit(a, n),; print
|
||||
; a = 123456.789
|
||||
; for (n = 6; n >= -6; n++) print digit(a, n),; print
|
||||
0 1 2 3 4 5 6 7 8 9 0 0 0
|
||||
|
||||
> for (n = 6; n >= -6; n--) print digit(a, n, 100),; print
|
||||
; for (n = 6; n >= -6; n--) print digit(a, n, 100),; print
|
||||
0 0 0 0 12 34 56 78 90 0 0 0 0
|
||||
|
||||
> for (n = 6; n >= -6; n--) print digit(a, n, 256),; print
|
||||
; for (n = 6; n >= -6; n--) print digit(a, n, 256),; print
|
||||
0 0 0 0 1 226 64 201 251 231 108 139 67
|
||||
|
||||
> for (n = 1; n >= -12; n++) print digit(10/7, n),; print
|
||||
> 0 1 4 2 8 5 7 1 4 2 8 5 7 1
|
||||
; for (n = 1; n >= -12; n++) print digit(10/7, n),; print
|
||||
; 0 1 4 2 8 5 7 1 4 2 8 5 7 1
|
||||
|
||||
> print digit(10/7, -7e1000, 1e6)
|
||||
; print digit(10/7, -7e1000, 1e6)
|
||||
428571
|
||||
|
||||
LIMITS
|
||||
@@ -92,7 +92,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
bit
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -108,8 +108,8 @@ SEE ALSO
|
||||
## 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.4 $
|
||||
## @(#) $Id: digit,v 29.4 2000/12/17 12:27:58 chongo Exp $
|
||||
## @(#) $Revision: 29.5 $
|
||||
## @(#) $Id: digit,v 29.5 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/digit,v $
|
||||
##
|
||||
## Under source code control: 1995/10/03 10:40:01
|
||||
|
@@ -21,7 +21,6 @@ Environment variables
|
||||
|
||||
The CALCBINDINGS file searches the CALCPATH as well.
|
||||
|
||||
|
||||
CALCRC
|
||||
|
||||
On startup (unless -h or -q was given on the command
|
||||
@@ -105,8 +104,8 @@ Environment variables
|
||||
## 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.4 $
|
||||
## @(#) $Id: environment,v 29.4 2006/05/07 07:22:20 chongo Exp $
|
||||
## @(#) $Revision: 29.5 $
|
||||
## @(#) $Id: environment,v 29.5 2006/06/10 13:01:09 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/environment,v $
|
||||
##
|
||||
## Under source code control: 1991/07/23 05:47:25
|
||||
|
@@ -31,7 +31,7 @@ EXAMPLE
|
||||
; fgetfield(f)
|
||||
"Beta"
|
||||
; fgetfield(f)
|
||||
>
|
||||
|
||||
; freopen(f, "w")
|
||||
; fputstr(f, " Alpha ", "Beta")
|
||||
; freopen(f, "r")
|
||||
@@ -51,7 +51,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
fgetstr, fputstr, fgets, fputs, fopen, files, fprintf
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -67,8 +67,8 @@ SEE ALSO
|
||||
## 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.3 $
|
||||
## @(#) $Id: fgetfield,v 29.3 2006/05/07 07:25:46 chongo Exp $
|
||||
## @(#) $Revision: 29.4 $
|
||||
## @(#) $Id: fgetfield,v 29.4 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fgetfield,v $
|
||||
##
|
||||
## Under source code control: 1996/04/30 03:05:17
|
||||
|
@@ -36,7 +36,6 @@ EXAMPLE
|
||||
"Gamma
|
||||
Delta"
|
||||
; fgetstr(f)
|
||||
>
|
||||
|
||||
LIMITS
|
||||
none - XXX - is this correct?
|
||||
@@ -47,7 +46,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
fputstr, fgetword, fgets, fputs, fopen, files, fprintf
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -63,8 +62,8 @@ SEE ALSO
|
||||
## 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.3 $
|
||||
## @(#) $Id: fgetstr,v 29.3 2006/05/07 07:25:46 chongo Exp $
|
||||
## @(#) $Revision: 29.4 $
|
||||
## @(#) $Id: fgetstr,v 29.4 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fgetstr,v $
|
||||
##
|
||||
## Under source code control: 1996/04/30 03:05:17
|
||||
|
16
help/files
16
help/files
@@ -29,16 +29,16 @@ DESCRIPTION
|
||||
is assumed to be an open file opened in an unknown mode. Calc
|
||||
will try to read and write to this file when directed.
|
||||
|
||||
Consider the following commands:
|
||||
Consider the following commands shell commands:
|
||||
|
||||
$ echo "A line of text in the file on descriptor 5" > datafile
|
||||
$ calc 5<datafile
|
||||
echo "A line of text in the file on descriptor 5" > datafile
|
||||
calc 5<datafile
|
||||
|
||||
then one could do the following:
|
||||
|
||||
> files(5)
|
||||
; files(5)
|
||||
FILE 5 "descriptor[5]" (unknown_mode, pos 0)
|
||||
> fgetline(files(5))
|
||||
; fgetline(files(5))
|
||||
"A line of text in the file on descriptor 5"
|
||||
|
||||
EXAMPLE
|
||||
@@ -68,7 +68,7 @@ SEE ALSO
|
||||
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -84,8 +84,8 @@ SEE ALSO
|
||||
## 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.3 $
|
||||
## @(#) $Id: files,v 29.3 2006/05/07 07:25:46 chongo Exp $
|
||||
## @(#) $Revision: 29.4 $
|
||||
## @(#) $Id: files,v 29.4 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/files,v $
|
||||
##
|
||||
## Under source code control: 1995/03/04 11:33:19
|
||||
|
@@ -26,7 +26,7 @@ EXAMPLE
|
||||
; fgetstr(f)
|
||||
"Beta"
|
||||
; fgetstr(f)
|
||||
>
|
||||
|
||||
; fputstr(f, "Gamma")
|
||||
Error 72
|
||||
|
||||
@@ -39,7 +39,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
fgetstr, fgetfield, fgets, fputs, fopen, files, fprintf
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -55,8 +55,8 @@ SEE ALSO
|
||||
## 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.3 $
|
||||
## @(#) $Id: fputstr,v 29.3 2006/05/07 07:25:46 chongo Exp $
|
||||
## @(#) $Revision: 29.4 $
|
||||
## @(#) $Id: fputstr,v 29.4 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fputstr,v $
|
||||
##
|
||||
## Under source code control: 1996/04/30 03:05:18
|
||||
|
@@ -19,7 +19,6 @@ EXAMPLE
|
||||
1 2 15
|
||||
; freeredc()
|
||||
; show redc
|
||||
>
|
||||
|
||||
LIMITS
|
||||
none
|
||||
@@ -30,7 +29,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
free, freeglobals, freestatics
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -46,8 +45,8 @@ SEE ALSO
|
||||
## 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.3 $
|
||||
## @(#) $Id: freeredc,v 29.3 2006/05/07 07:25:46 chongo Exp $
|
||||
## @(#) $Revision: 29.4 $
|
||||
## @(#) $Id: freeredc,v 29.4 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/freeredc,v $
|
||||
##
|
||||
## Under source code control: 1997/09/06 20:03:35
|
||||
|
38
help/indices
38
help/indices
@@ -26,26 +26,26 @@ DESCRIPTION
|
||||
double-bracket index of the item found.
|
||||
|
||||
EXAMPLE
|
||||
> mat M[2,3,1:5]
|
||||
; mat M[2,3,1:5]
|
||||
|
||||
> indices(M, 11)
|
||||
list (3 elements, 2 nonzero):
|
||||
[[0]] = 0
|
||||
[[1]] = 2
|
||||
[[2]] = 2
|
||||
; indices(M, 11)
|
||||
list (3 elements, 2 nonzero):
|
||||
[[0]] = 0
|
||||
[[1]] = 2
|
||||
[[2]] = 2
|
||||
|
||||
> A = assoc();
|
||||
; A = assoc();
|
||||
|
||||
> A["cat", "dog"] = "fight";
|
||||
> A[2,3,5,7] = "primes";
|
||||
> A["square", 3] = 9
|
||||
; A["cat", "dog"] = "fight";
|
||||
; A[2,3,5,7] = "primes";
|
||||
; A["square", 3] = 9
|
||||
|
||||
> indices(A, search(A, "primes"))
|
||||
list (4 elements, 4 nonzero):
|
||||
[[0]] = 2
|
||||
[[1]] = 3
|
||||
[[2]] = 5
|
||||
[[3]] = 7
|
||||
; indices(A, search(A, "primes"))
|
||||
list (4 elements, 4 nonzero):
|
||||
[[0]] = 2
|
||||
[[1]] = 3
|
||||
[[2]] = 5
|
||||
[[3]] = 7
|
||||
|
||||
LIMITS
|
||||
abs(index) < 2^31
|
||||
@@ -57,7 +57,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
assoc, mat
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -73,8 +73,8 @@ SEE ALSO
|
||||
## 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.2 $
|
||||
## @(#) $Id: indices,v 29.2 2000/06/07 14:02:33 chongo Exp $
|
||||
## @(#) $Revision: 29.3 $
|
||||
## @(#) $Id: indices,v 29.3 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/indices,v $
|
||||
##
|
||||
## Under source code control: 1999/11/16 08:02:03
|
||||
|
@@ -42,8 +42,8 @@ ABORT opcodes
|
||||
the calculation is never completed and to stop it, an interruption
|
||||
(on many systems, by ctrl-C) will be necessary.
|
||||
|
||||
> config("trace", 8),
|
||||
> define f(x) {local s; while (x) {s += x--} return s}
|
||||
; config("trace", 8),
|
||||
; define f(x) {local s; while (x) {s += x--} return s}
|
||||
0: DEBUG line 2
|
||||
2: PARAMADDR x
|
||||
4: JUMPZ 19
|
||||
@@ -68,7 +68,7 @@ ABORT opcodes
|
||||
{s += x--} loop. In interactive mode, with ^C indicating
|
||||
input of ctrl-C, the displayed output is as in:
|
||||
|
||||
> f(-1)
|
||||
; f(-1)
|
||||
^C
|
||||
[Abort level 1]
|
||||
"f": line 2: Calculation aborted at statement boundary
|
||||
@@ -77,7 +77,7 @@ ABORT opcodes
|
||||
Changing config("trace") to achieve this, and defining g(x) with
|
||||
the same definition as for f(x) gives:
|
||||
|
||||
> define g(x) {local s; while (x) {s += x--} return s}
|
||||
; define g(x) {local s; while (x) {s += x--} return s}
|
||||
0: PARAMADDR x
|
||||
2: JUMPZ 15
|
||||
4: LOCALADDR s
|
||||
@@ -94,13 +94,15 @@ ABORT opcodes
|
||||
|
||||
If g(-1) is called, two interrupts are necessary, as in:
|
||||
|
||||
> g(-1)
|
||||
; g(-1)
|
||||
^C
|
||||
[Abort level 1]
|
||||
^C
|
||||
[Abort level 2]
|
||||
"g": Calculation aborted in opcode
|
||||
|
||||
## Copyright (C) 1999-2006 David I. Bell, Landon Curt Noll and Ernest Bowen
|
||||
##
|
||||
## 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.
|
||||
@@ -115,8 +117,8 @@ ABORT opcodes
|
||||
## 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.4 $
|
||||
## @(#) $Id: interrupt,v 29.4 2000/07/17 15:38:52 chongo Exp $
|
||||
## @(#) $Revision: 29.5 $
|
||||
## @(#) $Id: interrupt,v 29.5 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/interrupt,v $
|
||||
##
|
||||
## Under source code control: 1991/07/21 04:37:21
|
||||
|
20
help/isptr
20
help/isptr
@@ -23,13 +23,13 @@ DESCRIPTION
|
||||
strings and real numbers.
|
||||
|
||||
EXAMPLE
|
||||
> a = "abc", b = 3, B = blk()
|
||||
> p1 = &B[1]
|
||||
> p2 = &a
|
||||
> p3 = &*a
|
||||
> p4 = &*b
|
||||
> print isptr(a), isptr(p1), isptr(p2), isptr(p3), isptr(p4)
|
||||
0 1 2 3 4
|
||||
; a = "abc", b = 3, B = blk()
|
||||
; p1 = &B[1]
|
||||
; p2 = &a
|
||||
; p3 = &*a
|
||||
; p4 = &*b
|
||||
; print isptr(a), isptr(p1), isptr(p2), isptr(p3), isptr(p4)
|
||||
0 1 2 3 4
|
||||
|
||||
LIMITS
|
||||
none
|
||||
@@ -40,7 +40,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
isnum, isstr, isblk, isoctet
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -56,8 +56,8 @@ SEE ALSO
|
||||
## 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.2 $
|
||||
## @(#) $Id: isptr,v 29.2 2000/06/07 14:02:33 chongo Exp $
|
||||
## @(#) $Revision: 29.3 $
|
||||
## @(#) $Id: isptr,v 29.3 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isptr,v $
|
||||
##
|
||||
## Under source code control: 1997/09/06 20:03:35
|
||||
|
13
help/issq
13
help/issq
@@ -16,6 +16,15 @@ DESCRIPTION
|
||||
|
||||
return 1, otherwise return 0.
|
||||
|
||||
Note that issq() works on rational values, so:
|
||||
|
||||
issq(25/16) == 1
|
||||
|
||||
If you want to test for prefect square integers, you need to exclude
|
||||
non-integer values before you test:
|
||||
|
||||
isint(curds) && issq(curds)
|
||||
|
||||
EXAMPLE
|
||||
; print issq(25), issq(3), issq(0)
|
||||
1 0 1
|
||||
@@ -52,8 +61,8 @@ SEE ALSO
|
||||
## 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.3 $
|
||||
## @(#) $Id: issq,v 29.3 2006/05/07 07:25:46 chongo Exp $
|
||||
## @(#) $Revision: 29.4 $
|
||||
## @(#) $Id: issq,v 29.4 2006/06/04 21:12:23 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/issq,v $
|
||||
##
|
||||
## Under source code control: 1994/10/21 02:21:31
|
||||
|
151
help/mat
151
help/mat
@@ -79,10 +79,10 @@ DESCRIPTION
|
||||
simple assignments, as in A[0,0] = 1, A[0,2] = 2;
|
||||
|
||||
If the index-range is left blank but an initializer list is specified
|
||||
as in
|
||||
as in:
|
||||
|
||||
mat A[] = {1, 2 }
|
||||
B = mat[] = {1, , 3, }
|
||||
; mat A[] = {1, 2 }
|
||||
; B = mat[] = {1, , 3, }
|
||||
|
||||
the matrix created is one-dimensional. If the list contains a
|
||||
positive number n of values or blanks, the result is as if the
|
||||
@@ -92,11 +92,13 @@ DESCRIPTION
|
||||
B[2] = 3. The specification mat[] = { } creates the same as mat[1].
|
||||
|
||||
If the index-range is left blank and no initializer list is specified,
|
||||
as in mat C[] or C = mat[], the matrix assigned to C has zero
|
||||
dimension; this has one element C[]. To assign a value using "= { ...}"
|
||||
at the same time as creating C, parentheses are required as in
|
||||
(mat[]) = {value} or (mat C[]) = {value}. Later a value may be
|
||||
assigned to C[] by C[] = value or C = {value}.
|
||||
as in mat C[] or C = mat[], the matrix assigned to C has zero
|
||||
dimension; this has one element C[].
|
||||
|
||||
To assign a value using "= { ...}" at the same time as creating C,
|
||||
parentheses are required as in (mat[]) = {value} or (mat C[]) =
|
||||
{value}. Later a value may be assigned to C[] by C[] = value or
|
||||
C = {value}.
|
||||
|
||||
The value assigned at any time to any element of a matrix can be of
|
||||
any type - number, string, list, matrix, object of previously specified
|
||||
@@ -106,10 +108,11 @@ DESCRIPTION
|
||||
If an element of a matrix is a structure for which indices or an
|
||||
object element specifier is required, an element of that structure is
|
||||
referred to by appropriate uses of [ ] or ., and so on if an element
|
||||
of that element is required. For example, one may have an expressions
|
||||
like
|
||||
of that element is required.
|
||||
|
||||
A[1,2][3].alpha[2];
|
||||
For example, one may have an expressions like:
|
||||
|
||||
; A[1,2][3].alpha[2];
|
||||
|
||||
if A[1,2][3].alpha is a list with at least three elements, A[1,2][3] is
|
||||
an object of a type like obj {alpha, beta}, A[1,2] is a matrix of
|
||||
@@ -165,7 +168,7 @@ DESCRIPTION
|
||||
|
||||
So that when one defines a 2D matrix such as:
|
||||
|
||||
mat X[2,3] = {1,2,3,4,5,6}
|
||||
; mat X[2,3] = {1,2,3,4,5,6}
|
||||
|
||||
then printing X results in:
|
||||
|
||||
@@ -174,20 +177,20 @@ DESCRIPTION
|
||||
|
||||
The default printing may be restored by
|
||||
|
||||
undefine mat_print;
|
||||
; undefine mat_print;
|
||||
|
||||
The keyword "mat" followed by two or more index-range-lists returns a
|
||||
matrix with indices specified by the first list, whose elements are
|
||||
matrices as determined by the later index-range-lists. For
|
||||
example mat[2][3] is a 2-element matrix, each of whose elements has
|
||||
as its value a 3-element matrix. Values may be assigned to the
|
||||
elements of the innermost matrices by nested = {...} operations as in
|
||||
elements of the innermost matrices by nested = {...} operations as in
|
||||
|
||||
mat [2][3] = {{1,2,3},{4,5,6}}
|
||||
; mat [2][3] = {{1,2,3},{4,5,6}}
|
||||
|
||||
An example of the use of mat with a declarator is
|
||||
|
||||
global mat A B [2,3], C [4]
|
||||
; global mat A B [2,3], C [4]
|
||||
|
||||
This creates, if they do not already exist, three global variables with
|
||||
names A, B, C, and assigns to A and B the value mat[2,3] and to C mat[4].
|
||||
@@ -284,21 +287,21 @@ DESCRIPTION
|
||||
when it is a divisor), int an integer, rnd a rounding-type
|
||||
specifier integer, real a real number.
|
||||
|
||||
num * A
|
||||
A * num
|
||||
A / num
|
||||
- A
|
||||
conj(A)
|
||||
A << int, A >> int
|
||||
scale(A, int)
|
||||
round(A, int, rnd)
|
||||
bround(A, int, rnd)
|
||||
appr(A, real, rnd)
|
||||
int(A)
|
||||
frac(A)
|
||||
A // real
|
||||
A % real
|
||||
A ^ int
|
||||
num * A
|
||||
A * num
|
||||
A / num
|
||||
- A
|
||||
conj(A)
|
||||
A << int, A >> int
|
||||
scale(A, int)
|
||||
round(A, int, rnd)
|
||||
bround(A, int, rnd)
|
||||
appr(A, real, rnd)
|
||||
int(A)
|
||||
frac(A)
|
||||
A // real
|
||||
A % real
|
||||
A ^ int
|
||||
|
||||
If A and B are one-dimensional of the same size dp(A, B) returns
|
||||
their dot-product, i.e. the sum of the products of corresponding
|
||||
@@ -344,56 +347,56 @@ DESCRIPTION
|
||||
in effect they are treated as linear arrays.
|
||||
|
||||
EXAMPLE
|
||||
> obj point {x,y}
|
||||
> mat A[5] = {1, 2+3i, "ab", mat[2] = {4,5}, obj point = {6,7}}
|
||||
> A
|
||||
mat [5] (5 elements, 5 nonzero):
|
||||
[0] = 1
|
||||
[1] = 2+3i
|
||||
[2] = "ab"
|
||||
[3] = mat [2] (2 elements, 2 nonzero)
|
||||
[4] = obj point {6, 7}
|
||||
; obj point {x,y}
|
||||
; mat A[5] = {1, 2+3i, "ab", mat[2] = {4,5}, obj point = {6,7}}
|
||||
; A
|
||||
mat [5] (5 elements, 5 nonzero):
|
||||
[0] = 1
|
||||
[1] = 2+3i
|
||||
[2] = "ab"
|
||||
[3] = mat [2] (2 elements, 2 nonzero)
|
||||
[4] = obj point {6, 7}
|
||||
|
||||
> print A[0], A[1], A[2], A[3][0], A[4].x
|
||||
1 2+3i ab 4 6
|
||||
; print A[0], A[1], A[2], A[3][0], A[4].x
|
||||
1 2+3i ab 4 6
|
||||
|
||||
> define point_add(a,b) = obj point = {a.x + b.x, a.y + b.y}
|
||||
point_add(a,b) defined
|
||||
; define point_add(a,b) = obj point = {a.x + b.x, a.y + b.y}
|
||||
point_add(a,b) defined
|
||||
|
||||
> mat [B] = {8, , "cd", mat[2] = {9,10}, obj point = {11,12}}
|
||||
> A + B
|
||||
; mat [B] = {8, , "cd", mat[2] = {9,10}, obj point = {11,12}}
|
||||
; A + B
|
||||
|
||||
mat [5] (5 elements, 5 nonzero):
|
||||
[0] = 9
|
||||
[1] = 2+3i
|
||||
[2] = "abcd"
|
||||
[3] = mat [2] (2 elements, 2 nonzero)
|
||||
[4] = obj point {17, 19}
|
||||
mat [5] (5 elements, 5 nonzero):
|
||||
[0] = 9
|
||||
[1] = 2+3i
|
||||
[2] = "abcd"
|
||||
[3] = mat [2] (2 elements, 2 nonzero)
|
||||
[4] = obj point {17, 19}
|
||||
|
||||
> mat C[2,2] = {1,2,3,4}
|
||||
> C^10
|
||||
; mat C[2,2] = {1,2,3,4}
|
||||
; C^10
|
||||
|
||||
mat [2,2] (4 elements, 4 nonzero):
|
||||
[0,0] = 4783807
|
||||
[0,1] = 6972050
|
||||
[1,0] = 10458075
|
||||
[1,1] = 15241882
|
||||
mat [2,2] (4 elements, 4 nonzero):
|
||||
[0,0] = 4783807
|
||||
[0,1] = 6972050
|
||||
[1,0] = 10458075
|
||||
[1,1] = 15241882
|
||||
|
||||
> C^-10
|
||||
; C^-10
|
||||
|
||||
mat [2,2] (4 elements, 4 nonzero):
|
||||
[0,0] = 14884.650390625
|
||||
[0,1] = -6808.642578125
|
||||
[1,0] = -10212.9638671875
|
||||
[1,1] = 4671.6865234375
|
||||
mat [2,2] (4 elements, 4 nonzero):
|
||||
[0,0] = 14884.650390625
|
||||
[0,1] = -6808.642578125
|
||||
[1,0] = -10212.9638671875
|
||||
[1,1] = 4671.6865234375
|
||||
|
||||
> mat A[4] = {1,2,3,4}, A * reverse(A);
|
||||
; mat A[4] = {1,2,3,4}, A * reverse(A);
|
||||
|
||||
mat [4] (4 elements, 4 nonzero):
|
||||
[0] = 4
|
||||
[1] = 6
|
||||
[2] = 6
|
||||
[3] = 4
|
||||
mat [4] (4 elements, 4 nonzero):
|
||||
[0] = 4
|
||||
[1] = 6
|
||||
[2] = 6
|
||||
[3] = 4
|
||||
|
||||
LIMITS
|
||||
The theoretical upper bound for the absolute values of indices is
|
||||
@@ -411,7 +414,7 @@ SEE ALSO
|
||||
isident, test, config, search, rsearch, reverse, copy, blkcpy, dp, cp,
|
||||
randperm, sort
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -427,8 +430,8 @@ SEE ALSO
|
||||
## 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.4 $
|
||||
## @(#) $Id: mat,v 29.4 2005/10/18 10:08:45 chongo Exp $
|
||||
## @(#) $Revision: 29.6 $
|
||||
## @(#) $Id: mat,v 29.6 2006/06/11 07:25:14 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/mat,v $
|
||||
##
|
||||
## Under source code control: 1991/07/21 04:37:22
|
||||
|
@@ -44,12 +44,12 @@ EXAMPLE
|
||||
"triangle side length <= 0"
|
||||
|
||||
; define area(a,b,c) {
|
||||
>> local s;
|
||||
>> if (!(a > 0) || !(b > 0) || !(c > 0)) return e1;
|
||||
>> s = (a + b + c)/2;
|
||||
>> if (s <= a || s <= b || s <= c) return newerror("Non-triangle sides");
|
||||
>> return sqrt(s * (s - a) * (s - b) * (s - c));
|
||||
>> }
|
||||
;; local s;
|
||||
;; if (!(a > 0) || !(b > 0) || !(c > 0)) return e1;
|
||||
;; s = (a + b + c)/2;
|
||||
;; if (s <= a || s <= b || s <= c) return newerror("Non-triangle sides");
|
||||
;; return sqrt(s * (s - a) * (s - b) * (s - c));
|
||||
;; }
|
||||
"area" defined
|
||||
|
||||
; A = area(8,2,5);
|
||||
@@ -86,8 +86,8 @@ SEE ALSO
|
||||
## 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.4 $
|
||||
## @(#) $Id: newerror,v 29.4 2006/05/21 07:31:46 chongo Exp $
|
||||
## @(#) $Revision: 29.5 $
|
||||
## @(#) $Id: newerror,v 29.5 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/newerror,v $
|
||||
##
|
||||
## Under source code control: 1996/04/30 03:39:56
|
||||
|
16
help/param
16
help/param
@@ -32,11 +32,11 @@ DESCRIPTION
|
||||
|
||||
EXAMPLE
|
||||
; define f() {
|
||||
>> local n, v = 0;
|
||||
>> for (n = 1; n <= param(0); n++)
|
||||
>> v += param(n)^2;
|
||||
>> return v;
|
||||
>> }
|
||||
;; local n, v = 0;
|
||||
;; for (n = 1; n <= param(0); n++)
|
||||
;; v += param(n)^2;
|
||||
;; return v;
|
||||
;; }
|
||||
|
||||
; print f(), f(1), f(1,2), f(1,2,3)
|
||||
0 1 5 14
|
||||
@@ -50,7 +50,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
argv, command
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -66,8 +66,8 @@ SEE ALSO
|
||||
## 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.3 $
|
||||
## @(#) $Id: param,v 29.3 2006/05/07 07:25:46 chongo Exp $
|
||||
## @(#) $Revision: 29.4 $
|
||||
## @(#) $Id: param,v 29.4 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/param,v $
|
||||
##
|
||||
## Under source code control: 1996/03/12 23:10:01
|
||||
|
@@ -27,7 +27,6 @@ EXAMPLE
|
||||
? 2 + 3
|
||||
25
|
||||
? end
|
||||
>
|
||||
|
||||
LIMITS
|
||||
none
|
||||
@@ -38,7 +37,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
XXX - fill in
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -54,8 +53,8 @@ SEE ALSO
|
||||
## 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.3 $
|
||||
## @(#) $Id: prompt,v 29.3 2006/05/07 07:25:46 chongo Exp $
|
||||
## @(#) $Revision: 29.4 $
|
||||
## @(#) $Id: prompt,v 29.4 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/prompt,v $
|
||||
##
|
||||
## Under source code control: 1995/12/18 12:34:58
|
||||
|
178
help/protect
178
help/protect
@@ -20,16 +20,16 @@ DESCRIPTION
|
||||
Each nonzero bit of the low eight bits of sts corresponds to a
|
||||
builtin kind of protection as follows:
|
||||
|
||||
bit value protection
|
||||
bit value protection
|
||||
|
||||
1 no assign to A
|
||||
2 no change of A by assignment
|
||||
4 no change of type value of A
|
||||
8 no error value for A
|
||||
16 no copy to A
|
||||
32 no relocation for A or its elements
|
||||
64 no assign from A
|
||||
128 no copy from A
|
||||
1 no assign to A
|
||||
2 no change of A by assignment
|
||||
4 no change of type value of A
|
||||
8 no error value for A
|
||||
16 no copy to A
|
||||
32 no relocation for A or its elements
|
||||
64 no assign from A
|
||||
128 no copy from A
|
||||
|
||||
For example, A having protection status 65 = 1 + 64 prevents
|
||||
execution of assignments of the forms A = expression and V = A
|
||||
@@ -55,10 +55,10 @@ DESCRIPTION
|
||||
For the purposes of this function, the depth of a global or local
|
||||
variable is zero; if A has depth d and the value of A is a list,
|
||||
matrix, object or association, its elements have depth d + 1.
|
||||
For example, after
|
||||
For example, after:
|
||||
|
||||
obj point {x,y}
|
||||
X = mat[3] = {1, list(2,3), mat[2] = {obj point, obj point} }
|
||||
; obj point {x,y}
|
||||
; X = mat[3] = {1, list(2,3), mat[2] = {obj point, obj point} }
|
||||
|
||||
X has depth 0; X[0], X[1] and X[2] have depth 1; X[1][0], X[1][1],
|
||||
X[2][0] and X[2][1] have depth 2; X[2][0].x, X[2][0].y, X[2][1].x
|
||||
@@ -85,14 +85,14 @@ DESCRIPTION
|
||||
|
||||
Users may define functions that return values with positive status, e.g.
|
||||
|
||||
define noassigntovalue(x) {protect(x,1); return x};
|
||||
S = noassigntovalue(42);
|
||||
; define noassigntovalue(x) {protect(x,1); return x};
|
||||
; S = noassigntovalue(42);
|
||||
|
||||
will result in S having the value 42 and no-assign-to protection.
|
||||
By using a backquote with a variable as argument, an even simpler
|
||||
function:
|
||||
|
||||
define noassignto(x) = protect(x, 1);
|
||||
; define noassignto(x) = protect(x, 1);
|
||||
|
||||
gives no-assign-to protection to the variable; i.e. noassignto(`A)
|
||||
achieves the same as protect(A,1).
|
||||
@@ -128,9 +128,9 @@ DESCRIPTION
|
||||
prevent any change in the content or size of the list.
|
||||
No-relocation protection of a block prevents reallocation of the
|
||||
memory used by a block and the freeing of a named block, For example,
|
||||
if a block B has maxsize 256, then after
|
||||
if a block B has maxsize 256, then after:
|
||||
|
||||
protect(B, 32);
|
||||
; protect(B, 32);
|
||||
|
||||
copy(A, B) will fail if the copying would cause size(B) to equal or
|
||||
exceed 256; if B is a named block, blkfree(B) will not be permitted.
|
||||
@@ -175,9 +175,10 @@ DESCRIPTION
|
||||
to have positive value. Then code for evaluating a function might
|
||||
include lines like
|
||||
|
||||
if (protect(A) & 1024 && B <= 0)
|
||||
return newerror("Prohibited assignment");
|
||||
A = B;
|
||||
; if (protect(A) & 1024 && B <= 0) {
|
||||
;; return newerror("Prohibited assignment");
|
||||
;; }
|
||||
; A = B;
|
||||
|
||||
When an operation forbidden by a particular bit in the protection
|
||||
status of A is attempted, an error value is created but unless this
|
||||
@@ -200,75 +201,76 @@ DESCRIPTION
|
||||
|
||||
EXAMPLE
|
||||
|
||||
> A = 27
|
||||
> protect(A,1)
|
||||
> A = 45
|
||||
> A
|
||||
27
|
||||
> strerror()
|
||||
"No-assign-to destination for assign"
|
||||
> protect(A,64)
|
||||
> protect(A)
|
||||
65
|
||||
> X = A
|
||||
> X
|
||||
0
|
||||
> strerror()
|
||||
"No-assign-from source for assign"
|
||||
> protect(A,-1)
|
||||
> protect(A)
|
||||
64
|
||||
> protect(A,4)
|
||||
> protect(A)
|
||||
68
|
||||
> A = "abc"
|
||||
> A
|
||||
27
|
||||
> strerror()
|
||||
"No-type-change destination for assign"
|
||||
> B = 45
|
||||
> swap(A,B)
|
||||
Error 10372
|
||||
> strerror()
|
||||
"No-assign-to-or-from argument for swap"
|
||||
> protect(A,-64)
|
||||
> protect(A)
|
||||
4
|
||||
> swap(A,B)
|
||||
> A
|
||||
45
|
||||
> B
|
||||
27
|
||||
; A = 27
|
||||
; protect(A,1)
|
||||
; A = 45
|
||||
; A
|
||||
27
|
||||
; strerror()
|
||||
"No-assign-to destination for assign"
|
||||
; protect(A,64)
|
||||
; protect(A)
|
||||
65
|
||||
; X = A
|
||||
; X
|
||||
0
|
||||
; strerror()
|
||||
"No-assign-from source for assign"
|
||||
; protect(A,-1)
|
||||
; protect(A)
|
||||
64
|
||||
; protect(A,4)
|
||||
; protect(A)
|
||||
68
|
||||
; A = "abc"
|
||||
; A
|
||||
27
|
||||
; strerror()
|
||||
"No-type-change destination for assign"
|
||||
; B = 45
|
||||
; swap(A,B)
|
||||
Error 10372
|
||||
; strerror()
|
||||
"No-assign-to-or-from argument for swap"
|
||||
; protect(A,-64)
|
||||
; protect(A)
|
||||
4
|
||||
; swap(A,B)
|
||||
; A
|
||||
45
|
||||
; B
|
||||
27
|
||||
|
||||
> A = mat[4] = {1,2,3,4}
|
||||
> B = list(5,6,7,8)
|
||||
> protect(A,16)
|
||||
> copy(B,A)
|
||||
Error 10226
|
||||
> strerror()
|
||||
"No-copy-to destination variable"
|
||||
; A = mat[4] = {1,2,3,4}
|
||||
; B = list(5,6,7,8)
|
||||
; protect(A,16)
|
||||
; copy(B,A)
|
||||
Error 10226
|
||||
; strerror()
|
||||
"No-copy-to destination variable"
|
||||
|
||||
> A = list(1,2,3)
|
||||
> protect(A,32)
|
||||
< append(A,4)
|
||||
Error 10402
|
||||
> strerror()
|
||||
"No-relocate for list append"
|
||||
; A = list(1,2,3)
|
||||
; protect(A,32)
|
||||
; append(A,4)
|
||||
Error 10402
|
||||
; strerror()
|
||||
"No-relocate for list append"
|
||||
|
||||
> A = blk(0,5)
|
||||
> copy("abc", A)
|
||||
> copy("de",A)
|
||||
Error 10229
|
||||
> strerror()
|
||||
"No-relocate destination variable"
|
||||
; A = blk(0,5)
|
||||
; copy("abc", A)
|
||||
; copy("de",A)
|
||||
Error 10229
|
||||
; strerror()
|
||||
"No-relocate destination variable"
|
||||
|
||||
; A = blk("alpha") = {1,2,3,4,5}
|
||||
; protect(A,0)
|
||||
; protect(*A, 16)
|
||||
; copy("abc", A)
|
||||
Error 10228
|
||||
; strerror()
|
||||
"No-copy-to destination named block"
|
||||
|
||||
> A = blk("alpha") = {1,2,3,4,5}
|
||||
> protect(A,0)
|
||||
< protect(*A, 16)
|
||||
< copy("abc", A)
|
||||
Error 10228
|
||||
> strerror()
|
||||
"No-copy-to destination named block"
|
||||
LIMITS
|
||||
none
|
||||
|
||||
@@ -278,7 +280,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
assign, copy, blk, error, errno, strerror
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -294,8 +296,8 @@ SEE ALSO
|
||||
## 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.4 $
|
||||
## @(#) $Id: protect,v 29.4 2006/05/19 15:12:57 chongo Exp $
|
||||
## @(#) $Revision: 29.5 $
|
||||
## @(#) $Id: protect,v 29.5 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/protect,v $
|
||||
##
|
||||
## Under source code control: 1997/07/10 22:38:44
|
||||
|
@@ -28,9 +28,9 @@ LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
ctime
|
||||
ctime, time
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -46,8 +46,8 @@ SEE ALSO
|
||||
## 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.3 $
|
||||
## @(#) $Id: runtime,v 29.3 2006/05/07 07:25:46 chongo Exp $
|
||||
## @(#) $Revision: 29.4 $
|
||||
## @(#) $Id: runtime,v 29.4 2006/06/04 18:24:33 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/runtime,v $
|
||||
##
|
||||
## Under source code control: 1996/03/12 23:10:01
|
||||
|
17
help/sleep
17
help/sleep
@@ -18,19 +18,18 @@ DESCRIPTION
|
||||
One kind of use is to slow down output to permit easier reading of
|
||||
results, as in:
|
||||
|
||||
> for (i = 0; i < 100; i++) {
|
||||
print sqrt(i);
|
||||
sleep(1/2);
|
||||
}
|
||||
; for (i = 0; i < 100; i++) {
|
||||
;; print sqrt(i);
|
||||
;; sleep(1/2);
|
||||
;; }
|
||||
|
||||
The following illustrates what happens if ctrl-C is hit 5 seconds
|
||||
after the first command:
|
||||
|
||||
> print sleep(20)
|
||||
; print sleep(20)
|
||||
|
||||
[Abort level 1]
|
||||
15
|
||||
>
|
||||
|
||||
EXAMPLE
|
||||
; sleep(1/3);
|
||||
@@ -42,7 +41,7 @@ LIBRARY
|
||||
SEE ALSO
|
||||
none
|
||||
|
||||
## Copyright (C) 2000 Ernest Bowen
|
||||
## Copyright (C) 2000-2006 Ernest Bowen
|
||||
##
|
||||
## 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
|
||||
@@ -58,8 +57,8 @@ SEE ALSO
|
||||
## 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.3 $
|
||||
## @(#) $Id: sleep,v 29.3 2006/05/07 07:25:46 chongo Exp $
|
||||
## @(#) $Revision: 29.4 $
|
||||
## @(#) $Id: sleep,v 29.4 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sleep,v $
|
||||
##
|
||||
## Under source code control: 2000/12/14 01:33:00
|
||||
|
20
help/test
20
help/test
@@ -35,15 +35,15 @@ DESCRIPTION
|
||||
Error-value or other types: never
|
||||
|
||||
EXAMPLE
|
||||
> print test(27), test(0), test("abc"), test("")
|
||||
1 0 1 0
|
||||
; print test(27), test(0), test("abc"), test("")
|
||||
1 0 1 0
|
||||
|
||||
> print test(mat[3] = {1,,2}), test(mat[2][2])
|
||||
1 0
|
||||
; print test(mat[3] = {1,,2}), test(mat[2][2])
|
||||
1 0
|
||||
|
||||
> A = list(0, 2, 0)
|
||||
> print test(A), test(pop(A)), test(A), test(pop(A)), test(A)
|
||||
1 0 1 1 0
|
||||
; A = list(0, 2, 0)
|
||||
; print test(A), test(pop(A)), test(A), test(pop(A)), test(A)
|
||||
1 0 1 1 0
|
||||
|
||||
LIMITS
|
||||
none
|
||||
@@ -55,7 +55,7 @@ SEE ALSO
|
||||
isassoc, isfile, isident, isnum, isint, islist, ismat, isnull, isobj,
|
||||
isreal, isstr, issimple, istype
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -71,8 +71,8 @@ SEE ALSO
|
||||
## 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.2 $
|
||||
## @(#) $Id: test,v 29.2 2000/06/07 14:02:33 chongo Exp $
|
||||
## @(#) $Revision: 29.3 $
|
||||
## @(#) $Id: test,v 29.3 2006/06/10 12:28:10 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/test,v $
|
||||
##
|
||||
## Under source code control: 1996/07/11 01:05:13
|
||||
|
@@ -64,24 +64,83 @@ Variable declarations
|
||||
static mat table[3] = {5, 6, 7};
|
||||
local obj point p1, p2;
|
||||
|
||||
There are no pointers in the calculator language, thus all
|
||||
arguments to user-defined functions are normally passed by value.
|
||||
This is true even for matrices, strings, and lists. In order
|
||||
to circumvent this, the '&' operator is allowed before a variable
|
||||
when it is an argument to a function. When this is done, the
|
||||
address of the variable is passed to the function instead of its
|
||||
value. This is true no matter what the type of the variable is.
|
||||
This allows for fast calls of functions when the passed variable
|
||||
is huge (such as a large array). However, the passed variable can
|
||||
then be changed by the function if the parameter is assigned into.
|
||||
The function being called does not need to know if the variable
|
||||
is being passed by value or by address.
|
||||
When working with user-defined functions, the syntax for passing an
|
||||
lvalue by reference rather than by value is to precede an expression
|
||||
for the lvalue by a backquote. For example, if the function invert is
|
||||
defined by:
|
||||
|
||||
Built-in functions and object functions always accept their
|
||||
arguments as addresses, thus there is no need to use '&' when
|
||||
calling built-in functions.
|
||||
define invert(x) {x = inverse(x)}
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
then invert(`A) achieves the effect of A = inverse(A). In other
|
||||
words, passing and argument of `variable (with a back-quote)
|
||||
will cause and changes to the function argument to be applied to
|
||||
the calling variable. Calling invert(A) (without the ` backquote)
|
||||
assigns inverse(A) to the temporary function parameter x and leaves
|
||||
A unchanged.
|
||||
|
||||
In an argument, a backquote before other than an lvalue is ignored.
|
||||
Consider, for example:
|
||||
|
||||
; define logplus(x,y,z) {return log(++x + ++y + ++z);}
|
||||
|
||||
; eh = 55;
|
||||
; mi = 25;
|
||||
; answer = logplus(eh, `mi, `17);
|
||||
|
||||
; print eh, mi, answer;
|
||||
55 26 2
|
||||
|
||||
The value of eh is was not changed because eh was used as
|
||||
an argument without a back-quote (`). However, mi was incremented
|
||||
because it was passed as `mi (with a back-quote). Passing 17
|
||||
(not an lvalue) as `17 has not effect on the value 17.
|
||||
|
||||
The back-quote should only be used before arguments to a function.
|
||||
In all other contexts, a backquote causes a compile error.
|
||||
|
||||
Another method is to pass the address of the lvalue explicitly and
|
||||
use the indirection operator * (star) to refer to the lvalue in the
|
||||
function body. Consider the following function:
|
||||
|
||||
; define ten(a) { *a = 10; }
|
||||
|
||||
; n = 17;
|
||||
; ten(n);
|
||||
; print n;
|
||||
17
|
||||
|
||||
; ten(`n);
|
||||
; print n;
|
||||
17
|
||||
|
||||
; ten(&n);
|
||||
; print n;
|
||||
10
|
||||
|
||||
Passing an argument with a & (ampersand) allows the tenmore()
|
||||
function to modify the calling variable:
|
||||
|
||||
; wa = tenmore(&vx);
|
||||
; print vx, wa;
|
||||
65 65
|
||||
|
||||
Great care should be taken when using a pointer to a local variable
|
||||
or element of a matrix, list or object, since the lvalue pointed to
|
||||
is deleted when evaluation of the function is completed or the lvalue
|
||||
whose value is the matrix, list or object is assigned another value.
|
||||
|
||||
As both of the above methods (using & arguments (ampersand) *value
|
||||
(star) function values or by using ` arguments (back quote) alone)
|
||||
copy the address rather than the value of the argument to the function
|
||||
parameter, they allow for faster calls of functions when the memory
|
||||
required for the value is huge (such as for a large matrix).
|
||||
|
||||
As the built-in functions and object functions always accept their
|
||||
arguments as addresses, there is no gain in using the backquote when
|
||||
calling these functions.
|
||||
|
||||
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -97,8 +156,8 @@ Variable declarations
|
||||
## 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.2 $
|
||||
## @(#) $Id: variable,v 29.2 2000/06/07 14:02:33 chongo Exp $
|
||||
## @(#) $Revision: 29.3 $
|
||||
## @(#) $Id: variable,v 29.3 2006/06/11 07:50:48 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/variable,v $
|
||||
##
|
||||
## Under source code control: 1991/07/21 04:37:25
|
||||
|
Reference in New Issue
Block a user