J: How to efficiently apply a verb to prefixes of suffixes?

Dan Oak

I have a list

   n =: i.3

and I want to have an adverb a such that u a n applies u to prefixes of suffixes of n:

   <a n
┌─────────────┬───────┬───┐
│┌─┬───┬─────┐│┌─┬───┐│┌─┐│
││0│0 1│0 1 2│││1│1 2│││2││
│└─┴───┴─────┘│└─┴───┘│└─┘│
└─────────────┴───────┴───┘

I've written a sentence that produces desirable result for verb <:

   ([: <@]\&.> <@]\.) n
┌─────────────┬───────┬───┐
│┌─┬───┬─────┐│┌─┬───┐│┌─┐│
││0│0 1│0 1 2│││1│1 2│││2││
│└─┴───┴─────┘│└─┴───┘│└─┘│
└─────────────┴───────┴───┘

but I cannot get how to make an adverb to use it with any verb.

I see another approach to this problem:

   a =: \\.
   <a n
┌─┬───┬─────┐
│0│0 1│0 1 2│
├─┼───┼─────┤
│1│1 2│     │
├─┼───┼─────┤
│2│   │     │
└─┴───┴─────┘
   ([: < (a: ~: ]) # ])"1(<a n)
┌─────────────┬───────┬───┐
│┌─┬───┬─────┐│┌─┬───┐│┌─┐│
││0│0 1│0 1 2│││1│1 2│││2││
│└─┴───┴─────┘│└─┴───┘│└─┘│
└─────────────┴───────┴───┘

but it is also written specifically for <, and maybe not efficient. And I still cannot get how to make an adverb.

It will be even better if I can get the following result:

   <a n
┌─┬───┬─────┬─┬───┬─┐
│0│0 1│0 1 2│1│1 2│2│
└─┴───┴─────┴─┴───┴─┘

For example:

   (10&#.)a n
0 1 12 1 12 2

Help me please. Thanks in advance.

Eelvex

There is (almost) already an adverb for this. It's the Spread (S:) which you want to apply to level 0.

E.g.

<\ each <\. n
┌─────────────┬───────┬───┐
│┌─┬───┬─────┐│┌─┬───┐│┌─┐│
││0│0 1│0 1 2│││1│1 2│││2││
│└─┴───┴─────┘│└─┴───┘│└─┘│
└─────────────┴───────┴───┘
< S:0 <\ each <\. n
┌─┬───┬─────┬─┬───┬─┐
│0│0 1│0 1 2│1│1 2│2│
└─┴───┴─────┴─┴───┴─┘

+/ S:0 <\ each <\. n
0 1 3 1 3 2

(10&#.)  S:0 <\ each <\. n
0 1 12 1 12 2

In other words, your a could be like this:

a =: 1 :'u S: 0 ([: <\&.><\.) y'

(edit) or, as @Tikkanz says in the comments below, you can avoid S: and use the more efficient:

a=: 1 : ';@([: u\&.> <@]\.)'

or

a=: 1 : ';@(<@(u\)\.)'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Excel prefixes or suffixes

From Dev

number of prefixes equal to suffixes

From Dev

How to remove prefixes and suffixes from filenames in a given directory?

From Dev

How to apply verb sequentially to vector and each single element of another vector in J

From Dev

Alternative to Levenshtein distance for prefixes / suffixes

From Dev

Capturing prefixes and suffixes using regex

From Dev

How do I apply vendor prefixes to inline styles in reactjs?

From Dev

Making a range verb in J

From Dev

Evaluate a string as a verb in J

From Dev

Evaluate a string as a verb in J

From Dev

How to efficiently apply a regex substitution on a Moose attribute?

From Dev

How to efficiently partially apply a function in R?

From Dev

Replacing only pronoun, noun, verb and adjective in a sentence with its corresponding tags, how could I do it efficiently in Python?

From Dev

Adding prefixes/suffixes to file names without typing it all over again?

From Dev

How to count suffixes in python?

From Dev

How to count suffixes in python?

From Dev

How to use VERB in url

From Dev

How to efficiently apply an operator to the cartesian product of two arrays?

From Dev

How to efficiently apply a function to each DataFrame of a Pandas Panel

From Dev

How do you apply the same action to multiple variables efficiently in Python?

From Dev

How to efficiently apply functions to values in an array based on condition?

From Dev

apply a verb to a sub-array, in place?

From Dev

Improve a working "Bulgarian Solitaire" J verb

From Dev

Better replacement for a huge "if x==2 / if x==3 / if x==4" chain adding prefixes and suffixes?

From Dev

What argument names do you prefer in constructors? Suffixes, prefixes or smth else?

From Dev

Better replacement for a huge "if x==2 / if x==3 / if x==4" chain adding prefixes and suffixes?

From Dev

neo4j: how to efficiently search value in list?

From Java

How to remove prefixes from strings?

From Dev

How to match phone number prefixes?

Related Related

  1. 1

    Excel prefixes or suffixes

  2. 2

    number of prefixes equal to suffixes

  3. 3

    How to remove prefixes and suffixes from filenames in a given directory?

  4. 4

    How to apply verb sequentially to vector and each single element of another vector in J

  5. 5

    Alternative to Levenshtein distance for prefixes / suffixes

  6. 6

    Capturing prefixes and suffixes using regex

  7. 7

    How do I apply vendor prefixes to inline styles in reactjs?

  8. 8

    Making a range verb in J

  9. 9

    Evaluate a string as a verb in J

  10. 10

    Evaluate a string as a verb in J

  11. 11

    How to efficiently apply a regex substitution on a Moose attribute?

  12. 12

    How to efficiently partially apply a function in R?

  13. 13

    Replacing only pronoun, noun, verb and adjective in a sentence with its corresponding tags, how could I do it efficiently in Python?

  14. 14

    Adding prefixes/suffixes to file names without typing it all over again?

  15. 15

    How to count suffixes in python?

  16. 16

    How to count suffixes in python?

  17. 17

    How to use VERB in url

  18. 18

    How to efficiently apply an operator to the cartesian product of two arrays?

  19. 19

    How to efficiently apply a function to each DataFrame of a Pandas Panel

  20. 20

    How do you apply the same action to multiple variables efficiently in Python?

  21. 21

    How to efficiently apply functions to values in an array based on condition?

  22. 22

    apply a verb to a sub-array, in place?

  23. 23

    Improve a working "Bulgarian Solitaire" J verb

  24. 24

    Better replacement for a huge "if x==2 / if x==3 / if x==4" chain adding prefixes and suffixes?

  25. 25

    What argument names do you prefer in constructors? Suffixes, prefixes or smth else?

  26. 26

    Better replacement for a huge "if x==2 / if x==3 / if x==4" chain adding prefixes and suffixes?

  27. 27

    neo4j: how to efficiently search value in list?

  28. 28

    How to remove prefixes from strings?

  29. 29

    How to match phone number prefixes?

HotTag

Archive