langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
2
Task/Generic-swap/Nemerle/generic-swap-1.nemerle
Normal file
2
Task/Generic-swap/Nemerle/generic-swap-1.nemerle
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
def coords = (1, -1);
|
||||
def invcoords = Swap(coords);
|
||||
1
Task/Generic-swap/Nemerle/generic-swap-2.nemerle
Normal file
1
Task/Generic-swap/Nemerle/generic-swap-2.nemerle
Normal file
|
|
@ -0,0 +1 @@
|
|||
a <-> b;
|
||||
4
Task/Generic-swap/Nemerle/generic-swap-3.nemerle
Normal file
4
Task/Generic-swap/Nemerle/generic-swap-3.nemerle
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Swap[T, U] (a : T, b : U) : U * T
|
||||
{
|
||||
(b, a)
|
||||
}
|
||||
2
Task/Generic-swap/Nial/generic-swap.nial
Normal file
2
Task/Generic-swap/Nial/generic-swap.nial
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
|reverse 1 2
|
||||
=2 1
|
||||
1
Task/Generic-swap/OCaml/generic-swap-1.ocaml
Normal file
1
Task/Generic-swap/OCaml/generic-swap-1.ocaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
let swap (x, y) = (y, x)
|
||||
4
Task/Generic-swap/OCaml/generic-swap-2.ocaml
Normal file
4
Task/Generic-swap/OCaml/generic-swap-2.ocaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
let swapref x y =
|
||||
let temp = !x in
|
||||
x := !y;
|
||||
y := temp
|
||||
6
Task/Generic-swap/Oz/generic-swap-1.oz
Normal file
6
Task/Generic-swap/Oz/generic-swap-1.oz
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
proc {SwapCells A B}
|
||||
Tmp = @A
|
||||
in
|
||||
A := @B
|
||||
B := Tmp
|
||||
end
|
||||
3
Task/Generic-swap/Oz/generic-swap-2.oz
Normal file
3
Task/Generic-swap/Oz/generic-swap-2.oz
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
proc {SwapCells A B}
|
||||
B := A := @B
|
||||
end
|
||||
3
Task/Generic-swap/Oz/generic-swap-3.oz
Normal file
3
Task/Generic-swap/Oz/generic-swap-3.oz
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fun {SwapPair A#B}
|
||||
B#A
|
||||
end
|
||||
3
Task/Generic-swap/PARI-GP/generic-swap-1.pari
Normal file
3
Task/Generic-swap/PARI-GP/generic-swap-1.pari
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
my(tmp=a);
|
||||
a=b;
|
||||
b=tmp;
|
||||
1
Task/Generic-swap/PARI-GP/generic-swap-2.pari
Normal file
1
Task/Generic-swap/PARI-GP/generic-swap-2.pari
Normal file
|
|
@ -0,0 +1 @@
|
|||
[a,b]=[b,a]
|
||||
11
Task/Generic-swap/PL-I/generic-swap-1.pli
Normal file
11
Task/Generic-swap/PL-I/generic-swap-1.pli
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
%swap: procedure (a, b);
|
||||
declare (a, b) character;
|
||||
return ( 't=' || a || ';' || a || '=' || b || ';' || b '=t;' );
|
||||
%end swap;
|
||||
%activate swap;
|
||||
|
||||
The statement:-
|
||||
swap (p, q);
|
||||
|
||||
is replaced, at compile time, by the three statements:
|
||||
t = p; p = q; q = t;
|
||||
16
Task/Generic-swap/PL-I/generic-swap-2.pli
Normal file
16
Task/Generic-swap/PL-I/generic-swap-2.pli
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
declare swap generic (
|
||||
swapf when (float, float),
|
||||
swapc when (char, char));
|
||||
|
||||
swapf: proc (a, b);
|
||||
declare (a, b, t) float;
|
||||
t = a; a = b; b = t;
|
||||
end swapf;
|
||||
swapc: proc (a, b);
|
||||
declare (a, b) character(*);
|
||||
declare t character (length(b));
|
||||
t = a; a = b; b = t;
|
||||
end swapc;
|
||||
|
||||
declare (r, s) character (5);
|
||||
call swap (r, s);
|
||||
36
Task/Generic-swap/PL-I/generic-swap-3.pli
Normal file
36
Task/Generic-swap/PL-I/generic-swap-3.pli
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
%swap: proc(x,y);
|
||||
dcl (x, y) char;
|
||||
|
||||
x = trim(x); /* Just for neatness sake */
|
||||
y = trim(y);
|
||||
|
||||
ans('begin; ') skip;
|
||||
ans(' dcl c char (1); ') skip;
|
||||
ans(' dcl sx char (1) based(px); ') skip;
|
||||
ans(' dcl sy char (1) based(py); ') skip;
|
||||
ans(' dcl i fixed bin (31); ') skip;
|
||||
ans(' dcl px ptr init (addr(' || x || ')); ') skip;
|
||||
ans(' dcl py ptr init (addr(' || y || ')); ') skip;
|
||||
ans(' do i = 1 to min(stg(' || x || '), stg(' || y || '));') skip;
|
||||
ans(' c = sx; ') skip;
|
||||
ans(' sx = sy; ') skip;
|
||||
ans(' sy = c; ') skip;
|
||||
ans(' px = px + 1; ') skip;
|
||||
ans(' py = py + 1; ') skip;
|
||||
ans(' end; ') skip;
|
||||
ans('end; ') skip;
|
||||
%end swap;
|
||||
%act swap;
|
||||
|
||||
dcl c1 char (10) init ('1234567890');
|
||||
dcl c2 char (10) init ('ABCDEFGHIJ');
|
||||
dcl f1 fixed bin (31) init (12345);
|
||||
dcl f2 fixed bin (31) init (98765);
|
||||
|
||||
put data(c1, c2, f1, f2);
|
||||
swap(c1, c2);
|
||||
swap(f1, f2);
|
||||
put data(c1, c2, f1, f2);
|
||||
f1 = -656877352; /* '5a5a5a5a'x, aka 'QQQQ' */
|
||||
swapper(c1, f1);
|
||||
put data(c1,f1);
|
||||
15
Task/Generic-swap/PL-I/generic-swap-4.pli
Normal file
15
Task/Generic-swap/PL-I/generic-swap-4.pli
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
begin;
|
||||
dcl c char (1);
|
||||
dcl sx char (1) based(px);
|
||||
dcl sy char (1) based(py);
|
||||
dcl i fixed bin (31);
|
||||
dcl px ptr init (addr(C1));
|
||||
dcl py ptr init (addr(C2));
|
||||
do i = 1 to min(stg(C1), stg(C2));
|
||||
c = sx;
|
||||
sx = sy;
|
||||
sy = c;
|
||||
px = px + 1;
|
||||
py = py + 1;
|
||||
end;
|
||||
end;
|
||||
28
Task/Generic-swap/Pascal/generic-swap.pascal
Normal file
28
Task/Generic-swap/Pascal/generic-swap.pascal
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
program generictest;
|
||||
|
||||
{$mode objfpc}
|
||||
|
||||
type
|
||||
generic TSwap<T> = procedure (var a, b: T);
|
||||
|
||||
procedure Proc1(var a, b: integer);
|
||||
var
|
||||
temp: integer;
|
||||
begin
|
||||
temp := a;
|
||||
a := b;
|
||||
b := temp;
|
||||
end;
|
||||
|
||||
var
|
||||
S, T: integer;
|
||||
SwapInt: specialize TSwap<integer>;
|
||||
|
||||
begin
|
||||
S := 4;
|
||||
T := 3;
|
||||
SwapInt := @Proc1;
|
||||
writeln(S, T:2);
|
||||
SwapInt(S, T);
|
||||
writeln(S, T:2);
|
||||
end.
|
||||
1
Task/Generic-swap/Perl-6/generic-swap.pl6
Normal file
1
Task/Generic-swap/Perl-6/generic-swap.pl6
Normal file
|
|
@ -0,0 +1 @@
|
|||
($x, $y) .= reverse;
|
||||
1
Task/Generic-swap/Pop11/generic-swap.pop11
Normal file
1
Task/Generic-swap/Pop11/generic-swap.pop11
Normal file
|
|
@ -0,0 +1 @@
|
|||
(a, b) -> (b, a);
|
||||
1
Task/Generic-swap/PostScript/generic-swap.ps
Normal file
1
Task/Generic-swap/PostScript/generic-swap.ps
Normal file
|
|
@ -0,0 +1 @@
|
|||
exch
|
||||
1
Task/Generic-swap/PowerShell/generic-swap-1.psh
Normal file
1
Task/Generic-swap/PowerShell/generic-swap-1.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
$b, $a = $a, $b
|
||||
3
Task/Generic-swap/PowerShell/generic-swap-2.psh
Normal file
3
Task/Generic-swap/PowerShell/generic-swap-2.psh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
function swap ([ref] $a, [ref] $b) {
|
||||
$a.Value, $b.Value = $b.Value, $a.Value
|
||||
}
|
||||
1
Task/Generic-swap/PowerShell/generic-swap-3.psh
Normal file
1
Task/Generic-swap/PowerShell/generic-swap-3.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
swap ([ref] $a) ([ref] $b)
|
||||
1
Task/Generic-swap/PureBasic/generic-swap.purebasic
Normal file
1
Task/Generic-swap/PureBasic/generic-swap.purebasic
Normal file
|
|
@ -0,0 +1 @@
|
|||
Swap a, b
|
||||
20
Task/Generic-swap/REBOL/generic-swap.rebol
Normal file
20
Task/Generic-swap/REBOL/generic-swap.rebol
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
REBOL [
|
||||
Title: "Generic Swap"
|
||||
Author: oofoe
|
||||
Date: 2009-12-06
|
||||
URL: http://rosettacode.org/wiki/Generic_swap
|
||||
Reference: [http://reboltutorial.com/blog/rebol-words/]
|
||||
]
|
||||
|
||||
swap: func [
|
||||
"Swap contents of variables."
|
||||
a [word!] b [word!] /local x
|
||||
][
|
||||
x: get a
|
||||
set a get b
|
||||
set b x
|
||||
]
|
||||
|
||||
answer: 42 ship: "Heart of Gold"
|
||||
swap 'answer 'ship ; Note quoted variables.
|
||||
print rejoin ["The answer is " answer ", the ship is " ship "."]
|
||||
22
Task/Generic-swap/RLaB/generic-swap.rlab
Normal file
22
Task/Generic-swap/RLaB/generic-swap.rlab
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
swap = function(x,y)
|
||||
{
|
||||
if (!exist($$.[x]))
|
||||
{ return 0; }
|
||||
if (!exist($$.[y]))
|
||||
{ return 0; }
|
||||
local (t);
|
||||
t = $$.[x];
|
||||
$$.[x] = $$.[y];
|
||||
$$.[y] = t;
|
||||
return 1;
|
||||
};
|
||||
|
||||
>> a=1
|
||||
1
|
||||
>> b = "fish"
|
||||
fish
|
||||
>> swap( "a" , "b" );
|
||||
>> a
|
||||
fish
|
||||
>> b
|
||||
1
|
||||
1
Task/Generic-swap/Retro/generic-swap.retro
Normal file
1
Task/Generic-swap/Retro/generic-swap.retro
Normal file
|
|
@ -0,0 +1 @@
|
|||
swap
|
||||
7
Task/Generic-swap/Run-BASIC/generic-swap.run
Normal file
7
Task/Generic-swap/Run-BASIC/generic-swap.run
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
a = 1
|
||||
b = 2
|
||||
'----- swap ----
|
||||
tmp = a
|
||||
a = b
|
||||
b = tmp
|
||||
end
|
||||
9
Task/Generic-swap/SNOBOL4/generic-swap.sno
Normal file
9
Task/Generic-swap/SNOBOL4/generic-swap.sno
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
* SWAP(.V1, .V2) - Exchange the contents of two variables.
|
||||
* The variables must be prefixed with the name operator
|
||||
* when the function is called.
|
||||
|
||||
DEFINE('SWAP(X,Y)TEMP') :(SWAP_END)
|
||||
SWAP TEMP = $X
|
||||
$X = $Y
|
||||
$Y = TEMP :(RETURN)
|
||||
SWAP_END
|
||||
13
Task/Generic-swap/Seed7/generic-swap-1.seed7
Normal file
13
Task/Generic-swap/Seed7/generic-swap-1.seed7
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
const proc: generate_swap (in type: aType) is func
|
||||
begin
|
||||
|
||||
const proc: swap (inout aType: left, inout aType: right) is func
|
||||
local
|
||||
var aType: temp is aType.value;
|
||||
begin
|
||||
temp := left;
|
||||
left := right;
|
||||
right := temp;
|
||||
end func;
|
||||
|
||||
end func;
|
||||
2
Task/Generic-swap/Seed7/generic-swap-2.seed7
Normal file
2
Task/Generic-swap/Seed7/generic-swap-2.seed7
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
generate_swap(integer);
|
||||
generate_swap(string);
|
||||
1
Task/Generic-swap/Seed7/generic-swap-3.seed7
Normal file
1
Task/Generic-swap/Seed7/generic-swap-3.seed7
Normal file
|
|
@ -0,0 +1 @@
|
|||
swap(a, b);
|
||||
10
Task/Generic-swap/Slate/generic-swap-1.slate
Normal file
10
Task/Generic-swap/Slate/generic-swap-1.slate
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
x@(Syntax LoadVariable traits) swapWith: y@(Syntax LoadVariable traits) &environment: env
|
||||
"A macro that expands into simple code swapping the values of two variables
|
||||
in the current scope."
|
||||
[
|
||||
env ifNil: [error: 'Cannot swap variables outside of a method'].
|
||||
tmpVar ::= env addVariable.
|
||||
{tmpVar store: x variable load.
|
||||
x variable store: y variable load.
|
||||
y variable store: tmpVar load} parenthesize
|
||||
].
|
||||
1
Task/Generic-swap/Slate/generic-swap-2.slate
Normal file
1
Task/Generic-swap/Slate/generic-swap-2.slate
Normal file
|
|
@ -0,0 +1 @@
|
|||
a `swapWith: b
|
||||
1
Task/Generic-swap/Standard-ML/generic-swap-1.ml
Normal file
1
Task/Generic-swap/Standard-ML/generic-swap-1.ml
Normal file
|
|
@ -0,0 +1 @@
|
|||
fun swap (x, y) = (y, x)
|
||||
2
Task/Generic-swap/Standard-ML/generic-swap-2.ml
Normal file
2
Task/Generic-swap/Standard-ML/generic-swap-2.ml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fun swapref (x, y) =
|
||||
let temp = !x in x := !y; y := temp end
|
||||
14
Task/Generic-swap/TI-89-BASIC/generic-swap.ti-89
Normal file
14
Task/Generic-swap/TI-89-BASIC/generic-swap.ti-89
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
Define swap(swapvar1, swapvar2) = Prgm
|
||||
Local swaptmp
|
||||
#swapvar1 → swaptmp
|
||||
#swapvar2 → #swapvar1
|
||||
swaptmp → #swapvar2
|
||||
EndPrgm
|
||||
|
||||
1 → x
|
||||
2 → y
|
||||
swap("x", "y")
|
||||
x
|
||||
2
|
||||
y
|
||||
1
|
||||
1
Task/Generic-swap/Trith/generic-swap.trith
Normal file
1
Task/Generic-swap/Trith/generic-swap.trith
Normal file
|
|
@ -0,0 +1 @@
|
|||
swap
|
||||
7
Task/Generic-swap/Ursala/generic-swap.ursala
Normal file
7
Task/Generic-swap/Ursala/generic-swap.ursala
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
pmgs("x","y") = ("y","x") # the pattern matching way
|
||||
|
||||
ugs = ~&rlX # the idiosyncratic Ursala way
|
||||
|
||||
#cast %sWL
|
||||
|
||||
test = <pmgs ('a','b'),ugs ('x','y')>
|
||||
5
Task/Generic-swap/V/generic-swap.v
Normal file
5
Task/Generic-swap/V/generic-swap.v
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
[swap [a b : b a] view].
|
||||
|
||||
1 2 swap
|
||||
= 2 1
|
||||
'hello' 'hi' swap
|
||||
6
Task/Generic-swap/VBScript/generic-swap-1.vbscript
Normal file
6
Task/Generic-swap/VBScript/generic-swap-1.vbscript
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
sub swap( byref x, byref y )
|
||||
dim temp
|
||||
temp = x
|
||||
x = y
|
||||
y = temp
|
||||
end sub
|
||||
7
Task/Generic-swap/VBScript/generic-swap-2.vbscript
Normal file
7
Task/Generic-swap/VBScript/generic-swap-2.vbscript
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
dim a
|
||||
a = "woof"
|
||||
dim b
|
||||
b = now()
|
||||
swap a,b
|
||||
wscript.echo a
|
||||
wscript.echo b
|
||||
2
Task/Generic-swap/VBScript/generic-swap-3.vbscript
Normal file
2
Task/Generic-swap/VBScript/generic-swap-3.vbscript
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
5/02/2010 2:35:36 PM
|
||||
woof
|
||||
14
Task/Generic-swap/XPL0/generic-swap.xpl0
Normal file
14
Task/Generic-swap/XPL0/generic-swap.xpl0
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
include c:\cxpl\codes;
|
||||
|
||||
proc Exch(A, B, S);
|
||||
char A, B, S;
|
||||
int I, T;
|
||||
for I:= 0 to S-1 do
|
||||
[T:= A(I); A(I):= B(I); B(I):= T];
|
||||
|
||||
|
||||
real X, Y;
|
||||
[X:= 3.0; Y:= 4.0;
|
||||
Exch(addr X, addr Y, 8);
|
||||
RlOut(0, X); RlOut(0, Y); CrLf(0);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue