September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,2 +0,0 @@
|
|||
---
|
||||
note: Object oriented
|
||||
|
|
@ -1,15 +1,11 @@
|
|||
void
|
||||
show_sublist(list l)
|
||||
{
|
||||
integer i;
|
||||
integer i, v;
|
||||
|
||||
i = 0;
|
||||
while (i < l_length(l)) {
|
||||
if (i) {
|
||||
o_space(1);
|
||||
}
|
||||
o_integer(l_q_integer(l, i));
|
||||
i += 1;
|
||||
for (i, v in l) {
|
||||
o_space(sign(i));
|
||||
o_integer(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -17,13 +13,12 @@ void
|
|||
show_list(list l)
|
||||
{
|
||||
integer i;
|
||||
list v;
|
||||
|
||||
i = 0;
|
||||
while (i < l_length(l)) {
|
||||
for (i, v in l) {
|
||||
o_text(" [");
|
||||
show_sublist(l_q_list(l, i));
|
||||
show_sublist(v);
|
||||
o_text("]");
|
||||
i += 1;
|
||||
}
|
||||
|
||||
o_byte('\n');
|
||||
|
|
@ -34,10 +29,7 @@ multiple_distinct(integer n, object o)
|
|||
{
|
||||
list l;
|
||||
|
||||
while (n) {
|
||||
l_append(l, o);
|
||||
n -= 1;
|
||||
}
|
||||
call_n(n, l_append, l, o);
|
||||
|
||||
return l;
|
||||
}
|
||||
|
|
@ -57,7 +49,7 @@ main(void)
|
|||
l = multiple_distinct(8, z);
|
||||
|
||||
# modify one of the sublists
|
||||
l_r_integer(l_q_list(l, 3), 0, 7);
|
||||
l_q_list(l, 3)[0] = 7;
|
||||
|
||||
# display the list of lists
|
||||
show_list(l);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
// version 1.1.2
|
||||
|
||||
class Foo {
|
||||
val id: Int
|
||||
|
||||
init {
|
||||
id = ++numCreated // creates a distict id for each object
|
||||
}
|
||||
|
||||
companion object {
|
||||
private var numCreated = 0
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val n = 3 // say
|
||||
|
||||
/* correct approach - creates references to distinct objects */
|
||||
val fooList = List(n) { Foo() }
|
||||
for (foo in fooList) println(foo.id)
|
||||
|
||||
/* incorrect approach - creates references to same object */
|
||||
val f = Foo()
|
||||
val fooList2 = List(n) { f }
|
||||
for (foo in fooList2) println(foo.id)
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
-- get an array of directory objects
|
||||
array = fillArrayWith(3, .directory)
|
||||
say "each object will have a different identityHash"
|
||||
say
|
||||
loop d over array
|
||||
say d~identityHash
|
||||
end
|
||||
|
||||
::routine fillArrayWith
|
||||
use arg size, class
|
||||
|
||||
array = .array~new(size)
|
||||
loop i = 1 to size
|
||||
-- Note, this assumes this object class can be created with
|
||||
-- no arguments
|
||||
array[i] = class~new
|
||||
end
|
||||
|
||||
return array
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
# WRONG
|
||||
my @a = Foo.new xx $n;
|
||||
|
|
@ -1 +0,0 @@
|
|||
my @a = map { Foo.new }, ^$n
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
sequence s = repeat("x",3*rand(3))
|
||||
?s
|
||||
s[rand(length(s))] = 5
|
||||
?s
|
||||
s[rand(length(s))] &= 'y'
|
||||
?s
|
||||
s[rand(length(s))] = s
|
||||
?s
|
||||
|
|
@ -0,0 +1 @@
|
|||
sequence s = repeat(my_func(),5)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
sequence s = repeat(0,5)
|
||||
for i=1 to length(s) do
|
||||
s[i] = my_func()
|
||||
end for
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
n:=3;
|
||||
n.pump(List) //-->L(0,1,2)
|
||||
|
||||
n.pump(List,List) //-->L(0,1,2), not expected
|
||||
because the second list can be used to describe a calculation
|
||||
n.pump(List,List(Void,List)) //--> L(L(),L(),L()) all same
|
||||
List(Void,List) means returns List, which is a "known" value
|
||||
n.pump(List,List.fpM("-")) //--> L(L(),L(),L()) all distinct
|
||||
fpM is partial application: call List.create()
|
||||
|
||||
n.pump(List,(0.0).random.fp(1)) //--> 3 [0,1) randoms
|
||||
L(0.902645,0.799657,0.0753809)
|
||||
|
||||
n.pump(String) //-->"012", default action is id function
|
||||
|
||||
class C{ var n; fcn init(x){n=x} }
|
||||
n.pump(List,C) //--> L(C,C,C)
|
||||
n.pump(List,C).apply("n") //-->L(0,1,2) ie all classes distinct
|
||||
Loading…
Add table
Add a link
Reference in a new issue