langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
|
|
@ -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 *)
|
||||
|
|
@ -0,0 +1 @@
|
|||
Array.init n (fun _ -> new foo);;
|
||||
|
|
@ -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}
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
# WRONG
|
||||
my @a = Foo.new xx $n;
|
||||
|
|
@ -0,0 +1 @@
|
|||
my @a = map { Foo.new }, ^$n
|
||||
|
|
@ -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.
|
||||
|
|
@ -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"
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue