j

What do you call this functional language feature?

ok, embarrassing enough, I posted code that I need explained. Specifically, it first chains absolute value and subtraction together, then tacks on a sort, all the while not having to mention parameters and arguments at all, because of the presense of "adverbs" that can join these functions "verbs" What (non-APL-type) languages support t...

Would anybody recommend learning J/K/APL?

I came across J/K/APL a few months ago while working my way through some project euler problems, and was intrigued, to say the least. For every elegant-looking 20 line python solution I produced, there'd be a gobsmacking 20 character J solution that ran in a tenth of the time. I've been keen to learn some basic J, and have made a few att...

J @ not working as expected

I'm just starting to try to pick up the J language, and am confused by the following: 1 2 +/@{ i.4 1 2 +/ 1 2 { i.4 3 when in the documentation for @ it says: "x u@v y ↔ u x v y" I assume I'm just mistaking one part of speech for another, but can't figure it out also, how do I tell what type of speech a name is? ...

Where can one find a list of all the operators in J

I am trying to learn J and one huge problem I'm running into is I don't know what all the predefined operators are or where to find them. It took me way too long to figure out the | is both the remainder function(when it dyadic) but when its used monadic it gets absolute value or magnitude. Does any one know where a list of all the ope...

Why is this J function not running?

I am attempting to learn J and the book I am using says this is the proper way to define a monadic function function =: 3:0 function statements so I followed this format and wrote the folding code. Can you tell me why this is throwing a syntax error when I try to call it with input but if I just call p it returns 3 h=:>:@i.@<....

Learning J/K/APL.

I know all 3 are related, and I've seen quite a few answers for problems in Project Euler written in J, and a few written K. What I'm wondering is, which would you suggest learning, and where would you suggest going about getting the materials to learn it? ...

How to refactor this in J?

My newbie solution to Project Euler #1 +/((0=3|1+i.1000-1) +. (0=5|1+i.1000-1)) * (1+i.1000-1) I know that this can be refactored, and transformed into a function, i don't know how to do it, and I would have to read all the labs to learn it. ...

How to refactor this in J?

Here is a different approach for the Project Euler #1 solution: +/~.(3*i.>.1000%3),5*i.>.1000%5 How to refactor it? ...

How to rewrite the halve function in J?

Hi, in the J programming language, -: i. 5 the above function computes the halves of all integers in [0,4]. Now let's say I'd like to re-write the -: function, just for the fun of it. My best guess so far was ]&%.2 but that doesn't seem to cut it. How do you do it? ...

Best strategies for reading J code

I've been using J for a few months now, and I find that reading unfamiliar code (e.g. that I didn't write myself) is one of the most challenging aspects of the language, particularly when it's in tacit. After a while, I came up with this strategy: 1) Copy the code segment into a word document 2) Take each operator from (1) and place it...

J: Self-reference in bubble sort tacit implementation

Hello people! Since I'm beginner in J I've decided to solve a simple task using this language, in particular implementing the bubblesort algorithm. I know it's not idiomatically to solve such kind of problem in functional languages, because it's naturally solved using array element transposition in imperative languages like C, rather th...

How to install new modes in emacs 23 on OS X?

I just downloaded the Haskell and J modes off of SourceForge, and I'm having trouble figuring out how to make them interface with emacs 23. Google searches yield detailed instructions for emacs 22, but it looks like changes have been made that make it hard to figure out where I'm supposed to stick the source files. The internal documenta...

How to filter a list in J?

I'm currently learning the fascinating J programming language, but one thing I have not been able to figure out is how to filter a list. Suppose I have the arbitrary list 3 2 2 7 7 2 9 and I want to remove the 2s but leave everything else unchanged, i.e., my result would be 3 7 7 9. How on earth do I do this? ...

How do I define a monadic function to work on a list in J?

Let's say I have the following J expression: # 3 ((|=0:)#]) 1+i.1000 This counts the number of numbers between 1 and 1000 that are evenly divisible by 3. (Now, before anyone points out that there's an easier way to do this, this question is about the syntax of J, and not mathematics.) Let's say I define a monadic function for this, as...

Setting the rank of a user-defined verb in J

Here's a function to calculate the digital sum of a number in J: digitalSum =: +/@:("."0)@": If I use b. to query the rank of this verb, I get _ 1 _, i.e., infinite. (We can ignore the dyadic case since digitalSum is not dyadic.) I would like the monadic rank of this verb to be 0, as reported by b.. The only way I know of to do this i...

Abstracting boxed array structures in J

I've been working on a J function for a while, that's supposed to scan a list and put consecutive copies of an element into separate, concatenated boxes. My efforts have taken me as far as the function (<;. 2) ((2&(~:/\)),1:) which tests successive list entries for inequality, returns a list of boolean values, and cuts the list into ...

How can I define a verb in J that applies a different verb alternately to each atom in a list?

Imagine I've defined the following name in J: m =: >: i. 2 4 5 This looks like the following: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 I want to create a monadic verb of rank 1 that applies to each list in this list of lists. It will double (+:) or add 1 ...

How can I generate the Rowland prime sequence idiomatically in J?

If you're not familiar with the Rowland prime sequence, you can find out about it here. I've created an ugly, procedural monadic verb in J to generate the first n terms in this sequence, as follows: rowland =: monad define result =. 0 $ 0 t =. 1 $ 7 while. (# result) < y do. a =. {: t n =. 1 + # t t =...

Why do I not get the correct answer for Euler 56 in J?

I've solved 84 of the Project Euler problems, mostly in Haskell. I am now going back and trying to solve in J some of those I already solved in Haskell, as an exercise in learning J. Currently, I am trying to solve Problem 56. Let me stress that I already know what the right answer is, since I've already solved it in Haskell. It's a ver...

How do I do file io in J?

I want to be able to read and write files, etc. How can I do this? ...