Please look at http://rosettacode.org/wiki/Function_composition#VBScript
and tell me if I've actually achieved a 'closure' or not. I have my
doubts.
Kind regards,
Bruce.
private composition
sub compose( f1, f2 )
composition = f2 & "(" & f1 & "(p1))"
end sub
public default function apply( p1 )
apply = eval( composition )
end function
public property get formula
formula = composition
end property
end class
dim c
set c = new closure
c.compose "ucase", "lcase"
wscript.echo c.formula
wscript.echo c("dog")
c.compose "log", "exp"
wscript.echo c.formula
wscript.echo c(12.3)
function inc( n )
inc = n + 1
end function
c.compose "inc", "inc"
wscript.echo c.formula
wscript.echo c(12.3)
function twice( n )
twice = n * 2
end function
c.compose "twice", "inc"
wscript.echo c.formula
wscript.echo c(12.3)
Outputs:
lcase(ucase(p1))
dog
exp(log(p1))
12.3
inc(inc(p1))
14.3
inc(twice(p1))
25.6