langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,3 @@
Array.make n (new foo);;
(* here (new foo) can be any expression that returns a new object,
record, array, or string *)

View file

@ -0,0 +1 @@
Array.init n (fun _ -> new foo);;

View file

@ -0,0 +1,5 @@
declare
Xs = {MakeList 5} %% a list of 5 unbound variables
in
{ForAll Xs OS.rand} %% fill it with random numbers (CORRECT)
{Show Xs}

View file

@ -0,0 +1,7 @@
declare
Arr = {Array.new 0 10 {OS.rand}} %% WRONG: contains ten times the same number
in
%% CORRECT: fill it with ten (probably) different numbers
for I in {Array.low Arr}..{Array.high Arr} do
Arr.I := {OS.rand}
end

View file

@ -0,0 +1,2 @@
# WRONG
my @a = Foo.new xx $n;

View file

@ -0,0 +1 @@
my @a = map { Foo.new }, ^$n

View file

@ -0,0 +1,25 @@
n=Random(50)+25
Dim A.i(n)
; Creates a Array of n [25-75] elements depending on the outcome of Random().
; Each element will be initiated to zero.
For i=0 To ArraySize(A())
A(i)=2*i
Next i
; Set each individual element at a wanted (here 2*i) value and
; automatically adjust accordingly to the unknown length of the Array.
NewList *PointersToA()
For i=0 To ArraySize(A())
AddElement(*PointersToA())
*PointersToA()=@A(i)
Next
; Create a linked list of the same length as A() above.
; Each element is then set to point to the Array element
; of the same order.
ForEach *PointersToA()
Debug PeekI(*PointersToA())
Next
; Verify by sending each value of A() via *PointersToA()
; to the debugger's output.

View file

@ -0,0 +1,7 @@
code Reserve=3, IntIn=10;
char A; int N, I;
[N:= IntIn(8); \get number of items from command line
A:= Reserve(N); \create array of N bytes
for I:= 0 to N-1 do A(I):= I*3; \initialize items with different values
for I:= 0 to N-1 do A:= I*3; \error: "references to the same mutable object"
]