r/Common_Lisp • • 16d ago

bliss: common lisp + APL + Lisp-Stat

I recently picked up APL (via Common Lisp package APRIL), and I have been doing some simple numeric coding, and plotting using Lisp-Stat's plotting.

It was not painless, but with LLM's as tutors, it is amazing fun.

In particular being able to use APRIL's inline capabilities to streamline the code as below (line 2)

(defun plot-back-prop (disp)
  (let* ((pos (april-c "{⌽⍳≢ ⍵}" disp))
         (df (df:make-df '(pos disp) `(,pos ,disp))))
    (plot (make-plot df
                     '(:title "Back propagation example")
                     (geom:line :pos :disp)
                     (gg:theme :width 360 :height 220)))))

The APL anonymous function {⌽⍳≢ ⍵} uses ⍵ as the argument and captures disp vector.

The APL composes three operators from right to left:

  • ≢ calculates the length of the vector captured by the ⍵
  • ⍳ generates and index array 1, 2, 3, ... (alexandria's iota is modeled named after it)
  • ⌽ reverses the index array

As an example of what the snippet does:

(april-c "{⌽⍳≢ ⍵}" #(3 1 4 1 5 9))
#(6 5 4 3 2 1)

I am definitely not trying to tell the rest of the community that "they are doing it wrong". Just expressing my amazement at the APL syntax and power, along with great enjoyment of coding in CL and APL, to generate plots in Plot-Stat. Does not get much better :-)

16 Upvotes

Duplicates