September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -1,24 +1,24 @@
import extensions.
import extensions;
singleton swap
{
eval ref:v1 ref:v2
[
var tmp := v1 value.
eval(ref object v1, ref object v2)
{
var tmp := v1.Value;
v1 object := v2 value.
v2 object := tmp.
]
v1 := v2.Value;
v2 := tmp
}
}
program =
[
var n := 2.
var s := "abc".
public program()
{
var n := 2;
var s := "abc";
console printLine(n," ",s).
console.printLine(n," ",s);
swap eval ref:n ref:s.
swap.eval(ref n, ref s);
console printLine(n," ",s).
].
console.printLine(n," ",s)
}

View file

@ -0,0 +1 @@
$

View file

@ -0,0 +1,19 @@
{$ifdef fpc}{$mode delphi}{$H+}{$endif}
{ note this is compiled with delphi mode but will only compile in Free Pascal }
{ Delphi doesn't support this syntax }
procedure swap<T>(var left,right:T);
var
temp:T;
begin
temp:=left;
left:=right;
right:=temp;
end;
var
a:string = 'Test';
b:string = 'me';
begin
writeln(a:6,b:6);
swap<string>(a,b);
writeln(a:6,b:6);
end.

View file

@ -0,0 +1,9 @@
>> a = 12
a = 12
>> b = 'foo'
b = foo
>> [b, a] = deal (a, b)
b = 12
a = foo

View file

@ -1,10 +1,10 @@
a: 10$
b: 20$
b: foo$
/* A simple way to swap values */
[a, b]: [b, a]$
a; /* 20 */
a; /* foo */
b; /* 10 */
/* A macro to hide this */
@ -13,4 +13,4 @@ swap(x, y) ::= buildq([x, y], ([x, y]: [y, x], 'done))$
swap(a, b)$
a; /* 10 */
b; /* 20 */
b; /* foo */

View file

@ -0,0 +1,23 @@
program generic_test;
{$mode objfpc}{H+}
uses
SysUtils;
generic procedure GSwap<T>(var L, R: T);
var
Tmp: T;
begin
Tmp := L;
L := R;
R := Tmp;
end;
var
I, J: Integer;
begin
I := 100;
J := 11;
WriteLn('I = ', I, ', J = ', J);
specialize GSwap<Integer>(I, J);
WriteLn('I = ', I, ', J = ', J);
end.