0 Members and 2 Guests are viewing this topic.
enum Foo {X,Y,Z}switch(Foo) g1, g2;Foo f;...switch(f) { ... } // f is used as an INDEX for a look-up-table for this switch...switch(f) { ... } // ...and again in this switch....switch(g1) { // No index. This is simply 'goto (g1)' case X: // g1.X refers to the address of this location in code case Y: // g1.Y refers to this address, etc. ...}...switch(g2) { ... } // Likewise, g2 will have it's own switch, and it's own X,Y,Z...switch(g2) { ... } // ILLEGAL! (g1 and g2 are variables for ONE specific switch)...g1 = g2.X // ILLEGAL, because that would cause the switch on g1 to goto g2's "case X"
cofunc generate(:word) { for(i := 2; true; i++) { yield i; } }cofunc filter { func(:word) in; word prime; } (:word) { while(true) { i := in(); if(i % prime != 0) { yield i; } }}cofunc sieve(:word) { in := new generate{}; while(true) { prime := in(); yield prime; in = new filter{in, prime}; }}func main() { nextPrime := sieve{}; // Print first 100 primes: for(i := 0; i < 100; i++) { Print(nextPrime()); }}
cofunc generate(...) { ...i := 2;... } // word i = 2;cofunc filter(func(:word) in ...) { ...i := in();... } // word i = in();cofunc sieve(...) { ...in := new generate();... // *generate in = new generate(); ...prime := in();... // word prime = in();}func main() { ...nextPrime := sieve();... } // sieve nextPrime = sieve();
// ===== Previous setup for cofuncs ===== cofunc ABC(a:b:c) { ... } // a,b,c represent init args, call args, returns cofunc B(b) { ... } // short for B( :b: ) cofunc C(:c) { ... } // short for C( : :c) cofunc BC(b:c) { ... } // short for BC( :b:c) cofunc AB(a:b: ) { ... } // no short form for this cofunc AC(a: :c) { ... } // no short form for this func(b:c) f = BC(); // funcs declared with same call-args & returns // ===== Current setup for cofuncs ===== cofunc ABC{a}(b:c) { ... } // a,b,c represent init args, call args, returns cofunc B(b) { ... } // previously B( :b: ) cofunc C(:c) { ... } // previously C( : :c) cofunc BC(b:c) { ... } // previously BC( :b:c) cofunc AB{a}(b) { ... } // previously AB(a:b: ) cofunc AC{a}(:c) { ... } // previously AC(a: :c) func(b:c) f = ABC{a}; // func declaration matches that of cofunc ABC // ===== Example of using cofuncs as struct-funcs ===== cofunc blah { byte x, y; } (byte z : char) { ... } b := blah{1,2}; // Just like a struct! b.x = 5; char c = b(3); // Just like a func! func(byte:char) f = c; func(byte:char) f2 = blah{3,4};
(as you can see, barely anybody replies to your posts here, but this should change eventually).