Skip to content

Instantly share code, notes, and snippets.

(defun probability-choice (lst)
"Expect LST to be ((prob item) (prob item) ...). It doesn't have to be
sorted but all PROB values must sum to 1. Return a random item based on these
probabilities."
(let ((tol 1d-10)
(prob-sum (reduce #'+ lst :key #'car)))
(assert (<= (- 1d0 (abs prob-sum)) tol)))
(format t "Probabilities are good.~%")
Type BLInst
Field N:UInt = 1024 * 1024 * 5 ' number of Lisp objects (doubles) to store
Field hp:ULong = 0 ' heap pointer
Field sp:ULong = N ' stack pointer
Field cell:Double[N]
Field nil_val:Double
Field quit_val:Double
Field tru_val:Double
Field err_val:Double
(logior
sdl2-ffi:+SDL-INIT-TIMER+
sdl2-ffi:+SDL-INIT-AUDIO+
sdl2-ffi:+SDL-INIT-VIDEO+
sdl2-ffi:+SDL-INIT-JOYSTICK+
sdl2-ffi:+SDL-INIT-HAPTIC+
sdl2-ffi:+SDL-INIT-GAMECONTROLLER+
sdl2-ffi:+SDL-INIT-EVENTS+
sdl2-ffi:+SDL-INIT-SENSOR+)
;; disable floating point traps
(eval-when (:load-toplevel :execute)
(sb-int:set-floating-point-modes :traps nil))
(asdf:load-system :cl-cffi-gtk)
(defpackage :gtk-tutorial
(:use :gtk :gdk :gdk-pixbuf :gobject
:glib :gio :pango :cairo :cffi :common-lisp))
+-----------------------------------------------------------------------------+
|sm1#bibp |
|# MlA#Ls |
|c tep |
|t23smecs |
| s |
| c#mm sm |
|m m |
|CCI H |
| |
+-----------------------------------------------------------------------------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
(defclass bsm-mapid-table ()
((%by-key :reader by-key
:initarg :by-key
:initform nil)
(%by-value :reader by-value
:initarg :by-value
:initform nil)))
(defun bsm-make-bsm-mapid-table (by-key-test by-value-test)
(bsm-mapid-table :by-key (make-hash-table :test by-key-test)
@psilord
psilord / 1d.lisp
Last active September 15, 2024 05:18
(c:define-texture-map g000-1d-phy-gnd-one-non (:1d :unique)
(c:data-elements
(0 (c:image-element :logloc (textures 1d-64x1))))
(c:mipmap-1d
:extent (c:span-1d :origin 0 :extent 64)
(c:mapping-span-1d :to (c:data-span-1d :origin 0 :extent 64)
:from (c:data-span-1d :origin 0 :extent 64 :elidx 0))))
;; -
;; |
;; | The same grounded form as above, but built from programmatic API.
;; The logical form which is written 99% of the time by a human.
(c:define-texture-map g001-1d-log-inf-all-non (:1d :unique)
;; USER MUST PUT THEM IN ORDER.
(c:mipmap (textures 1d-64x1))
(c:mipmap (textures 1d-32x1))
(c:mipmap (textures 1d-16x1))
(c:mipmap (textures 1d-8x1))
(c:mipmap (textures 1d-4x1))
(c:mipmap (textures 1d-2x1))
(c:mipmap (textures 1d-1x1)))
CL-USER> (floor 18014398509481980d0)
18014398509481980
0.0d0
CL-USER> (floor 18014398509481981d0)
18014398509481980
0.0d0
CL-USER> (floor 18014398509481982d0)
18014398509481982
0.0d0
CL-USER> (floor 18014398509481983d0)