helpful, thanks Raul.

I wasn't so much married to & as not wanting to duplicate both sides in fork. 
(it seemed like a job for &)

You failed on the bonus though :P


----- Original Message -----
From: Raul Miller <[email protected]>
To: Programming forum <[email protected]>
Cc: 
Sent: Thursday, September 24, 2015 10:35 PM
Subject: Re: [Jprogramming] towards a reshape arguments adverb

On Thu, Sep 24, 2015 at 10:05 PM, 'Pascal Jasmin' via Programming
<[email protected]> wrote:
> for vectors, this is ok
>
>    7 (([ $~ >.&# ) ; ] $~ >.&#) i.5
> ┌─────────┬─────────┐
> │7 7 7 7 7│0 1 2 3 4│
> └─────────┴─────────┘
>
> I thought this should work too though.
>
>    7  ;&($~ >.&#) i.5
> ┌─┬─────────┐
> │7│0 1 2 3 4│
> └─┴─────────┘
>
>
> Is there a way to chain & to get first result?

That depends, what is the purpose of this?

For example, this gets the first result:
   7 ((#~#) ; ] ) i.5

It doesn't use & but you could easily throw one in:
   7 ((#~#) ;&] ] ) i.5

Another approach, which accomplishes something a bit different, would be:
   7 ;/@,: i.5

Again, doesn't use & but "use X" specifications are broken more often
than not. But, if you really want to "use &" you can always easily add
it in:
   7 ;&]/@,: i.5
   7 ;/@,:&] i.5

Yet another approach, perhaps closer to your original result for a
broader domain, would be:
   7 (>.&# $&.> ;) i.5

But I don't know what you'd use that for...

> can you make an adverb that reshapes the right argument such that a
> rank0 verb would produce a sensible result, or more impressive,
> reshape both arguments if they are incompatible to reproduce "0 1
> behaviour? ie.
>
>   7 6 +/ i.5
> 7 8 9 10 11
> 6 7 8  9 10

I have no idea in this example what "sensible" means. But, sure, I
guess I can do this:

adv=: /

Thanks,

-- 
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

Reply via email to