History

moving examples to top dir

Ge Wang committed 9 years ago

Commit 35ca2f61 parent fd011ef486 files · +-44 −-44Browse files

Showing the changes to examples/array (8 of 486 files). Show all

Unified · Split

8 files
  1. examples/array/array_argument.ck +19 −0
  2. examples/array/array_assign.ck +13 −0
  3. examples/array/array_dynamic.ck +20 −0
  4. examples/array/array_mdim.ck +14 −0
  5. examples/array/array_mmixed.ck +17 −0
  6. examples/array/array_resize.ck +35 −0
  7. examples/array/array_storage.ck +9 −0
  8. examples/array/array_sub_assign.ck +14 −0
examples/array/array_argument.ck+19−0
@@ -0,0 +1,19 @@
1// array pass by reference test - should change values?
2
3// function that takes array
4fun void mirror( int arg[] )
5{
6 // assign 0th element to 1st element
7 arg[0] => arg[1];
8}
9
10// declare array
11int foo[2];
122 => foo[0];
131 => foo[1];
14
15// call the function
16mirror( foo );
17
18// test
19if ( foo[0] == foo[1] ) <<<"success">>>;
examples/array/array_assign.ck+13−0
@@ -0,0 +1,13 @@
1// 17.ck : partial array
2
3// declare int array 2x2
4int x[2][2];
5
6// assign
72 => x[1][1];
8
9// assign partial array reference to 'y'
10x[1] @=> int y[];
11
12// test
13if( y[1] == 2 ) <<<"success">>>;
examples/array/array_dynamic.ck+20−0
@@ -0,0 +1,20 @@
1// instantiate int array
2float argh[0];
3
4// print out relevant info
5<<< "array size:", argh.size() >>>;
6
7// append items (array should grow dynamically as needed)
8argh << 3.0 << 4 << 5;
9
10// print out relevant info
11<<< "array size:", argh.size() >>>;
12
13// print out elements
14<<< "contents:", argh[0], argh[1], argh[2] >>>;
15
16// pop element
17argh.popBack();
18
19// print out relevant info
20<<< "array size:", argh.size() >>>;
examples/array/array_mdim.ck+14−0
@@ -0,0 +1,14 @@
1// 15.ck : multi-dimensional array instantiation
2
3// delcare int array 2x2x2
4int a[2][2][2];
5// delcare float array 2x2x2
6float b[2][2][2];
7// assign
85 => a[1][1][1] => b[1][1][1];
9
10// multi-dimensional array initialization
11[ [1,2], [3,4] ] @=> int c[][];
12
13// test
14if( a[1][1][1] == 5 && b[1][1][1] == 5.0 && c[0][1] == 2 ) <<<"success">>>;
examples/array/array_mmixed.ck+17−0
@@ -0,0 +1,17 @@
1// based on Robin Haberkorn's example
2int a[0][2];
3
4// instantiate arrays
5new int[2] @=> a["foo"];
6new int[2] @=> a["bar"];
7
8// fill them
923 => a["foo"][0];
1024 => a["foo"][1];
1132 => a["bar"][0];
1242 => a["bar"][1];
13
14// test them
15if( a["foo"][0] == 23 && a["bar"][1] == 42 )
16 <<< "success" >>>;
17
examples/array/array_resize.ck+35−0
@@ -0,0 +1,35 @@
1// instantiate a float array
2float argh[0];
3
4// print
5<<< "array size:", argh.size() >>>;
6
7// resize
84 => argh.size;
9
10// print
11<<< "array size:", argh.size() >>>;
12
13// set elements
143.0 => argh[0];
154 => argh[1];
165.0 => argh[2];
176 => argh[3];
18
19// print
20<<< "contents:", "">>>;
21for( int i; i < argh.size(); i++ )
22 <<< "argh[", i, "]:", argh[i] >>>;
23
24// recap
252 => argh.size;
26
27// print
28<<< "array size:", argh.size() >>>;
29
30// clear the contents
31argh.clear();
32
33// print
34<<< "array size:", argh.size() >>>;
35
examples/array/array_storage.ck+9−0
@@ -0,0 +1,9 @@
1// multi-dimensional array
2int a[2][2][2];
3// assignment
44 => a[0][0][1];
5// access
6a[0][0][1] => int b;
7
8// test
9if ( b == 4 ) <<<"success">>>;
examples/array/array_sub_assign.ck+14−0
@@ -0,0 +1,14 @@
1// multi-dimensional array
2// array to array assignment
3
4int a[2][2][2];
5int b[2][2];
6// assignment
71 => b[0][1];
82 => b[0][0];
9
10// assign b to 0th element of a
11b @=> a[0];
12
13// verify
14if ( a[0][0][1] == 1 ) <<<"success">>>;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t