mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
40 lines
844 B
Plaintext
40 lines
844 B
Plaintext
NAME
|
|
swap - swap values of two variables
|
|
|
|
SYNOPSIS
|
|
swap(x,y)
|
|
|
|
TYPES
|
|
x, y lvalues, any type
|
|
|
|
return null value
|
|
|
|
DESCRIPTION
|
|
swap(x,y) assigns the value of x to a temporary location, temp say,
|
|
assigns the value of x to y, and then assigns the value at temp to y.
|
|
|
|
swap(x,y) should not be used if the current value of one of the
|
|
variables is a component of the value of the other; for example, after:
|
|
|
|
A = list(1,2,3); swap(A, A[[1]]);
|
|
|
|
A will have the value 2, but a three-member list remains in memory
|
|
with no method within calc of recalling the list or freeing the
|
|
memory used.
|
|
|
|
EXAMPLE
|
|
> x = 3/4; y = "abc"; print x, y, swap(x,y), x, y
|
|
.75 abc abc .75
|
|
|
|
> A = list(1,2,3); mat B[3] = {4,5,6}; swap(A[[1]], B[1]); print A[[1]], B[1]
|
|
5 2
|
|
|
|
LIMITS
|
|
none
|
|
|
|
LIBRARY
|
|
none
|
|
|
|
SEE ALSO
|
|
assign
|