Array contains selector?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Array contains selector?

John Whittaker-2
Hello Dolphineers,

I've been sort of half-heartedly trying to port a regular expression library
written by Vassili Bykov to Dolphin.  Some of it works, and some doesn't.
Currently I'm stumped by some code that attempts to (I think) return blocks
which can be used to possibly match subexpressions.  There is a message sent
to an array in this code that uses a selector which Dolphin doesn't have,
and I'm not quite sure what this selector returns.  My first attempt to
create an equivalent with Dolphin has failed, so I'm asking for some advice
from those who know Smalltalk and Dolphin better than I do.

Here's the method:

determineTestMethod
 "Answer a block closure that will work well as a can-match predicate.
 Answer nil if no viable optimization is possible (too many chars would
 be able to start a match)."

 | testers |
 (conditions includes: #any) ifTrue:[^nil].
 testers := OrderedCollection new: 5.
 #(prefixTester nonPrefixTester conditionTester predicateTester
nonPredicateTester)
  do: [:selector |
   | tester |
   tester := self perform: selector.
   tester notNil ifTrue: [testers add: tester]].
 testers isEmpty ifTrue: [^nil].
 testers size = 1 ifTrue: [^testers first].
 testers := testers asArray.

"This is my wrong attempt!"
 ^[:char :matcher |
              | result |
               testers do: [:t | result := result or: [ (t value: char
value: matcher)]].
               result.].

"This is the old code which doesn't work in Dolphin"
 "^[:char :matcher | testers contains: [:t | t value: char value: matcher]]"


Thanks,

John Whittaker


Reply | Threaded
Open this post in threaded view
|

Re: Array contains selector?

John Aspinall
John,

>
> "This is the old code which doesn't work in Dolphin"
>  "^[:char :matcher | testers contains: [:t | t value: char value:
matcher]]"
>

#contains: is the same as #anySatisfy: in Dolphin, so you should just be
able to say:

^[:char :matcher | testers anySatisfy: [:t | t value: char value:
matcher]]

In fact, Dolphin used to implement this method as #contains: but this was
phased out with v3. Similarly, the current Dolphin method #allSatisfy: used
to be known as #conform: - something to bear in mind; if the code you're
porting uses #contains: it may well use #conform: as well.

HTH.

John Aspinall
Solutions Software


Reply | Threaded
Open this post in threaded view
|

Re: Array contains selector?

Bill Schwab-2
In reply to this post by John Whittaker-2
John,

Try replacing #contains: with #anySatisfy:.  I think you'll find that you
are suffering from ANSI compliance growing pains.  Ultimately, we'll all
benefit from more portable code, but, for a while, some old stuff will break
like this.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Array contains selector?

John Brant
In reply to this post by John Whittaker-2
"John Whittaker" <[hidden email]> wrote in message
news:9cmp3g$873$[hidden email]...
> I've been sort of half-heartedly trying to port a regular expression
library
> written by Vassili Bykov to Dolphin.  Some of it works, and some doesn't.
> Currently I'm stumped by some code that attempts to (I think) return
blocks
> which can be used to possibly match subexpressions.  There is a message
sent
> to an array in this code that uses a selector which Dolphin doesn't have,
> and I'm not quite sure what this selector returns.  My first attempt to
> create an equivalent with Dolphin has failed, so I'm asking for some
advice
> from those who know Smalltalk and Dolphin better than I do.
>
> ...
>
> "This is the old code which doesn't work in Dolphin"
>  "^[:char :matcher | testers contains: [:t | t value: char value:
matcher]]"

#contains: is a VisualWorks method and is equivalent to #anySatisfy:.

BTW, you might want to look at the regular expression support in Microsoft's
VBScript Regular
Expressions(http://msdn.microsoft.com/scripting/default.htm?/scripting/VBScr
ipt/doc/vsobjRegExp.htm). You can use Dolphin's ActiveX component wizard to
create the classes. Assuming you have component installed, it should only
take a few minutes to get it up and running...


John Brant


Reply | Threaded
Open this post in threaded view
|

Re: Array contains selector?

John Whittaker-2
Thanks everyone for the responses.  I think I might try both the VBScript
and the Smalltalk RE's now that I know about both.

John Whittaker

>
> BTW, you might want to look at the regular expression support in
Microsoft's
> VBScript Regular
>
Expressions(http://msdn.microsoft.com/scripting/default.htm?/scripting/VBScr
> ipt/doc/vsobjRegExp.htm). You can use Dolphin's ActiveX component wizard
to
> create the classes. Assuming you have component installed, it should only
> take a few minutes to get it up and running...
>
>
> John Brant
>
>