JNJ: J iN Janet

JNJ provides bindings to the J language to be used in Janet code.

J is a powerful array programming language in the APL lineage. It has a few features that might make it useful to expose from within a more general-purpose language:

JNJ in Action

Dot Product

(let [left [1 3 -5]
      right [4 -2 -1]]
  (jnj/j "+/ . *" left right))
; => 3

Matrix Transposition

(let [mat (jnj/eval "(^/ }:) >:i." 5)]
  (jnj/j "|:" mat))
; => ((1 2 3 4 5) 
;     (1 4 9 16 25) 
;     (1 8 27 64 125) 
;     (1 16 81 256 625))

Power Set

(jnj/let-j [ps ("#~ 2 #:@i.@^ #")] 
 (ps "ACE"))
; => ("   " "E  " "C  " "CE " "A  " "AE " "AC " "ACE")

Square But Not Cube

(jnj/let-j [checksqr ("(*. -.)/@(= <.)@(2 3 %:/ ])")]
 (checksqr [:raw "I."] (range 0 1090)))
; => (4 9 16 25 36 49 81 100 121 144 169 196 225 ...)

Learn More

Installation instructions available at sourcehut.

Z. D. Smith, 2021.
Built with Bagatto.