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
;; In this population, a should be selected with frequency of 10%, while | |
;; b and c are each chosen with frequency 45%. | |
(defvar weights '(10 45 45)) | |
(defvar population '(a b c)) | |
(defun cumulative-weights (weights) | |
"Return the total of `weights' and the cumulative distribution | |
table." | |
(loop for w in weights | |
sum w into total |
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 random-0-to-1 (&optional range) | |
"Generate a random value in [0.0, 1.0)." | |
(let ((range (or range most-positive-fixnum))) | |
(/ (random range) (float range)))) |
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
(ql:quickload :str) | |
(ql:quickload :alexandria) | |
(import 'alexandria:compose) | |
(ql:quickload :arrows) | |
(use-package :arrows) | |
(defun split-names (s) | |
(mapcar (compose #'str:downcase #'str:trim) (str:split #\, s))) | |
(let (names) |
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
(ql:quickload :jsown) | |
(ql:quickload :dexador) | |
(ql:quickload :quri) | |
(if (evenp | |
(sxhash | |
(car (jsown:val | |
(jsown:parse | |
(dex:get | |
(quri:make-uri |
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
set pending_release {} | |
set pressed false | |
proc press_action {} { puts "pressed" } | |
proc release_action {} { puts "released" } | |
proc is_pressed {} { | |
global pressed | |
return $pressed | |
} |
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
(ql:quickload :dexador) | |
(ql:quickload :jsown) | |
(ql:quickload :arrows) | |
(use-package :arrows) | |
(defparameter url "https://api.weather.gov/gridpoints/FWD/95,141/forecast") | |
(defun json-val-in (o &rest keys) | |
(reduce (lambda (o k) (jsown:val o k)) keys :initial-value o)) |
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
(flet ((cycle (list) (setf (cdr (last list)) list))) | |
(let ((fcyc (cycle (list "" "" "Fizz"))) | |
(bcyc (cycle (list "" "" "" "" "Buzz")))) | |
(mapcar (lambda (f b n &aux (fb (concatenate 'string f b))) | |
(if (= 0 (length fb)) n fb)) | |
fcyc bcyc (loop for n from 1 to 100 collect n)))) |
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-chain-table (&rest tables) | |
(lambda (key) | |
(labels ((aux (tables) | |
(if (null tables) | |
(values nil nil) | |
(multiple-value-bind (value found) (gethash key (car tables)) | |
(if found | |
(values value t) | |
(aux (cdr tables))))))) | |
(aux tables)))) |
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 while (fn seq) | |
"Evaluates to the sequence that results from calling fn on each element of seq, until the result is NIL" | |
(labels ((aux (seq acc) | |
(if (null seq) acc | |
(let ((val (funcall fn (first seq)))) | |
(if val | |
(aux (rest seq) (cons val acc)) | |
acc))))) | |
(aux seq nil))) |
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
(require 'thingatpt) | |
(defun beginning-of-integer-at-point () | |
(let ((inhibit-changing-match-data t)) | |
(skip-chars-backward "[[:digit:]]") | |
(unless (looking-at "[[:digit:]]") | |
(error "No integer here")) | |
(when (looking-back "[+-]") | |
(backward-char 1)))) |
NewerOlder