And there is adverse :: too
like1 =: [: *./ = +. '?' E. ]
like3=:like1 :: 0:
'abcabc' like3 'abc?bc'
1
'abcabc' like3 'abc?bcc'
0
On 4/9/2011 6:35 AM, Steven Taylor wrote:
> Hi,
>
> as an exercise, I decided to make a simple "like" operator
>
> like=:([:*./([=])+.('?'E.]))
> NB. in english: get membership flags where '?' is in the set y
> NB. OR that with the comparison flags
> NB. *./ insert-AND to get the result
>
> the problem with this "like" operator is that x and y portions must be the
> same length. For example:
> 'abcaabc' like 'abc?abc'
> 1
> 'Abcaabc' like 'abc?abc'
> 0
> 'abcaabc' like 'abc?ab'
> |length error --- NB. fair enough that's how equals '=' is defined
>
> Is there an easy way to do guard conditionally, but to do this tacitly? i.e.
> the lengths are different, so return fail/zero?
> ideas so far:
> * email the list without fully exploring the possibilities ;)
> * look at J's regex library (did this a little)
> * implement something like "stretch=: [$],($,:@{:)" but with an unlikely
> non-ASCII character (hack so *bad*).
> * convert characters to numbers. move elements to a 2D array pre-filled
> with null whose right bound is the max of #x,#y (i.e.>/ (#x,#y). Continue
> on from there. create various verbs + flatten it afterwards to get tacit
> version. (not done yet).
>
> thanks,
> -Steven
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
Clifford A. Reiter
Lafayette College, Easton, PA 18042
http://webbox.lafayette.edu/~reiterc/
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm