It will only lead to confusion if a verb has the same name as a primitive in 
the Dictionary but performs a different function.  Users of the 'primitives’ 
add on would redefine the verb to its dictionary definition.  I have never 
found overtaking a problem and often find it very useful.   If you only need to 
operate on the an array of the length of the data then you do not need to use 
take.  If you are concerned about the case of empty data then your take should 
recognise that and take 0 items.


Your example of  update_firstfewindexes_where  is an example of a function 
where for most users the cost of learning about it will exceed the cost of 
writing  a specific verb for your task. However if you have a specific area of 
application where it often arises, then it would have a place in a library of 
functions for that area.  I do not see it as having a role in the base library. 






Sent from Surface





From: 'Pascal Jasmin' via Programming
Sent: ‎Monday‎, ‎29‎ ‎June‎ ‎2015 ‎3‎:‎18‎ ‎a.m.
To: [email protected]





one problem it solves is simply not overtaking (on positive indexes).  
Sometimes what you can want.

the other problem it solves is returning i.0 if there are no items, and then 
leveraging other J functions interaction with i.0 as a parameter.

one such interaction is in the last few examples I showed which is basically 
update_firstfewindexes_where function, but do nothing if the where clause 
returns no indexes.


----- Original Message -----
From: Raul Miller <[email protected]>
To: Programming forum <[email protected]>
Cc: 
Sent: Thursday, June 18, 2015 10:11 PM
Subject: Re: [Jprogramming] recomendation for take

I think you are trying to eliminate overtake - where the result is
longer than the right argument.

If that is the case, I do not think this definition achieves that:

   take =: (([ <. #@:]) {. ])
   _6 take i.4
0 0 0 1 2 3

But here's a deeper question: what problem does this solve? Is this
suggestion purely a matter of taste, or are there practical problems
which are better solved this way?

(If there are such problems, I'd be interested in hearing about them...)

Thanks,

-- 
Raul

On Thu, Jun 18, 2015 at 10:00 PM, 'Pascal Jasmin' via Programming
<[email protected]> wrote:
> The verb take is defined in later versions of J as {.
>
> I recommend instead (this definition will not overwrite the one in z)
>
> take =: (([ <. #@:]) {. ])
>
>  1 take i.2 NB. same as head
> 0
>
>  3 take i.2
> 0 1
>
>
>  (i.0) -:  1 take i.0
> 1
>
>
> the reason this definition is better, is if you want the following, you can 
> still just use {.
>
>  3 {. i.2
> 0 1 0
>  1 {. i.0
> 0
>  {. i.0
> 0
>
>
>  my question is does anyone use the word take in code, such that it would 
> break under this redefinition?  Even if you do, would you prefer having the 
> word take behave as above, and any code that depends on pure {. can just be 
> replaced with {. ?
>
> one of the reasons the code is useful (regardless of name)
>
> amdt =:2 : '(u (v{ ]))`(v"_)`]} ]'
>
>  2 + amdt (I.@:(2 < ])) i.5 NB. add 2 to items over 2
> 0 1 2 5 6
>
>
>  2 + amdt (I.@:(6 < ])) i.5 NB. no items pass filter, but no error, bc I. 
> returns i.0
> 0 1 2 3 4
>
>
>   2 + amdt (1 take I.@:(2 < ])) i.5 NB. just to first item over 2
> 0 1 2 5 4
>
>   2 + amdt (2 take I.@:(1 < ])) i.5 NB. just to first 2 items over 1
> 0 1 4 5 4
>
>
>   2 + amdt (1 take I.@:(8 < ])) i.5 NB. no error. no unwanted updates
> 0 1 2 3 4
>
>
>   2 + amdt (1 {. I.@:(8 < ])) i.5 NB. buggy - not intended
> 2 1 2 3 4
>
>   2 + amdt (2 {. I.@:(3 < ])) i.5 NB. buggy - not intended
> 2 1 2 3 6
> ----------------------------------------------------------------------
> 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

Reply via email to