Apr
30
answered Estimate error in floating point calculations
Apr
29
awarded Supporter
Apr
29
awarded Scholar
Apr
29
accepted Scala Streams: Self-Reference, Function Calls and Lazy Evaluation
Apr
27
comment Scala Streams: Self-Reference, Function Calls and Lazy Evaluation
thanks - that link did indeed help.
Apr
27
answered Scala Streams: Self-Reference, Function Calls and Lazy Evaluation
Apr
26
awarded Teacher
Apr
26
answered sum of small double numbers c++
Apr
26
comment Scala Streams: Self-Reference, Function Calls and Lazy Evaluation
it's not like lazy val x: String = x.toUpperCase because in your snippet every character in that string needs to have a value before one can compute its upper case. Not so with my example. My example is more like lazy val x: String = "A" + x. This is (conceptually) an infinite string of A's. However, lazy evaluation is not supported via Strings in Scala (AFAIK) and so actually executing that snippet gives me a stack overflow. However, re-writing in terms of streams gives me the equivalent lazy val x: Stream[Char] = 'A' #:: x. This works perfectly, e.g. println(x(1)) prints 'A'.
Apr
25
comment Scala Streams: Self-Reference, Function Calls and Lazy Evaluation
what is wrong with it as far as I am concerned is the need for the calling code to look inside the SimNumericStream object: I should be able to implement the shift operator on the SimNumericStream object itself, hiding the implementation using Scala streams under the hood. Am I wrong, or does the fact that one form works whereas the other doesn't break the idea of referential transparency?
Apr
25
comment Scala Streams: Self-Reference, Function Calls and Lazy Evaluation
I guess I am struggling to see why this issue is also not present in the version that works. In that case we also have the "new SimNumericStream" within the definition of the same SimNumericStream (y). Self-replication is not what I'm looking for, just self reference. Perhaps asking the question another way, how would you define a "shift" function that returns a shifted stream and then use that function within the definition of the stream that's being shifted? Is there another way?
Apr
25
comment Scala Streams: Self-Reference, Function Calls and Lazy Evaluation
Thanks, but: def main(args: Array[String]): Unit = { lazy val shift = ( sns : SimNumericStream ) => new SimNumericStream( 0 #:: sns.scalstream ) lazy val y : SimNumericStream = shift(y) y.scalstream.take(10).print } Also produces the same (runtime) error whereas (manual) inlining of the function does not.
Apr
25
asked Scala Streams: Self-Reference, Function Calls and Lazy Evaluation