seems better than what I've been doing,
take
(*@[ * |@[ <. #@:]) {. ]
$ 2 take i.0
0
take =: ];.0 :: (i.@(0"_) )
$ 2 take i.0
0
it loses negative indexing though, so
take =: (];.0)`(];.0)`(] {.~ _1: * |@[ <. #@:])@.(*@[)^:(0 < #@])
_7 take i.6
0 1 2 3 4 5
_3 take i.6
3 4 5
_3 take i.0
3 take i.2 2
0 1
2 3
________________________________
From: Igor Zhuravlov <[email protected]>
To: Jprogramming <[email protected]>
Sent: Saturday, December 29, 2018 9:02 PM
Subject: [Jprogramming] Cut (;.) behavior consistency
A Cut (;.) is a convenient alternative to Take ({.) when there is a need to
ignore overtake:
4 {. i. 3
0 1 2 0
4 ];.0 i. 3
0 1 2
But is Cut's behavior consistent?:
2 ];.0 i. 2
0 1 NB. ok
2 ];.0 i. 1
0 NB. ok
2 ];.0 i. 0
|index error
| 2 ];.0 i.0
Shouldn't result be an empty list instead of error? However, the following
works:
0 ];.0 i. 0
NB. empty list, ok
--
Regards,
Igor
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm