This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -0,0 +1 @@
(a, b) = (b, a)

View file

@ -0,0 +1 @@
swap

View file

@ -0,0 +1 @@
set :a set :b @a @b

View file

@ -0,0 +1,8 @@
procedure Swap_T(var a, b: T);
var
temp: T;
begin
temp := a;
a := b;
b := temp;
end;

View file

@ -0,0 +1,26 @@
program GenericSwap;
type
TSwap = class
class procedure Swap<T>(var left, right: T);
end;
class procedure TSwap.Swap<T>(var left, right: T);
var
temp : T;
begin
temp := left;
left := right;
right := temp;
end;
var
a, b : integer;
begin
a := 5;
b := 3;
writeln('Before swap: a=', a, ' b=', b);
TSwap.Swap<integer>(a, b);
writeln('After swap: a=', a, ' b=', b);
end.

View file

@ -0,0 +1,21 @@
/* NetRexx */
options replace format comments java crossref symbols nobinary
-- Simple values with no spaces can be swapped without the use of a parse template
lval = 27
rval = 5
say 'Before - <lval>'lval'</lval> <rval>'rval'</rval>'
parse (lval rval) rval lval
say 'After - <lval>'lval'</lval> <rval>'rval'</rval>'
say
-- More complex data needs to use some form of parsing template
lval = 'This value started on the left'
rval = 'This value started on the right'
dlm = 12x80facebead01 -- some delimiting value that is unlikely to occur in the LVAL to be swapped
say 'Before - <lval>'lval'</lval> <rval>'rval'</rval>'
parse (lval || dlm || rval) rval (dlm) lval
say 'After - <lval>'lval'</lval> <rval>'rval'</rval>'
say
return