Still not clear on exactly what you're trying but I think Raul is right. To
simplify your example, maybe you want something more along these lines?
gen1=: 1: NB. Define these 3 fns as verbs returning constants, to
simplify
gen2=: 2:
gen3=: 3:
condn=: 13 : '10000 5000 501 i. #y' NB. This may be the condition we're
testing?
condn&>(10000$1);(5000$1);501$1 NB. Test how the condition works on its
own
0 1 2
gen=: [EMAIL PROTECTED] NB. Put them all together in kind of
"nested if"
gen 501 501$1 NB. Test each expected condition...
3
gen 5000 1$1
2
gen 10000 1$1
1
gen 10$1 NB. Test an "impossible" case
|index error: gen
| gen 10$1
On 1/19/08, Kairit Sirts <[EMAIL PROTECTED]> wrote:
>
> > cond1 =: 2&|
> > Something1 =: <:
> >
> > cond2 =: >&100
> > Something2 =: -:
> > Something3 =: ]
> >
> > tni =: [EMAIL PROTECTED](cond1 (* >:)&:-.
> cond2)
> >
>
> Now I tried to rewrite my code by following your suggested pattern. The
> initial code is the following:
>
> Terns is of shape 10000 x 10000
> Pairs is of shape 5000 x 5000
> Solos is of shape 501 x 501
>
> Next =: 13 : '0 i.~(?+/y)>+/\y'
>
> Generate =: 3 : 0
> Text =. terns {~ ?10000
> For i.y do.
> tern =. terns i. _3{. Text
> pair =. Pairs i. _2{. Text
> if. tern < 10000 do.
> Text =. Text, next tern { terns
> Else.
> If. pair < 5000 do.
> Text =. Text, next pair { pairs
> Else.
> Text=. Text, next ({:text){ solos
> End.
> End.
> )
>
> I rewrote it like that:
>
> n=: 10000 5000 501
> argument =. (terns i. _3 {.text),(pairs i. _2{. Text),{:text
>
> gen1=:next@((0&{){&terns)
> gen2=:next@((1&{){&pairs)
> gen1=:next@((2&{){&solos)
>
> gen =: [EMAIL PROTECTED]({.I.-.=&n)
>
> Now I should be able to generate text with
> Text =: text, gen argument, but I get the length error and I don't
> understand what's wrong.
>
> Kairit Sirts
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm