I was watching an interview with John Hughes and he was asked if he missed laziness when he switched from Haskell to Erlang. As an answer he said yes and he used tools to "emulate" it. My question is: How does one emulate laziness in a strict language ? It Would be nice to see cools examples in mainstream languages.
Studies of motivation suggest that laziness may be caused by a decreased level of motivation, which in turn can be caused by over-stimulation or excessive impulses or distractions. These increase the release of dopamine, a neurotransmitter responsible for reward and pleasure.
The usual trick is to use a lambda
(I guess that would be fun
in Erlang).
Here is an example using Ruby:
Monad equivalent in Ruby
The basic idea is pretty simple... You take whatever expression you want to make lazy, wrap it in a zero-argument anonymous function, then evaluate that function when you want to force it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With