If not for the bug ,/ would be better. ,/ does not
actually compute the result by inserting appends;
it is implemented by special code that "knows" what
the answer should be. The bug is in the special code.
ts=: 6!:2 , 7!:[EMAIL PROTECTED]
NB. special code, linear time
ts ',/y' [ y=: 1e6$'abc'
0.00290177 1.04954e6
NB. no special code, quadratic time
append=: ,
ts 'append/y' [ y=: 1e3$'abc'
0.00102443 5504
ts 'append/y' [ y=: 1e4$'abc'
0.0552841 34176
ts 'append/y' [ y=: 1e5$'abc'
7.45338 263552
----- Original Message -----
From: "Leigh J. Halliwell" <[EMAIL PROTECTED]>
Date: Saturday, April 7, 2007 10:58 am
Subject: RE: [Jprogramming] Singleton Reduction
> Thanks, Roger. I like the "f" solution better than the "append", and
> suspect that it will run faster than inserting a comma in between
> each item.
> I knew about ^: (0 or 1) as an "if" function; but did not realize
> that it
> could apply to the {. operator. Thanks again.
>
> Sincerely,
>
> Leigh
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Roger Hui
> Sent: Saturday, April 07, 2007 1:33 PM
> To: Programming forum
> Subject: Re: [Jprogramming] Singleton Reduction
>
> The monad ,/ should also work for this problem.
> That it does not is a bug in the interpreter and
> will be fixed for J6.02.
>
> $ ,/ 1$'a' NB. wrong
> 1
> append=: ,
> $ append/ 1$'a' NB. correct
>
> $ append/ 'a' NB. correct
>
> append/ 'abc' NB. correct
> abc
>
> ----- Original Message -----
> From: Roger Hui <[EMAIL PROTECTED]>
> Date: Saturday, April 7, 2007 10:25 am
> Subject: Re: [Jprogramming] Singleton Reduction
>
> > f=: {.^:(1=#)
> > f 'abc'
> > abc
> > $ f 'a'
> >
> > $ f ,'a'
> >
> > f^:proprosition y is equivalent to
> > if. proposition y do. f y else. y end.
> >
> > ----- Original Message -----
> > From: "Leigh J. Halliwell" <[EMAIL PROTECTED]>
> > Date: Saturday, April 7, 2007 10:14 am
> > Subject: [Jprogramming] Singleton Reduction
> >
> > > Dear J Forum:
> > >
> > > Let X1 =. 'A' and X2 =. 1$'A'. Now X1 and X2 look equal, but
> > > because of
> > > different ranks X1 does not equal X2. I would like to reduce
> a
> > > singleton to
> > > an atom. If #X is 1, {.X does this. But I don't want to take
> > the
> > > firstitem, if the string has more than one item. Can someone
> > tell
> > > me a simple or
> > > efficient tacit expression that reduces one-rank, one-item
> > arrays
> > > to atoms,
> > > and leaves other one-rank arrays unchanged? Can it be done
> > > without gerunds?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm