This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun make (pts &key closed) | |
(let ((n (length pts))) | |
(if (< n 4) (error "must have at least 4 pts.")) | |
(let ((apts (make-dfloat-array n))) | |
(loop | |
for p in pts | |
for i from 0 | |
do | |
(destructuring-bind (x y) | |
p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun psymb (package &rest args) | |
(values (intern (apply #'mkstr args) package))) | |
(defmacro with-struct ((name . fields) struct &body body) | |
(let ((gs (gensym))) | |
`(let ((,gs ,struct)) | |
(let ,(mapcar #'(lambda (f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; https://stackoverflow.com/a/25264944/69545 | |
; ================================================================ | |
; This is the usual evolution | |
; 1) simple recursive version | |
; 2) more efficient tail-recursive version | |
; 3) efficient loop | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;see https://stackoverflow.com/questions/46496083/lazily-generating-prime-in-common-lisp/46497515#46497515 | |
(defun divisor-in-list (n list) | |
(some (lambda (i) | |
(zerop (rem n i))) | |
list)) | |
(defun primes () | |
(let ((p (list 2)) | |
(n 2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; the hashtable is found on the binding stack | |
(defmacro memo (v e &aux (§v (gensym "V"))) | |
`(locally (declare (special *mem*)) | |
(let ((*mem* (or (and (boundp '*mem*) *mem*) | |
(make-hash-table))) | |
(,§v ,v)) | |
(declare (special *mem*)) | |
(or (gethash ,§v *mem*) | |
(setf (gethash ,§v *mem*) ,e))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; https://github.com/inconvergent/snek/blob/master/utils/count.lisp | |
(defun make-counter (&optional ll) | |
(let ((c (make-hash-table :test #'equal))) | |
(loop for a in ll do (counter-add c a)) | |
c)) | |
(defun counter-add (c a) | |
(incf (gethash a c 0))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; https://github.com/inconvergent/snek/blob/master/utils/spline-script.lisp | |
(defun test-centroids (counts nc ncn) | |
(loop for i from 0 below nc | |
always (multiple-value-bind (val exists) | |
(gethash i counts) | |
(and exists (>= val ncn))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<GLS is Guy Steele, RMS is Richard Stallman, DLW is Dan Weinreb, Moon is David Moon, Ed is Ed | |
Schwalenberg, CBF is Charles Frankston, EAK is Earl Killian, ECC is Gene Cicarelli, | |
RMF is Bob Frankston, and JLK is John Kulp.> | |
--- | |
I think all of us have been relying on our memories, which can | |
fail in various ways. Last time around I checked my file folder | |
of notes about Emacs, which has some useful information, but | |
not a lot about who did what. Now I have some more information |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun divisors (n &aux (divisors (list 1))) | |
(etypecase n | |
((integer * 1) nil) | |
((integer 2 *) | |
(loop with q and r | |
for i from 2 to (isqrt n) | |
do (setf (values q r) (truncate n i)) | |
when (zerop r) do (push q divisors) and do (push i divisors)) | |
(if (and (second divisors) | |
(= (first divisors) (second divisors))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; John McCarthy. Puzzle Solving Program in LISP. Memo 20, Artificial Intelligence Project | |
; http://www.bitsavers.org/pdf/mit/ai/aim/AIM-020.pdf | |
; 1960 | |
; Common Lisp translation: Rainer Joswig, 2016, [email protected] | |
; basically the code is unchanged, but using s-expression syntax in Common Lisp | |
(defparameter pzl | |
'((a1 (a2 a5) 7.5) | |
(a2 (a1 a5 a9 a3) 3.5) |