# Programming in J

I’ll discuss my progress with J. I intend to update this page if I learn more. This page was last updated on November 26th, 2018.

If you want to learn J, you can use the tutorial and vocabulary overview on the official website, or just install and try things out in the J console.

## Introduction

Functions are referred to as “verbs” and they can be modified with “adverbs”. Verbs that take one argument are called monads and those that take two arguments dyads. One symbol can have several meanings depending on the context, for example monadic `#`

counts a list, dyadic `#`

creates copies of something. Parentheses are placed on the right, so `2*3 + 4`

means `2*(3 + 4)`

which gives 14.

## A list of Mersenne primes

I’ll explain the program `(#~1&p:)<:2^p:i.10`

which lists the first few Mersenne primes (prime numbers of the form 2^{p} − 1, where p is prime).

`i.10`

Gives the list `0 1 2 3 4 5 6 7 8 9`

.

`p:6`

Gives the 7th prime, 17.

`2^3`

Gives 2^{3}=8.

`<:5`

Gives 5−1=4.

`1 4 0 7 0 0 3 # 6 7 8 9 10 11 12`

Gives a list of copies `6 7 7 7 7 9 9 9 9 9 9 9 12 12 12`

. This also allows you to create a sublist by only using ones and zeros in the left argument.

`3 4 5 #~ 1 0 1`

Gives the sublist `3 5`

. (The adverb `~`

switches the arguments.)

`1 p:8`

Gives 1 or 0 depending on whether 8 is a prime number. The dyad `p:`

is used for other number-theoretic functions, such as `5 p: 15`

which gives the Euler totient function φ(15)=8.

`1&p:`

Turns the dyad `p:`

into a monad by fixing the left argument `1`

.

`(f g)y`

When f is a dyad and g is a monad, it means `y f (g y)`

.

`(#~1&p:)<:2^p:i.10`

`3 7 31 127 8191 131071 524287`