(Bad ;-) Example of using LazyEvaluation in a VisualBasic program.
(The objective of this exercise is to show that LazyEvaluation is complex and slow: That you shouldn't use it unless the computation is expensive/difficult, and the result won't be needed in many cases.)
Well, you've shown that it's complex (and maybe slow, got any numbers?) in VB. Since I'm not in a VB shop, what do I care?
I get it: if you take extra steps to avoid adding the numbers, then when you add the numbers you end up taking extra steps.
I suppose what we need now is an EagerEvaluationExampleInHaskell to show that LazyEvaluation is still complex and slow by comparison.
Example taken from the LazyEvaluation page: Compute...
Result = (a + b) + (c + d) + (a + b)
using LazyEvaluation.
Usage:
Dim lLazy As New clsLazyEvaluation
lLazy.a = a
lLazy.b = b
lLazy.c = c
lLazy.d = d
' (One normally assumes that there is some "distance" in time and/or code at this point.)
Result = lLazy.Result
Class definition for clsLazyEvaluation:
Option Explicit
'
' Attributes of the class:
'
Private mintA As Integer ' Inputs
Private mintB As Integer
Private mintC As Integer
Private mintD As Integer
Private mblnHaveResult As Boolean ' Internal
Private mintResult As Integer ' Output
Private Sub Class_Initialize()
mblnHaveResult = False
End Sub
Public Property Let a(ByVal pintNewValue As Integer)
mintA = pintNewValue
End Property
Public Property Get a() As Integer
a = mintA
End Property
Public Property Let b(ByVal pintNewValue As Integer)
mintB = pintNewValue
End Property
Public Property Get b() As Integer
b = mintB
End Property
Public Property Let c(ByVal pintNewValue As Integer)
mintC = pintNewValue
End Property
Public Property Get c() As Integer
c = mintC
End Property
Public Property Let d(ByVal pintNewValue As Integer)
mintD = pintNewValue
End Property
Public Property Get d() As Integer
d = mintD
End Property
Public Property Get Result() As Integer
If Not mblnHaveResult Then
mintResult = (mintA + mintB) + (mintC + mintD) + (mintA + mintB)
mblnHaveResult = True
End If
Result = mintResult
End Property
Very interesting, but why do your values come in pints and why are you growing mint? mint = member int, pint = parameter int