434
questions
1
vote
2
answers
65
views
How to use local variables in nested verbs?
Perhaps there's no facility to do this in the J language, but when I write:
succession =: monad define
greg =. 1 2 3
tom =. {{ greg }}
tom y
)
and then call succession 'season 1', I get the ...
2
votes
1
answer
47
views
How to reshape an array with an arbitrary size in one dimension?
How would you go about reshaping a length-N 1D array into an (N/2) x 2 array? In numpy, for example, you can use -1 in place of N/2 when reshaping:
>>> x = np.array([1,2,3,4])
>>> x....
0
votes
0
answers
88
views
What does 'm' stand for in an inline function?
What's going on that makes this code work? It seems that using m in an anonymous verb (if that's what it's called) turns the verb into a postfix operator.
1 {{ 1 + m }}
2
If I replace the m with y ...
3
votes
3
answers
134
views
Why is Insert (fold) right associative
I expected
-/ 1 2 3 4
_8 NB. ((1-2)-3)-4
but I got
-/ 1 2 3 4
_2 NB. 1-(2-(3-4))
I there a reason for this? How do I get the associativity that I was expecting? If there are relevant sections in the ...
2
votes
2
answers
79
views
Alignment issue when printing formatted prime numbers in J language
I am a relatively new programmer in J-Lang and recently discovered its efficacy in Code Golfing, where it excels in scoring. I am currently working on a coding problem that involves printing all prime ...
2
votes
1
answer
196
views
Can Prolog-like unification be expressed in a point free way?
Pattern matching can be implemented using a point free style, and there are many articles on the internet about it. I'm wondering if the more generalized case also holds, i.e. is it possible to ...
4
votes
1
answer
155
views
How to unbox a list of boxed lists of differing lengths in J?
Given the following list of boxed lists of differing lengths…
┌──────────────┬───────────┬─────┬───┐
│0 2 3 4 7 9 11│9 7 4 3 2 1│1 2 3│3 1│
└──────────────┴───────────┴─────┴───┘
How can I create a ...
2
votes
2
answers
387
views
How to get user input in the J programming language
I'm very new to the J programming language, so I got interested in array programming languages and decided to give it a go.
Unfortunately, It's a very niche language, meaning that there aren't many ...
1
vote
3
answers
210
views
Print char of string uppercase if it is a vowel and lowercase if it is a consonant
I am trying to come up with a verb that will take a string as input
and printa character uppercase if it is a vowel i.e. (aeiou) or lowercase
if it is a consonant.
s=:'authority'
t=:<&>s
│a│...
3
votes
1
answer
120
views
Jconsole is complaining "file name error"
I am having trouble compiling and running J Programming Language
The Jconsole binary file (From J Language) throws an error when executed:
|file name error
| 0!:0 y
it compiled almost ...
0
votes
1
answer
97
views
How can I fix 'noun result was required' error in J?
I'm trying to do the 4th Advent of Code problem using J, and I've ran into lots of problems, but now I have a code that looks like this:
fn =. < 'D:/PyCharm/AOC/output4.txt'
data =. freads fn
...
2
votes
0
answers
121
views
Trying to understand why my custom function seems to be ignoring most of it's arguments
Defining a simple fibonacci function as:
fib=: verb : '{. (({: , +/ )^:y) 0 1'
I expected to be able to call it as
fib 5 6 7 NB. expected 5 8 13
but instead I get
fib 5 6 7
5 8
Trying to ...
2
votes
1
answer
198
views
Convert boxed array to normal array?
Suppose I have a boxed array like;
┌─┬─┬─┐
│1│2│3│
└─┴─┴─┘
how do I covert it to a normal array such as 1 2 3?
2
votes
1
answer
105
views
Convert array of strings to array of integers
How do I convert types in J?
For example, how to I convert an array of strings like "4" "78" "0" "_1" to an array of numbers like 4 78 0 _1
2
votes
1
answer
74
views
Replace atom in array of strings
Suppose I have an array of strings "31,793.1" "29,798.6" "30,455.7" "29,700.9"
How do I replace , with nothing to give me "31793.1" "29798.6"...
3
votes
2
answers
177
views
Read column of CSV file as array
I am trying to read a column from a CSV file into an array.
So far I have successfully read the file with the code below.
load 'csv'
data =: readcsv '/Users/max/Desktop/prices.csv'
Typing data in ...
6
votes
2
answers
217
views
What is the "j" expression for the "maximum consecutive ones" problem?
In the paper "Combinatory Logic and Combinators in Array Languages" they give a solution in APL:
vec ← 1 1 0 1 1 1 0 0 0 1
⍝ split (partition) on zeroes
⊆⍨vec
┌───┬─────┬─┐
...
4
votes
0
answers
94
views
How to expand memoization table in J
Previous discussion is on Memoization in J which doesn't answer the issue. The problem is that using memoization M. somehow makes the program much slower.
I encountered the same problem. Consider this ...
2
votes
1
answer
104
views
What does the dyad `=` do to boxed strings?
If x were a boxed string, I expect x=<'ABC' to compare the >x to 'ABC' to see if they are equal, but the following example shows that this is not the case. The J vocabulary document doesn't say ...
1
vote
2
answers
171
views
Building an array of verbs in J
Is it possible to build arrays of verbs?
I've tried this:
f =: >:
f2 =: f f
There's no syntax error but f2 is clearly not an array of verbs.
For instance
f2 yields f f
$ f2 yields $ f2
0 { f2 ...
3
votes
1
answer
130
views
In j, how can I define a verb locally in one scope and pass it to a defined adverb?
I am getting an unexpected value error when I use a name to pass a verb as the argument to an adverb.
The adverb (integer binary search with predicate u and bounds x):
bsearch=: adverb define
r=. y ...
2
votes
1
answer
131
views
Amend with bond to new data shows unexpected behaviour
I have been using J for a couple of weeks now and recently started using it for simple problems rather than just toying with concepts.
This problem needs to replace all x characters in a string into y,...
1
vote
1
answer
144
views
How to turn a table or matrix into a (flat) list in J
I know how to reshape a list into a table. But how do I turn a table into a list or uni- dimensional array.
my_list=:3 4 $i.12
0 1 2 3
4 5 6 7
8 9 10 11
And is it better to perform operations on ...
2
votes
1
answer
121
views
How to run dissect in J?
I have J9.02 installed in Debian-based OS. I try to run dissect but it fails:
load 'debug/dissect'
dissect '10 + i. 3 3'
value error
|value error: wd
| wd DISSECT
|value error: wd
| ...
3
votes
2
answers
121
views
How to define selection using index function in J
Let's assume I have a following tensor t:
]m=: 100 + 4 4 $ i.16
100 101 102 103
104 105 106 107
108 109 110 111
112 113 114 115
]t=: (m ,: m+100) , m+200
100 101 102 103
104 105 106 107
108 109 ...
1
vote
1
answer
189
views
How to exit the J console?
I recently downloaded j902 and can launch the console from my terminal, but I don't know how to exit. I tried “Ctrl + C” and "exit" but they did not work.
How do I exit the J console?
3
votes
1
answer
170
views
Find 4-neighbors using J
I'm trying to find the 4-neighbors of all 1's in a matrix of 0's and 1's using the J programming language. I have a method worked out, but am trying to find a method that is more compact.
To ...
3
votes
2
answers
151
views
Writing custom verbs in J
When you write your custom verbs(functions) should you use the following convention:
convert degrees fahrenheit to celsius.
centigrade =: 3 : 0
t1 =. y - 32
t2 =. t1 * 5
t3 =. t2 % 9
)
...
1
vote
0
answers
100
views
where does j save the result of its last operation?
In python's repl, _ holds the value of the last operation.
Where is the value of the last operation saved in the j repl?
2
votes
0
answers
94
views
what does 1: mean in the verb train (100 $ - {. 1:)"0
the j solution to the 100 doors problem in rosetta code is ~:/ (100 $ - {. 1:)"0 >:i.100
>: i. 100 means 'make a list of numbers from 1 to 100'
(100 $ - {. 1:)"0 >: i. 100 means '...
2
votes
1
answer
99
views
How to use arbitrary selector in interchange in J lang?
Let's assume we have a vector and matrix like below:
r =: 100 + 5 5 $ i.25
r
100 101 102 103 104
105 106 107 108 109
110 111 112 113 114
115 116 117 118 119
120 121 122 123 124
v =: 100 + 5 $...
2
votes
3
answers
158
views
How do I negate a selector in J lang?
I am playing with selection. Let's look at the initial example:
rarg=. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
_1 (<(<0 1),(<0 1)) } ( 4 4 $ rarg)
_1 _1 2 3
_1 _1 6 7
8 9 10 11
12 13 ...
3
votes
2
answers
117
views
different result once square root is added inside tacit
Very new to J. I love it but still far from fluent in it.
I have managed to hit an issue and I don't know why it is happening. If somebody could please explain why this is occuring I could learn more ...
2
votes
2
answers
181
views
Sum of arrays with repeated indices
How can I add an array of numbers to another array by indices? Especially with repeated indices. Like that
x
1 2 3 4
idx
0 1 0
y
5 6 7
] x add idx;y NB. (1 + 5 + 7) , (2 + 6) , 3 , 4
13 8 3 ...
3
votes
1
answer
136
views
Need help parsing the meaning of "i.~"
I'm trying to understand the solution for day 1 part 2: https://code.jsoftware.com/wiki/Essays/Advent_Of_Code#Part_2
PART2=: >: _1 i.~ +/\ 1 _1 mp '()'=/read'input'
I feel like I understand most ...
2
votes
1
answer
147
views
How to drop columns of csv data in J
I have a lot of csv files that I have to drop the date column.
I have a J line that reads in csv file into a numeric array, rdtabfile =: (0&".;.2@:(TAB&,)@:}:);._2) @ ReadFile @<
2
votes
1
answer
90
views
amend a subarray in place in j?
I've got two ways to amend a subarray in J but I don't like either of them.
(Imagine selecting a rectangle in a paint program and applying some arbitrary
operation to that rectangle in place.)
t =. ...
1
vote
1
answer
111
views
Using less trivial random generation in J lang
I am experimenting with random generation using J and would have a couple of questions that occured:
If I want to pick random 10-character word I can use
(?10 # 26) { 'abcdefghijklmnopqrstuvwxyz'
...
4
votes
4
answers
119
views
Get whole result when using J console
When using J console ijconsole I get only results up to some. For example,
ijconsole -js "a=. 3 3 5 6 " "echo 200 $ a" "exit''"
3 3 5 6 3 3 5 6 3 3 5 6 3 3 5 6 3 3 5 6 ...
2
votes
0
answers
89
views
J packages with sparse matrix algorithms
Are there any J packages with sparse matrix algorithms that enhance the functionalities mentioned here:
https://www.jsoftware.com/help/dictionary/d211.htm ?
For example, Singular Value Decomposition (...
4
votes
3
answers
1k
views
Write 4 : 'x&{.&.;: y' tacitly
Conor Hoekstra recently solved a Leetcode problem in APL https://youtu.be/QtvvQ7MdwKY The problem is to take the first x words from a character string y
In J, using &. (Under) and ;: (Words) I can ...
4
votes
2
answers
217
views
Sorting words in a string by their length in J
I have the following string:
s=:'when can we dance'
I can find the length of each word with this:
# each ;:s
I can sort the lengths in ascending/descending order:(/:~) # each ;:s which gives me boxed ...
3
votes
1
answer
84
views
Amend with multiple indices per substitution in J
In J, how do you idiomatically amend an array when you have:
substitution0 multipleIndices0
...
substitutionN multipleIndicesN
(not to be confused with:
substitution0 multipartIndex0
...
...
2
votes
2
answers
161
views
How can I take the outer product of string vectors in J?
I'm trying to replicate the outer product notation in APL:
∘.,⍨ 'x1' 'y1' 'z1' 'x2' 'y2' 'z2' 'x3' 'y3' 'z3'
which yields
x1x1 x1y1 x1z1 x1x2 x1y2 x1z2 x1x3 x1y3 x1z3
y1x1 y1y1 y1z1 y1x2 y1y2 y1z2 ...
4
votes
2
answers
150
views
Is there an idiomatic way to print a vector(list) or a character string diagonally in J?
if I have a list a=:i.5, can it be printed like this(diagonally):
0
1
2
3
4
or in the case of a string like 'enigmatic' can a 'x' pattern be generated?
e e
n n
i i
g g
...
3
votes
2
answers
171
views
Index of minimum element using J
In J it is trivial to find the minimum element of an array:
<./ 5 6 4 9
4
But how to find the index of the minimum element using J?
(In case this is an XY problem, I should say that I want the ...
1
vote
3
answers
144
views
J programming how to wait fo X seconds before executing the next verb?
I want to wait for X seconds before executing the next line in a verb.
So far, I have tried this foreign command 6!:3 (2.5) found in time (delay) though it looks like the entire verb execution is ...
2
votes
1
answer
214
views
How to reshape data array from wide to long in J?
I like to replicate the reshape function in J.
For example, Stata can reshape a dataset "from wide to long". Below is their Example 1 from their documentation:
. use http://www.stata-press....
3
votes
4
answers
193
views
Run J script as if it were line-by-line entered into the interpreter
Is there a way to run the script as if it were typed into the interpeter? The benefits are that I don't need echos everywhere, the work done is saved as a file, and I can use vim to do the editing. ...
2
votes
1
answer
91
views
Print values and it's associated index when working with vectors / matrix in J
If I want to check how many values in a vector or matrix are less than a given value
I can use +/ (a < 20). But what if I wanted to know both the specific value and it's index.
Something like (2(...