Generator/Exponential: Difference between revisions
Content added Content deleted
(→{{libheader|libco}}: Add some ugly code to check for memory allocation, and to free memory. C is being an awful language.) |
(→{{header|Go}}: better implementation. replaced entire program.) |
||
Line 232:
=={{header|Go}}==
Most direct and most efficient on a single core is implementing generators with closures.
<lang go>package main
Line 245 ⟶ 241:
// note: exponent not limited to ints
func
r = math.Pow(i, e)
}
// given two functions af, bf, both monotonically increasing, return a
// new function that returns values of af not returned by bf.
func newMonoIncA_NotMonoIncB_Gen(af, bf func() float64) func() float64 {
for {
a = af()
}
b = bf()
}
}
}
func main() {
fGen := newMonoIncA_NotMonoIncB_Gen(newPowGen(2), newPowGen(3))
▲ chSq := powCh(2)
▲ chF := make(chan float64)
for i := 0; i < 20; i++ {
}
for i := 0; i < 10; i++ {
fmt.Print(
}
fmt.Println("")
}</lang>▼
▲</lang>
Output:
<pre>
|