Hacker News new | ask | show | jobs
by ginsider_oaks 895 days ago
list languages and array languages are quite different. in LISP, the lists are heterogeneous i.e. each element can contain different types, which is also how you can e.g. make a tree out of lists in LISP. typically in array languages all elements are the same, and you use operations that apply to the whole array e.g. one operation for summing the array rather than a loop.
1 comments

There are attempts to combine those...

a cool example is April (Array Programming Re-Imagined in Lisp), which runs on top of Common Lisp...

https://github.com/phantomics/april

One can see that the Lisp macro APRIL-F compiles APL-like code to Lisp.

  APRIL> (macroexpand '(april-f "3r4J9r5×⍳4"))
  (LET ((OUTPUT-STREAM *STANDARD-OUTPUT*))
    (DECLARE (IGNORABLE OUTPUT-STREAM))
    (SYMBOL-MACROLET ((INDEX-ORIGIN APRIL-WORKSPACE-COMMON::*INDEX-ORIGIN*)
                      (PRINT-PRECISION APRIL-WORKSPACE-COMMON::*PRINT-PRECISION*)
                      (COMPARISON-TOLERANCE
                       APRIL-WORKSPACE-COMMON::*COMPARISON-TOLERANCE*)
                      (DIVISION-METHOD APRIL-WORKSPACE-COMMON::*DIVISION-METHOD*)
                      (RNGS APRIL-WORKSPACE-COMMON::*RNGS*))
      (A-OUT (A-CALL (APL-FN-S ×) (A-CALL (APL-FN ⍳ INDEX-ORIGIN) 4) #C(3/4 9/5))
             :PRINT-PRECISION PRINT-PRECISION :PRINT-TO OUTPUT-STREAM)))
  T
we can run that:

  APRIL> (april-f "3r4J9r5×⍳4")
  3r4J9r5 3r2J18r5 9r4J27r5 3J36r5
  #(#C(3/4 9/5) #C(3/2 18/5) #C(9/4 27/5) #C(3 36/5))
It has created a Lisp vector of complex numbers.

  APRIL> (describe *)
  #(#C(3/4 9/5) #C(3/2 18/5) #C(9/4 27/5) #C(3 36/5))
    [simple-vector]

  Element-type: T
  Length: 4
  ; No value