Re:Why functional programming matters (1990) [pdf]
by mafribe on Thursday May 07, 2015 @03:25AM
(#9503705)
Scala doesn't have lazy evaluation of function arguments, it's got call-by-name.
The difference is that lazy evaluation caches the value an argument evaluates to the first time it is needed, so it's evaluated at most once, whereas call-by-name simply passes the parameter unevaluated and the result of evaluation is not cached, so might be computed more than once.
Consider this Scala program
object Main extends {
def tryit [ T ] ( block : => T ) : Unit = {
println ( "----- Running 1st block -----" )
block
println ( "----- Running 2nd block -----" )
block
println ( "--------- Finished ----------" ) }
def main ( args : Array [ String ] ) {
var i = -1
tryit ( { i += 1; println ( s"i = $i" ) } ) }
}
Re:Why functional programming matters (1990) [pdf]
by seanmcdirmid on Thursday May 07, 2015 @03:30AM
(#9503715)
Does scala not have lazy vals anymore?
Re:Why functional programming matters (1990) [pdf]
by mafribe on Thursday May 07, 2015 @03:49AM
(#9503771)
Sorry, I had forgotten about lazy vals. Thanks for reminding me. They are cached, so proper lazy [1], see e.g. https://stackoverflow.com/questions/3041253/whats-the-hidden...
Re:Why functional programming matters (1990) [pdf]
by justthistime_ on Friday May 08, 2015 @02:54AM
(#9510334)
Holy shit ... is your space bar broken?
Regarding lazyness by default, although you are right, I would say the lazy modifier found in Scala/ML derivatives/C#/D and the use of sequences/ranges kind of help half way there.