swapping can be done in various ways in various programming languages:
Perl:
($a, $b) = ($b, $a);
C - macro version (doesn't work with structs, or floats. pointers should be cast to int):
#define SWAP(x,y) x^=y;y^=x;x^=y;
vi: press "x" followed by "p", to swap to letters.
(Forth:)
Swaps the top 2 words on the stack. For example, we could define NEGATE as follows:
   : negate ( n -- -n )  swap - ;
(we need to SWAP to get the operands for - in the right order!)

Swap in is often used in books on C++ because it's an excellent example of why references are useful. Sometimes you need a function to change two variables, but a function can only return one value. For example:

void swap(int i, int j)
{

int hold = i;
i = j;
j = hold;
}

If you use this function, you'll find that the values of i and j afterwards have remained the same. However, if you pass i and j by reference:

void swap(int &i, int &j)
{

int hold = i;
i = j;
j = hold;
}

Because the actual address of the variable was passed to the function, not just its value, the variable will remain changed after the function completes.

Swap still hasn't finished its usefulness however. It also works as a great example of templates, since its a very small piece of code. A much less complicated example of templates than say the quicksort algorithm:

template<class T>
void swap(T &i, T &j)
{

T hold = i;
i = j;
j = hold;
}

Now you have a function that can swap any type of variable, without having to overload the function for every data type. However, for classes and structures you'll still have to through function template specialization, or by overloading the operators for that class or structure. (overloading the equal operator is preferable)

In financial markets, the exchange of interest payment on two different investments or loans of some form. The point of this is that different borrowers and lenders can get different conditions in different markets, and these are seldom uniform for different companies. This allows a comparative advantage (and sometimes a direct advantage, as in the example below); by exchanging interest payments, two companies can get better rates than each would by itself.

I'll go directly onto an example. In August 1981, IBM and World Bank conducted the first known currency swap ever. At this point, the World Bank (which is Swizz) wanted to borrow money in Swiss Francs, and IBM (which is a US company) wanted to borrow the same amount in US dollars. They both wanted to do this by issuing bonds. Due to rarity value, IBM could issue bonds in the Swiss Francs at the same rate as the Swiss Treasury - the best possible rate for SFr (Swiss Francs), while it had a fairly "bad" rate at home - US Treasury plus 45 basis points (0.45%). The situation was similar for World Bank. It could issue dollar-denominated bonds at a rate of US Treasury plus 40 basis points (0.40%), while it had to pay Swiss Treasury plus 20 basis points (0.20%) for SFr. As you can see, IBM could borrow what World Bank needed (SFr) cheaper than World Bank could, and World Bank could borrow what IBM wanted - USD (US dollars) at a cheaper rate than IBM. The stage was ripe for a swap - IBM had the loan World Bank wanted, and the reverse was also true.

If the World Bank borrowed USD and lent them to IBM at US Treasury + 40 bp (basis points) it would lose no money, and IBM would get a better rate. If IBM borrowed SFr and lent them to the World Bank at Swiss Treasury + 10 bp, IBM would make ten bp, and so would the World Bank. If both of these loans were done, it would result in a profit to IBM of 15 bp, and a profit to the World Bank of 10 bp. Thus, World Bank and IBM implemented something like this.

Since IBM and World Bank both borrowed the same amount of money (the principal), there is no need to do all the money exchange the above implies. A number of the terms cancel against each other. If the money was actually moved around, IBM would intially get (principal) from World Bank, and World Bank would intially get (principal) from IBM. These cancel each other out, so no money is transferred initially. Each due date, IBM would be paying (interest on USD + 40 bp) to World Bank and recieving (interest on SFr + 10 bp) from World Bank. World Bank would be paying (interest on SFr + 10 bp) and recieving (interest on USD + 40 bp). These terms can be expressed as a difference: IBM would be receiving or paying (depending on the sign) ((interest on USD + 40 bp) - (interest on SFr + 10 bp)), which simplifies to (interest on USD - interest on SFR + 30 bp). World Bank would be on the opposite end of the transaction. This is all the exchange of money there is. In a "normal" transaction, IBM and World Bank would be paying the principals to each other at the end of the terms; however, as the principals were not exchanged in the first place, this is not necessary.

Note that as principals are never exchanged, the risk involved is much smaller than in a loan of similar size. (In the transaction above, the risk of default was close to zero, as both IBM and World Bank had an AAA credit rating.)

Financial institutions quicly took an interest in this technique. They tried to facilitate it by (for a fee) finding partners for companies that wanted to partake in a swap. This proved fairly difficult - there was a lot of companies interested in swaps, but the swaps were often too different to be reconciled. This was handled by introducing a new party: The swap dealer. A swap dealer will function as a market maker by being willing to take either side in a swap, and adjusting rates depending on how much inventory it has on each side. Any risk not offset by selling opposing swaps is offset in the currency market. This provided the liquidity that allowed the swap market to really take off.

Today, there are two primary forms of swaps - currency swaps (similar to above), and interest rate swaps (between fixed and floating rates, both for borrowing and lending). Exotic swaps done over the counter (OTC) include such things as swapping a bond portfolio with a stock portfolio (done primarily to avoid capital gain taxes.) A futures contract can also be viewed as a form of swap.

swab = S = swap space

swap vt.

1. [techspeak] To move information from a fast-access memory to a slow-access memory (`swap out'), or vice versa (`swap in'). Often refers specifically to the use of disks as `virtual memory'. As pieces of data or program are needed, they are swapped into core for processing; when they are no longer needed they may be swapped out again. 2. The jargon use of these terms analogizes people's short-term memories with core. Cramming for an exam might be spoken of as swapping in. If you temporarily forget someone's name, but then remember it, your excuse is that it was swapped out. To `keep something swapped in' means to keep it fresh in your memory: "I reread the TECO manual every few months to keep it swapped in." If someone interrupts you just as you got a good idea, you might say "Wait a moment while I swap this out", implying that a piece of paper is your extra-somatic memory and that if you don't swap the idea out by writing it down it will get overwritten and lost as you talk. Compare page in, page out.

--The Jargon File version 4.3.1, ed. ESR, autonoded by rescdsk.

Swap (?), v. t. [imp. & p. p. Swapped (?); p. pr. & vb. n. Swapping.] [OE. swappen to strike; cf. E. to strike a bargain; perh. akin to E. sweep. Cf. Swap a blow, Swap, v. i.] [Written also swop.]

1.

To strike; -- with off.

[Obs. or Prov. Eng.] "Swap off his head!"

Chaucer.

2.

To exchange (usually two things of the same kind); to swop.

[Colloq.]

Miss Edgeworth.

 

© Webster 1913.


Swap, v. i. [Cf. Swap, v. t.]

1.

To fall or descend; to rush hastily or violently.

C. Richardson (Dict.).

All suddenly she swapt adown to ground. Chaucer.

2.

To beat the air, or ply the wings, with a sweeping motion or noise; to flap.

 

© Webster 1913.


Swap, n. [Cf. G. schwapp, n., a slap, swap, schwapp, schwapps, interj., slap! smack! and E. swap, v.t.]

1.

A blow; a stroke.

[Obs. or Prov. Eng.]

2.

An exchange; a barter.

[Colloq.]

Sir W. Scott.

 

© Webster 1913.


Swap, adv. [See Swap, n.]

Hastily.

[Prov. Eng.]

 

© Webster 1913.

Log in or registerto write something here or to contact authors.