(⊃,(⍕2-⍨≢),⊃∘⌽)'accessibility' (⊃,(⍕2-⍨≢),⊃∘⌽)'accessibility'Here's a much more convoluted way, because everything is difficult in this language:
,/((⊂∘⍕∘⍴∘⊃@2)⊢⊂⍨((1@2)1,⍨¯1↓1⌷(↑(1,⊂))))'accessibility'
a11y
a frustratingly roundabout way to build up the boolean vector: 'accessibility'
1100000000001 ⍝ for penclose
without counting the length first.(Is there a way to drop from the middle of an array? "delete index 4 5 6"? Or to insert into the middle of an array? "Insert between elements 2 and 3"?)
To insert items from B into A at point N, you could (in pseudocode, I don't have time to play with APL right now!):
(Take N of A) , B , (Drop N of A)
To remove items from the middle of an array between N and M, I can think of two ways (I might have off-by-one errors here):
- (Take N of A) , (Drop M of A)
- Bools / A
where "Bools" is an array of 1/0 values, and the 1's indicate the elements to keep. As a dyadic verb, "/" means "compress", that is, to keep only the indicated elements from the right-hand object.
I'm sure there are other ways! These are the few ways that my limited brain could come up with. :)
Vector[2 8 5]←100
but instead of them getting value 100, they get deleted.Or like you can do ~ for set subtraction "without some values" like (⍳9)~5 7 but treating the right argument as indices to remove from the array, rather than values to remove from the array. I feel like there's two patterns which work in the same way as the thing I imagine and a space where the thing I imagine could exist but doesn't. Which I've now tried to code up:
4 9 8 7 10 11 {(~(⍳⍴⍵)∊⍺)/⍵}'accessibility'
accssty
It's not so ugly, but that took me down another rabbit hole of why I can't turn that into a train because there seems to be no way to force monadic iota when the trains design wants it to be dyadic. That is I want 3 4(⍳⍴)'accessibility' to come out the same as (⍳⍴)'accessibility' by somehow blocking the iota from having a left arg. Like 3 4(⍬∘⍳⍴)'accessibility' but Dyalog shoves the numbers in as a left arg then complains that the left arg is unavailable. Is this a problem with having to overload every glyph with a double meaning because of limitations on IBM 1960s printer technology, or is this my misunderstanding of tacit code and limited knowledge of operator behaviour, who knows. Maybe in another thousand errors I'll know a little more.I just enjoy the mental challenge sometimes.
There's no accounting for taste ;)
---
Abandon all hope, ye who read further.
I try not to worry too much about making things tacit. But there's a neat trick you can play in J to find a tacit definition for a non-tacit expression (if one can be found). I don't know if there is a counterpart in any common APL distributions.
First you define an expression in terms of values named 'x' and 'y'. Your goal is to find a tacit verb -- let's say 'T' -- that you can call as 'x T y'. (X is always on the left and y is always on the right, by convention -- compare with ⍺ and ⍵, sort of.) There is a J operation, cryptically named '13 :', which will try to make such an expresssion tacit.
Here's a quick attempt at writing 'N M drop Y', which will return Y but with the N:M section deleted. Again there might be off-by ones here (you could use Increment/Decrement to fix that):
Define some 'x' and 'y' values for experimenting:
x =: 5 10 NB. these will be our N:M indexes
y =: 'abcdefghijklmnopqrstuv'
Here are examples of Take and Drop (these are just to help you
translate between APL and J): 5 {. y
abcde
10 }. y
klmnopqrstuv
Monadically the same verbs mean First and Last: {. x
5
}. x
10
With M and N defined as the first ({.) and last (}.) values of X, take
M from Y, and join (,) it up with the result of dropping N from Y: (({. x) {. y ) , (}. x) }. y
abcdeklmnopqrstuv
Close enough! Now here's where we invoke the 'make tacit' verb, '13
:'. We have to wrap the original x/y expression in quotes, to make it
a string, and then call it like this: 13 : '(({. x) {. y ) , (}. x) }. y'
(] {.~ [: {. [) , ] }.~ [: }. [
There's the magic. The tilde (~) is like ⍨ in APL, and the bare [ and
] represent 'take left value' and 'take right value'. The [: word is
called a 'cap' and is used to limit the left side of a verb
fork. (Sorry, I don't know the equivalent in APL.)And that's our tacit version. We can try it out, give it a name, and try it out again:
x ( (] {.~ [: {. [) , ] }.~ [: }. [ ) y
abcdeklmnopqrstuv
drop =: (] {.~ [: {. [) , ] }.~ [: }. [
x drop y
abcdeklmnopqrstuv
5 10 drop 'abcdefghijklmnopqrstuv'
abcdeklmnopqrstuv
If you've truly abandoned all hope, the J vocabulary is listed here:
https://code.jsoftware.com/wiki/NuVocBut I'm going to have to read more to work out what/how the tacit version works because I have no intuition for telling where the x and y or ⍺ ⍵ enter into them.
Dyalog have this document for tips for translating d-fns into tacit form: https://dfns.dyalog.com/n_tacit.htm but how that compares to what '13 :' does internally..
This sort of feels like we are two tourists, trying to help each other translate between two languages that neither of us speaks very well. :)
These two pages might help you to build an intuition about how J does verb trains. The diagrams help to explain where the x and y values are used throughout (and where they are not).
https://code.jsoftware.com/wiki/Vocabulary/hook
https://code.jsoftware.com/wiki/Vocabulary/fork
I'm starting to be able to write long-ish forks in J without mechanical help, although I usually get them wrong the first dozen times. Practice makes perfect, I guess!
I'm planning to do this year's Advent of Code puzzles (https://adventofcode.com/) in J this year... at least until I reach a problem that explodes my brain. I'm hoping that this will give me something concrete to sharpen my skills on.
Vector[(iota rho Vector) set-minus indices to remove]