|
|
|
|
@ -38,6 +38,7 @@ |
|
|
|
|
(-map-indexed (lambda (x el) (list el (list x y))) l)) |
|
|
|
|
li))))) |
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
* 2D geometry auxiliary functions |
|
|
|
|
Here a vector is just a list with two components; the "dot" |
|
|
|
|
function is a bit of an overkill tbh |
|
|
|
|
@ -56,4 +57,23 @@ |
|
|
|
|
"Returns the taxicab distance from P to Q" |
|
|
|
|
(+ (abs (- (car p) (car q))) |
|
|
|
|
(abs (- (cadr p) (cadr q))))) |
|
|
|
|
#+end_src |
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
These are two-dimensional equivalent of -map and -map-indexed |
|
|
|
|
#+begin_src emacs-lisp |
|
|
|
|
(defun -2map (fun li) |
|
|
|
|
(--map (-map fun it) li)) |
|
|
|
|
|
|
|
|
|
(defmacro --2map (form list) |
|
|
|
|
`(-2map (lambda (it) ,form) ,list)) |
|
|
|
|
|
|
|
|
|
(defun -2map-indexed (fun li) |
|
|
|
|
(-map-indexed (lambda (j row) |
|
|
|
|
(-map-indexed (lambda (i it) |
|
|
|
|
(funcall fun i j it)) |
|
|
|
|
row)) |
|
|
|
|
li)) |
|
|
|
|
|
|
|
|
|
(defmacro --2map-indexed (form li) |
|
|
|
|
`(-2map-indexed (lambda (it-index-1 it-index-2 it) ,form) ,li)) |
|
|
|
|
#+end_src |
|
|
|
|
|