Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Closures?

8 views
Skip to first unread message

axtens

unread,
Feb 22, 2010, 2:15:14 AM2/22/10
to
G'day.

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.

Bob Barrows

unread,
Feb 22, 2010, 7:53:04 PM2/22/10
to
axtens wrote:
> G'day.
>
> 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.
>
no.
Paste your examople either here or better yet: .scripting.vbscript to get
more people to look at it
--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


axtens

unread,
Feb 23, 2010, 1:14:36 AM2/23/10
to
option explicit
class closure

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

0 new messages