Seeing the SICP made a very beautiful and very cute stream in Scheme, itch, ready to use C / Java to do one. The result failed, it was depressed.
C naturally try Templates, although it is usually annoying this thing-variation error, the long-term long does not say, the function that is not used is not checked, it is very annoying, but doing toys or can be used. After using C Template, after the entire stream is finished, the value is divided into two phases: first compiled from Comipler (partial value, determine all required calculations), then run the program, to get the Nth in Stream Elements, before n elements, this N must be given by the compile period. This makes me very unhappy. Later, because I can't directly derive the return type, I didn't do it. It is really not used. (Although it is a toy)
Try to see Java, I initially feel very good, but there is a difficult point: Delay (Proc, Arg1, Arg2, ...) Returns a promise, which is a PROMISE Practical Promise.eval () To get Proc (Arg1, Arg2,. ..), but the number of arg is not ... use the annoying enumeration (no parameters to n parameters)? ? Then PROC is another interface function and then derived one by one? ? Too Messy! Although C is doing this, but ready-made Boost :: function is available, it is not a matter, it is better, DELAY can be made with boost :: bind, which is really labor-saving. Here is good, you have to go ... The variable parameters are only in Java 1.5. I am too lazy, and every proc handles yourself to check Argument Types is not very elegant ... but at least here is feasible, But because it is too ugly, I didn't do it.
There may be C # / java1.5 in a day, C heart can also continue, reprint reprinting, today will come here today.
?
Appendix: About STREAM mentioned above:
First, introduce the basic syntax of Scheme: (Proc Arg1 Arg2) is a function name, arg1, arg2, and call this function, and the value of the expression is the value returned by PROC. (consx x y) is a binary group that returns (x, y), and can be obtained by using (CONS X Y), (CDR (CONS X Y) is Y. It's so much, the following is the original book about stream.
http://mitpress.mit.edu/sicp/full-text/book/book-z-h-24.html#%_sec_3.5