Here's a correction to ins2 and a more compact model.
id=: 1 : ('".''v=.'',u b. 1';'v')
ins1=: 1 : 0
z=. u id y
for_i. |.y do.
z=. i u z end.
)
However, insert most likely modeled as below
ins2=: 1 : 0
if. 0=#y do. u id y return. end.
z=. {:y
for_i. }.|.y do.
z=. i u z end.
)
--- Oleg Kobchenko <[EMAIL PROTECTED]> wrote:
> So monad u/ returns {.y if 1=#y regardless of u?
>
> One might think that it would be different,
> with rank 1 arguments, for atom valued +/ and
> vector valued ,/ when 1~:#y.
>
> ins2=: 1 : 0
> if. 0=#y do.
> ".'v=.',u b.1
> v y end.
^ should return here
>
> That is when 1=#y, u is not even accessed in any way
> even for identity.
>
> $bogus/ 'a'
>
> $bogus/ ,'a'
>
> $bogus/ ,'ab'
> |value error: bogus
> | $ bogus/,'ab'
>
>
> bogus ins2 1
> 1
> bogus ins1 1
> |value error: bogus
> | ".'v=.', u b.1
>
>
> --- Roger Hui <[EMAIL PROTECTED]> wrote:
>
> > 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?
> > > > Thanks.
> > > >
> > > > Sincerely,
> > > >
> > > > Leigh
____________________________________________________________________________________
Get your own web address.
Have a HUGE year through Yahoo! Small Business.
http://smallbusiness.yahoo.com/domains/?p=BESTDEAL
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm