Point of nomenclature: every noun has a shape. All shapes are lists.
The shape of an atom is an empty list.
(also, all nouns are arrays, ecch)
The way to turn a list of length 1 to an atom is
{. list
The way to turn any array with 1 atom to a list is
{. , array (or '' ($,) array)
The line you quote will leave lim as an atom as long as y has rank less
than 2.
# 5
1
$ 5
# {. 4 5 6
1
$ {. 4 5 6
# 1 {. 4 5 6
1
$ 1 {. 4 5 6
1
Henry Rich
On 10/20/2011 2:29 AM, Nick Simicich wrote:
> Today I was executing code where I wanted to compare a rational to a a
> computed list of about 1.8 million rationals. I wanted to be able to
> specify two items as input to the program in y, so I coded
>
> if. #y do. lim =. {. y else. lim =. 99r100 end.
>
> and then I had a line where I was comparing it to a long running total of
> booleans over a i.
>
> As long as I allowed it to accept the default, the program worked, but when
> I specified the value of y from the command line, y got a shape. Then I got
> a length error. When I stopped the program in debug, I found that the way I
> passed in y to lim, lim ended up having a shape - it was a 1 element array
> and not a scalar. In order to compare it using =, I had to do the following:
>
> , lim ="1 (step, 1) $
>
> And that seemed like a lot of manipulation and jumping through hoops.
>
> I did searches and other things, I am not sure I've read it anywhere, but I
> think I've seen discussion of it, I just can't find it.
>
> How do you "unarray" a thing? Turn it back into a scalar? Is it something
> horrible like ".": ? I didn't think of that this afternoon, and I'm not
> sure it would have worked. I probably could have done %/ 2 x: since I
> expected the input to be a rational, but I was drawing a blank at the
> time...is there an official way to scrub the arrayness off of a variable? A
> way to reshape it that scrubs the shape?
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm