Closed AleBeda closed 2 years ago
3(⊃,⊢~⊃)'Hello'
fails
Maybe we can change the description to say that it extracts all of the elements? :-)
But it doesn't.
This should work, but it's ugly: 3(⊃,{⍵/⍨⍺≠(⍳≢⍵)})'Hello'
I am not sure if this is worth adding to the APL Cart, at this point.
I was not able to make it shorter and tacit, because of the infamous overloading between replicate and reduce and also because there are monadic functions, not conducive to tacit style.
I wrote the original tacit function (⊃,⊢~⊃)
to be used with vectors of unique values as the right argument. However, while it was useful to me, I realize that it may not be so general to be useful for APL Cart.
{⍵⌷⍨⊂⍒⍺=⍳≢⍵}
Should it be generalised to include vector left arguments? {⍵⌷⍨⊂⍒⍺∊⍨⍳≢⍵}
This is a nice function. It seems to work already with vectors on the left, although the grade down reorganizes the matches always in the same order regardless the indexes on the left. I suppose that with vectors on the left, the grade down should not be used.
OK, I'll change it to {⍵⌷⍨⊂⍺∪⍳≢⍵}
then.
With this modification (which assumes ⎕IO←1
) your function seems to work with vector inputs on the left and respect the order of the indexes:
⎕IO←1
(3 7 1){⍵⌷⍨⊂⍒(⌽⍳≢⍺)(×@⍺)⍺∊⍨⍳≢⍵}'Hello world!'
lwHelo orld!
(1 7 3){⍵⌷⍨⊂⍒(⌽⍳≢⍺)(×@⍺)⍺∊⍨⍳≢⍵}'Hello world!'
Hwlelo orld!
(7+⍳3){⍵⌷⍨⊂⍒(⌽⍳≢⍺)(×@⍺)⍺∊⍨⍳≢⍵}'Hello world!'
orlHello wd!
To make it work with ⎕IO←0
, a 1+
is needed:
⎕IO←0
(2 6 0){⍵⌷⍨⊂⍒(⌽1+⍳≢⍺)(×@⍺)⍺∊⍨⍳≢⍵}'Hello world!'
lwHelo orld!
(0 6 2){⍵⌷⍨⊂⍒(⌽1+⍳≢⍺)(×@⍺)⍺∊⍨⍳≢⍵}'Hello world!'
Hwlelo orld!
(7+⍳3){⍵⌷⍨⊂⍒(⌽1+⍳≢⍺)(×@⍺)⍺∊⍨⍳≢⍵}'Hello world!'
orlHello wd!
The version with 1+
also works with ⎕IO←1
, so perhaps it is preferable.
⎕IO←1
(3 7 1){⍵⌷⍨⊂⍒(⌽1+⍳≢⍺)(×@⍺)⍺∊⍨⍳≢⍵}'Hello world!'
lwHelo orld!
{⍵⌷⍨⊂⍺∪⍳≢⍵}
Ha! this is better! :-)
Suggested additional code entry (required)
Description (required)
Class (optional)
Type (optional)
Group (optional)
Category (required)
Keywords (optional)
TIO (optional)
Note: By submitting this issue, you permit your contribution to be used without restriction.