A little trick for catching any message send

1 view
Skip to first unread message

Igor Stasenko

unread,
Nov 23, 2008, 9:46:57 PM11/23/08
to Moebius project discussion
The class allows to catch any message sent to object and convert it to lambda:

For instance, if you add this mehod:

CVLambda>>pure
^ CVPureLambdaBuilder createProxyFor: self

Then you can build lambda with guarantee that you create a lambda,
even if CVLambda(or its superclass) responds to a message you sending.

For instance:
CVLambda one two selector

returns #two

But
CVLambda one two pure selector

returns ((<#one> #two) #selector)

You can even send:

CVLambda foo bar pure doesNotUnderstand: #bum

and it will return:
((<#foo> #bar) doesNotUnderstand: #bum)


Of course, this hacky class will work in squeak only. Because
implementation depends on VM.

--
Best regards,
Igor Stasenko AKA sig.

CVPureLambdaBuilder.st

Igor Stasenko

unread,
Nov 23, 2008, 10:34:37 PM11/23/08
to Moebius project discussion
Btw, i think it can be expanded even more for usage in a form like:

CVLambda foo bar wrappedUntil: #printString

so, it will remain wrapped with proxy until #printString message is sent to it.

Too bad, its mostly unusable in such form, because there are many
places with loops, which enter recursion.
And of course, because control flow optimized by compiler, like
#ifTrue:ifFalse: or #to:do: , which can't work with anything except
booleans or integers :)

Reply all
Reply to author
Forward
0 new messages