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,16 @@
/* NetRexx */
options replace format comments java crossref symbols nobinary
myVals = [ 'zero', 'one', 'two', 'three', 'four', 'five' ]
mySet = Set
mySet = HashSet()
loop val over myVals
mySet.add(val)
end val
loop val over mySet
say val
end val
return

View file

@ -0,0 +1 @@
[1; 2; 3; 4; 5]

View file

@ -0,0 +1 @@
1 :: [2; 3; 4; 5]

View file

@ -0,0 +1 @@
[1; 2] @ [3; 4; 5]

View file

@ -0,0 +1,2 @@
# List.flatten [[1; 2]; [3; 4]; [5; 6; 7]] ;;
- : int list = [1; 2; 3; 4; 5; 6; 7]

View file

@ -0,0 +1 @@
[| 1; 2; 3; 4; 5 |]

View file

@ -0,0 +1,4 @@
values := IntVector->New();
values->AddBack(7);
values->AddBack(3);
values->AddBack(10);

View file

@ -0,0 +1,4 @@
values := IntList->New();
values->AddBack(7);
values->AddBack(3);
values->AddBack(10);

View file

@ -0,0 +1,4 @@
values := StringHash->New();
values->Insert("seven", IntHolder->New(7));
values->Insert("three", IntHolder->New(3));
values->Insert("ten", IntHolder->New(10));

View file

@ -0,0 +1,4 @@
values := IntStack->New();
values->Push(7);
values->Push(3);
values->Push(10);

View file

@ -0,0 +1,60 @@
#import <Foundation/Foundation.h>
void show_collection(id coll)
{
id el;
NSEnumerator *en;
if ( [coll respondsToSelector: @selector(keyEnumerator)] ) {
en = [coll keyEnumerator];
} else {
en = [coll objectEnumerator];
}
while( (el = [en nextObject]) != nil)
{
if ( [coll respondsToSelector: @selector(countForObject:)] ) {
NSLog(@"%@ appears %d times", el, [coll countForObject: el]);
} else if ( [coll isKindOfClass: [NSDictionary class]] ) {
NSLog(@"%@ -> %@", el, [coll valueForKey: el]);
} else {
NSLog(@"%@", el);
}
}
printf("\n");
}
int main()
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// create an empty set
NSMutableSet *set = [[NSMutableSet alloc] init];
// populate it
[set addObject: @"one"];
[set addObject: [NSNumber numberWithInt: 10]];
[set addObjectsFromArray: [NSArray arrayWithObjects: @"one",
[NSNumber numberWithInt: 20],
[NSNumber numberWithInt: 10],
@"two", nil] ];
// let's show it
show_collection(set);
// create an empty counted set (a bag)
NSCountedSet *cset = [[NSCountedSet alloc] init];
// populate it
[cset addObject: @"one"];
[cset addObject: @"one"];
[cset addObject: @"two"];
// show it
show_collection(cset);
// create a dictionary
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
// populate it
[dict setValue: [NSNumber numberWithInt: 4] forKey: @"four"];
[dict setValue: [NSNumber numberWithInt: 8] forKey: @"eight"];
// show it
show_collection(dict);
[pool release];
return EXIT_SUCCESS;
}

View file

@ -0,0 +1,25 @@
declare
%% Lists (immutable, recursive)
Xs = [1 2 3 4]
%% Add element at the front (cons)
Xs0 = 0|Xs
{Show {Length Xs}} %% output: 4
%% Records (immutable maps with a label)
Rec = label(1:2 symbol:3)
{Show Rec} %% output: label(2 symbol:3)
{Show Rec.1} %% output: 2
%% create a new record with an added field
Rec2 = {AdjoinAt Rec 2 value}
{Show Rec2} %% output: label(2 value symbol:3)
%% Dictionaries (mutable maps)
Dict = {Dictionary.new}
Dict.1 := 1
Dict.symbol := 3
{Show Dict.1} %% output: 1
%% Arrays (mutable with integer keys)
Arr = {Array.new 1 10 initValue}
Arr.1 := 3
{Show Arr.1} %% output: 3

View file

@ -0,0 +1,8 @@
v = vector(0);
v = [];
cv = vectorv(0);
cv = []~;
m = matrix(1,1);
s = Set(v);
l = List(v);
vs = vectorsmall(0);

View file

@ -0,0 +1,3 @@
listput(l, "hello world")
v=concat(v, [1,2,3]);
v=concat(v, 4);

View file

@ -0,0 +1,4 @@
declare countries character (20) varying controlled;
allocate countries initial ('Britain');
allocate countries initial ('America');
allocate countries initial ('Argentina');

View file

@ -0,0 +1,5 @@
var
MyArray: array[1..5] of real;
begin
MyArray[1] := 4.35;
end;

View file

@ -0,0 +1,6 @@
var
MyArray: array of integer;
begin
setlength (MyArray, 10);
MyArray[4] := 99;
end;

View file

@ -0,0 +1,11 @@
var
MyRecord: record
x, y, z: real;
presence: boolean;
end;
begin
MyRecord.x := 0.3;
MyRecord.y := 3.2;
MyRecord.z := -4.0;
MyRecord.presence := true;
end;

View file

@ -0,0 +1,9 @@
type
days = (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
var
workDays, week, weekendDays: set of days;
begin
workdays := [Mon, Tue, Wed, Thu, Fri];
week := workdays + [Sat, Sun];
weekendDays := week - workdays;
end;

View file

@ -0,0 +1,5 @@
var
MyString: String;
begin
MyString:= 'Some Text';
end;

View file

@ -0,0 +1,19 @@
program ListDemo;
uses
classes;
var
MyList: TList;
a, b, c: integer;
i: integer;
begin
a := 1;
b := 2;
c := 3;
MyList := TList.Create;
MyList.Add(@a);
MyList.Add(@c);
MyList.Insert(1, @b);
for i := MyList.IndexOf(MyList.First) to MyList.IndexOf(MyList.Last) do
writeln (integer(MyList.Items[i]^));
MyList.Destroy;
end.

View file

@ -0,0 +1,34 @@
Program ex34;
{ Program to demonstrate the TCollection.AtInsert method }
Uses Objects, MyObject; { For TMyObject definition and registration }
Var C : PCollection;
M : PMyObject;
I : Longint;
Procedure PrintField (Dummy : Pointer; P : PMyObject);
begin
Writeln ('Field : ',P^.GetField);
end;
begin
Randomize;
C:=New(PCollection, Init(120, 10));
Writeln ('Inserting 100 records at random places.');
For I:=1 to 100 do
begin
M:=New(PMyObject, Init);
M^.SetField(I-1);
If I=1 then
C^.Insert(M)
else
With C^ do
AtInsert(Random(Count), M);
end;
Writeln ('Values : ');
C^.Foreach(@PrintField);
Dispose(C, Done);
end.

View file

@ -0,0 +1,2 @@
my @array = 1,2,3;
@array.push: 4,5,6;

View file

@ -0,0 +1,3 @@
my %hash = a => 1, b => 2;
%hash<c d> = 3,4;
%hash.push: e => 5, f => 6;

View file

@ -0,0 +1,2 @@
my @list := 1,2,3;
my @newlist := @list, 4,5,6;

View file

@ -0,0 +1,2 @@
my $set = set <a b c>;
my $newset = $set <d e f>;

View file

@ -0,0 +1,2 @@
my $s = KeySet.new: <a b c>;
$s = <d e f>;

View file

@ -0,0 +1,2 @@
my $bag = bag <b a k l a v a>;
my $newbag = $bag <b e e f>;

View file

@ -0,0 +1,2 @@
my $b = KeySet.new: <b a k l a v a>;
$b = <d e f>;

View file

@ -0,0 +1,2 @@
my $tail = d => e => f => Nil;
my $new = a => b => c => $tail;

View file

@ -0,0 +1,2 @@
my $obj = Something.new: foo => 1, bar => 2;
my $newobj = $obj but role { has $.baz = 3 } # anonymous mixin

View file

@ -0,0 +1,4 @@
Dim Text.s(9)
Text(3)="Hello"
Text(7)="World!"

View file

@ -0,0 +1,4 @@
NewList Cars.s()
AddElement(Cars()): Cars()="Volvo"
AddElement(Cars()): Cars()="BMV"

View file

@ -0,0 +1,4 @@
NewMap Capitals.s()
Capitals("USA") = "Washington"
Capitals("Sweden")= "Stockholm"

View file

@ -0,0 +1,8 @@
[ 1 2 3 'abc' ] as a_list
a_list print
list (4 items)
0 => 1
1 => 2
2 => 3
3 => "abc"

View file

@ -0,0 +1,6 @@
{ 'a' 1 'b' 2 } as a_hash
a_hash print
hash (2 items)
a => 1
b => 2

View file

@ -0,0 +1,3 @@
17 a_list 1 set # set second item
42 a_hash 'b' set # set item with key 'b'
42 a_hash:b # shorthand

View file

@ -0,0 +1,3 @@
a_list 1 get # get second item
a_hash 'b' get # get item with key 'b'
a_hash.b # shorthand

View file

@ -0,0 +1,6 @@
42 a_list push # append an item
a_list pop # remove last item
42 a_list shove # prepend an item
a_list shift # remove first item
42 a_list 1 insert # insert item second, shuffling others down
a_list 1 remove # retrieve second item, shuffling others up

View file

@ -0,0 +1,12 @@
$ include "seed7_05.s7i";
enable_output(set of string);
const proc: main is func
local
var set of string: aSet is {"iron", "copper"};
begin
writeln(aSet);
incl(aSet, "silver");
writeln(aSet);
end func;

View file

@ -0,0 +1,17 @@
$ include "seed7_05.s7i";
const proc: main is func
local
var array string: anArray is [] ("iron", "copper");
var string: element is "";
begin
for element range anArray do
write(element <& " ");
end for;
writeln;
anArray &:= "silver";
for element range anArray do
write(element <& " ");
end for;
writeln;
end func;

View file

@ -0,0 +1,16 @@
$ include "seed7_05.s7i";
const type: aHashType is hash [string] string;
const proc: main is func
local
var aHashType: aHash is aHashType.value;
var string: aValue is "";
var string: aKey is "";
begin
aHash @:= ["gold"] "metal";
aHash @:= ["helium"] "noble gas";
for aValue key aKey range aHash do
writeln(aKey <& ": " <& aValue);
end for;
end func;

View file

@ -0,0 +1,4 @@
{1. 2. 3. 4. 5} collect: [|:x| x + 1]. "--> {2. 3. 4. 5. 6}"
{1. 2. 3. 4. 5} select: #isOdd `er. "--> {1. 3. 5}"
({3. 2. 7} collect: #+ `er <- 3) sort. "--> {"SortedArray traitsWindow" 5. 6. 10}"
ExtensibleArray new `>> [addLast: 3. addFirst: 4. ]. "--> {"ExtensibleArray traitsWindow" 4. 3}"

View file

@ -0,0 +1,13 @@
$$ MODE TUSCRIPT
collection=*
DATA apple
DATA banana
DATA orange
morestuff=*
DATA peaches
DATA apple
collection=APPEND(collection,morestuff)
TRACE *collection

View file

@ -0,0 +1,3 @@
x = <1,5,6>
y = <'foo','bar'>
z = 3:<6,8>

View file

@ -0,0 +1 @@
foo ("newhead","existing-list") = "newhead":"existing-list"

View file

@ -0,0 +1,3 @@
x = {'a','b'}
y = {'b','a'}
z = {'a','b','a'}

View file

@ -0,0 +1 @@
m = <'foo': 1,'bar': 2,'baz': 3>

View file

@ -0,0 +1,9 @@
x =
'z'^: <
'x'^: <
'7'^: <>,
'?'^: <'D'^: <>>>,
'a'^: <'E'^: <>,'j'^: <>>,
'b'^: <'i'^: <>>,
'c'^: <>>

View file

@ -0,0 +1,8 @@
x =
[
4:0: 'foo',
4:1: 'bar',
4:2: 'baz',
4:3: 'volta',
4:4: 'pramim']

View file

@ -0,0 +1,23 @@
g =
<
[0:0: -9.483639e+00^: <4:10,4:14>],
[
4:14: -9.681900e+00^: <4:15>,
4:10: 2.237330e+00^: <4:7>],
[
4:15: -2.007562e+00^: <5:5>,
4:7: 2.419021e+00^: <5:5,5:15>],
[
5:15: 8.215451e+00^: <11:118>,
5:5: 4.067704e+00^: <11:741>],
[
11:741: -7.608967e+00^: <8:68>,
11:118: -1.552837e+00^: <8:68,8:208>],
[
8:208: 5.348115e+00^: <4:7,4:9,4:12>,
8:68: -9.066821e+00^: <4:9,4:12>],
[
4:12: -3.460494e+00^: <>,
4:9: 2.840319e+00^: <>,
4:7: -2.181140e+00^: <>]>

View file

@ -0,0 +1,2 @@
[4 3 2 1] 5 swap cons
=[5 4 3 2 1]

View file

@ -0,0 +1,4 @@
Dim toys As New List(Of String)
toys.Add("Car")
toys.Add("Boat")
toys.Add("Train")