Lisp is a list processor, but we're working with R, so we have access to more complex data-types. One of which is the vector or c() data-type for simple storage and vector arithmetic. We can create a vector with squared-brackets, e.g. [1 2 3] is translated to c(1, 2, 3). This translation is necessary for when we're using functions that expect vector arguments:

Vectors

[1 2 3 4] ;; creates a vector like c() in R

(mean [1 2 3 4 5])

;; perfect for vector arithmetic
(defparam x [1 2 3 4 5])
(defparam y [1 2 3 4 5])

(+ x y)

Lists

Even though lisp is already a list and indeed represented in R using multi-dimensional lists. We use a special token to denote that data should stored in the list not processed. This special token is { }.

SluRp> (defparam x {1 2 3 4})
[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
[1] 3

[[4]]
[1] 4

;; we can use keywords to specify the index of each element
SluRp> (defparam x {:one 1 :two 2})
$one
[1] 1

$two
[1] 2

Matrices

(defparam x (array [[1 2] [2 4]] :dim [2 2]))
(defparam y (array [[1 3] [3 1]] :dim [2 2]))

(* x y)

(t x) ;; transpose x

(diag x)

(eigen x)


jaypmorgan/slurp documentation built on Dec. 20, 2021, 10 p.m.