Raul wrote:
> {.^:(#@$) i.-5 4 3 2
> 119
> {., i.-5 4 3 2
> 119
Henry said:
> Point of nomenclature: every noun has a shape.
> All shapes are lists.
> The shape of an atom is an empty list.
So Henry's given us a big hint here:
'' ($,) i.-5 4 3 2
119
And, if you remember the recent thread "Operations on boolean lists" [1],
the hook ($,) is supported by special code. Thus:
first =: {.@:,`( {.^:(#@$) )`( {.^:_ )`( ''&($,) )
DATA =: i.-15#2
NB. Reasonably large data
assert (-: 1&|.) first`:0 DATA
NB. All give identical results
lrep =: (`:6) 1 : '5!:6 {.;:''u'' '
NB. Convert atomic rep to literal
ts =: time , space@:]
gts =: 4 : 'lr; ts (''('','')'',~ lr =. x lrep), ''y'''"0 _
NB. Gerund time & space
cgts =: (; (%"1 <./))&:>/@:|:@:gts
NB. Compare ts of gerund;
first cgts DATA
+---------+-------------+
|{.@:, | 38 228.222|
|{.^:(#@$)| 20.5 171.722|
|{.^:_ |72.75 456.278|
|''&($ ,) | 1 1|
+---------+-------------+
Not bad.
-Dan
[1] Top of operations on boolean lists thread:
http://www.jsoftware.com/pipermail/programming/2011-October/024417.html
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Raul Miller
Sent: Thursday, October 20, 2011 11:15 AM
To: Programming forum
Subject: Re: [Jprogramming] {. y produces an array.
{.^:(#@$) i.-5 4 3 2
119
{., i.-5 4 3 2
119
--
Raul
On Thu, Oct 20, 2011 at 10:44 AM, Marshall Lochbaum
<[email protected]> wrote:
> A more general solution is {.^:(#@$) , which will strip all the
dimensions
> off the array.
>
> Marshall
>
> On Thu, Oct 20, 2011 at 7:34 AM, Raul Miller <[email protected]>
wrote:
>
>> {. gets the first item from an array.
>>
>> You might be wanting lim=. {.,y (which will always have lim be a rank 0
>> array).
>>
>> But I do not have a good enough of a mental model of your data
>> structures to say for sure what you want.
>>
>> --
>> Raul
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm