[Jprogramming] Simple J
Marc Simpson
marc at 0branch.com
Sat Nov 12 19:06:06 HKT 2011
On Sat, Nov 12, 2011 at 2:13 AM, Kip Murray <km at math.uh.edu> wrote:
> Verb k is my version of f written in "Simple J" which uses trains and
> rank but no other conjunction. The expected left argument is a string,
> right argument a list of boxed strings.
>
> k =: ( ([: +/ E.) > )"1 0
>
> 'bc' k 'a bc def';'ab cde f';'abc d ef' NB. Is 'bc' a substring?
> 1 0 1
>
> ' ' k 'ab';'abc';'abcd' NB. two spaces a substring?
> 0 0 0
Good stuff—but note that the following case is problematic,
'bc' k 'ab';'bc';'bcd';'ad';'a'
|rank error: k
| 'bc' k'ab';'bc';'bcd';'ad';'a'
In other words, padding with fill characters is a trade-off: on the
one hand incorrect results are yielded for whitespace tests, on the
other there are no length restrictions (length >= #x) placed on the
boxed strings.
When it's possible to use ;: as in Raul's example, the domain
restriction and whitespace issues are resolved,
'bc' k ;:'ab bc bcd ad a'
0 1 1 0 0
' ' k ;:'ab bc bcd ad a'
0 0 0 0 0
-M
More information about the Programming
mailing list