--- danil osipchuk <[EMAIL PROTECTED]> wrote:
> Not all of the tasks can be expressed without the use of temp variables (at
> least efficiently or naturally). To put an example, write a tacit version of
> verb which checks if parenthesises in a string are balanced. My best version
> (*) in the case of a longs string (1M) involve a lot of array copying and
> are slow. Algorithmically effective explicit code (using a list as a stack)
> is intolerantly slow.
>
> (*)
> br=: 0=[:#[:,`([:}.])@.(3=[-[:{.])/ '])}[({'&([i.e.~#])
> br '{}()'
> 1
> br ' 9({}()'
> 0
>
That's the idea of J: to find a *functional* tacit
solution, where state is accumulative and passed
around between calls.
br1=: 0=[:#( (3 2$[) (] #~ [:-.@(+._1&|.) +./ . (E."1))^:_ e.~#])
br2=: '()[]{}'&br1
br2 'a[()]c'
1
br2 'a[()c'
0
_10{. 1e6$'a[()]c'
a[()]ca[()
3 ts'br2 A1' [ A1=: 1e6$'a[()]c'
0.0736727 7.3447e6
3 ts'br2 A2' [ A2=: A1,']'
0.0742985 7.3447e6
3 ts'br A1'
1.56664 5.24371e6
br 'a[()]ca[()' NB. false positive
1
br2 'a[()]ca[()'
0
For fast procedural approach, what's wrong with plain C?
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm