Wiki: J

Basics

Printing

Hardcoding

0 :0 starts a "heredoc" multi-line string, from the next line until a line containing a single ). But you can actually leave off the ) at the end of file.

echo 0 :0
wow I am
 so good at
   code golf!

Input

Built-ins

Hidden Features

It is easy to miss or forget certain features of some of the primitives:

Other tips

Packers

Simple 2:1 packer

Works with any ASCII-only code, and gives the length of ceil(original/2)+16. Yet to find the 2:1+11 compression which primo and nwellnhof uses apparently.

NB. compressor
6 u:'source padded to even'
NB. decompressor (submission)
".1 ic 3 u:ucp'compressed'

3:1 packer (only works in special cases)

For this to work, the source code must not contain charcode 96 or higher (`{|}~ and lowercase), which means you cannot use echo, stdout (among others), and built-ins { {. {: | |. |: } }. }: ~ ~. ~:. Also it's probably not worth it when you need to print some literal character of charcode 96 or higher. echo can be replaced with 1!:2&2, and ARGV still works though.

NB. compressor
1 u:u:,_3(241,96+])\3 u:'source padded to multiple of 3'
NB. decompressor (submission)
".u:96|241-.~3 u:'compressed'

Near-3:1 packer (more liberal than above)

Encodes chars above 96 as the start byte of a 2-byte UTF-8 sequence. If there are not enough continuation bytes, it is extended with copies of ? converted. Combined with the fact that the bytes c0 and c1 are banned in UTF-8, you cannot use `a? chars in the code. It still compresses better if you try to avoid the bytes above 96 as much as possible.

Compressor in Python (output is the submission)