Skip to main content

Interpreter for the J programming language.

Project description

Jinx

ci

An experimental interpreter for the J programming language, built on top of NumPy.

Implements many of J's primitives and tacit programming capabilities, and can be extended to support execution via other frameworks too.

Executing J

Start the interactive shell:

jinx

The shell prompt is four spaces, so commands appear indented. Internally, all multidimensional arrays are NumPy arrays. Verbs, conjunctions and adverbs are a mixture of Python and NumPy methods.

Here are some examples what Jinx can do so far:

  • Solve the "trapping rainwater" problem (solution taken from here):
    +/@((>./\ <. >./\.)-]) 0 1 0 2 1 0 1 3 2 1 2 1
6
  • Compute the correlation between two arrays of numbers (taken from here). This is a complex combination of different verbs, adverbs, conjunctions and trains:
    2 1 1 7 9 (+/@:* % *&(+/)&.:*:)&(- +/%#) 6 3 1 5 7
0.721332
  • Create identity matrices in inventive ways (see this essay):
    |.@~:\ @ ($&0) 3
1 0 0
0 1 0
0 0 1

    (i.@,~ = >: * i.) 3
1 0 0
0 1 0
0 0 1

    ((={:)\ @ i.) 3
1 0 0
0 1 0
0 0 1
  • Solve the Josephus problem (see this essay). Calculate the survivor's number for a circle of people of size N. Note the use of verb obverse and the rank conjunction:
    (1&|.&.#:)"0 >: i. 5 10    NB. N ranges from 1 to 50 here (arranged as a table)
 1  1  3  1  3  5  7  1  3  5
 7  9 11 13 15  1  3  5  7  9
11 13 15 17 19 21 23 25 27 29
31  1  3  5  7  9 11 13 15 17
19 21 23 25 27 29 31 33 35 37
  • Build nested boxes containing heterogeneous data types and print the contents:
    (<<'abc'),(<(<'de',.'fg'),(<<i. 5 2)),(<(<"0 ] % i. 2 2 3))
┌─────┬──────────┬────────────────────────────┐
│┌───┐│┌──┬─────┐│┌────────┬────────┬────────┐│
││abc│││df│┌───┐│││_       1       0.5     ││
│└───┘││eg││0 1│││├────────┼────────┼────────┤│
     ││  ││2 3││││0.3333330.25    0.2     ││
     ││  ││4 5│││└────────┴────────┴────────┘│
     ││  ││6 7│││                            
     ││  ││8 9│││┌────────┬────────┬────────┐│
     ││  │└───┘│││0.1666670.1428570.125   ││
     │└──┴─────┘│├────────┼────────┼────────┤│
               ││0.1111110.1     0.090909││
               │└────────┴────────┴────────┘│
└─────┴──────────┴────────────────────────────┘

Easily Customisable

Everything is in Python. Adding new primitives is easy.

Update the primitives.py file with your new part of speech (e.g. a new verb such as +::). Write your implementation of this new part of speech in the relevant executor module (e.g. verbs.py) and then update the name-to-method mapping at the foot of that module. That's all that's needed.

Alternative Executors

Execution of sentences is backed by NumPy by default.

However Jinx is designed so that it's possible to implement the primitives using alternative frameworks too. Python many Machine Learning and Scientific Programming libraries that could be used to execution J code.

To prove this concept, there's highly experimental and incomplete support for JAX:

jinx --executor jax

Primitive verbs are JIT compiled and execute on JAX arrays:

    mean =: +/ % #
    mean 33 55 77 100 101
73.2

Warning

This project is experimental. There will be bugs, missing features and performance quirks.

Many key parts of J are not currently implemented (but might be in future). These include:

  • Differences in how names are interpreted and resolved at execution time.
  • Locales.
  • Definitions and direct definitions (using {{ ... }}).
  • Array types other than floats, integers and and strings.
  • Executing J scripts.
  • Control words.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jjinx-0.0.1.tar.gz (41.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jjinx-0.0.1-py3-none-any.whl (44.1 kB view details)

Uploaded Python 3

File details

Details for the file jjinx-0.0.1.tar.gz.

File metadata

  • Download URL: jjinx-0.0.1.tar.gz
  • Upload date:
  • Size: 41.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.13

File hashes

Hashes for jjinx-0.0.1.tar.gz
Algorithm Hash digest
SHA256 fad5e41aecdfc18fd215e80d42542d598d56ba55ed8151d61ab308419519932e
MD5 6ebd610f1390420e8cf3273d6eef01fc
BLAKE2b-256 cf07261fe7bb7f3e7c632851291136ab53dd945c48355d06246cbc59595fb3e1

See more details on using hashes here.

File details

Details for the file jjinx-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: jjinx-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 44.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.13

File hashes

Hashes for jjinx-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1bfd32039d55dbab6d0e73a55d4bdacb560a735ed3af5990b0eb1df032598c3c
MD5 09185ecdffea475e68172420d63c45ed
BLAKE2b-256 b625384b0deac93cc522e18a61d5b2c20cf03baad20840d2288988aefe502d2c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page