There are many occasions where a function can be optimized under certain assumptions about the system. But since most aspects of Common Lisp can be redefined almost arbitrarily, there are few assumptions that a compiler can generally make. (A notable exception is the behavior of definitions in the CL package, and of built-in objects.)
This file contains hidden or 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-package #:cl-user) | |
(defun jacobi-a (dst src &optional (w 0.25d0)) | |
(declare (type (simple-array double-float 2) dst src) | |
(type double-float w)) | |
(loop for i from 1 below (1- (array-dimension dst 0)) do | |
(loop for j from 1 below (1- (array-dimension dst 1)) do | |
(setf (aref dst i j) | |
(* w | |
(+ |
This file contains hidden or 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 odd-bits (x) | |
(declare (type (unsigned-byte 32) x)) | |
(setf x (logand (ash x -1) #x55555555)) | |
(setf x (logand (logior (ash x -1) x) #x33333333)) | |
(setf x (logand (logior (ash x -2) x) #x0F0F0F0F)) | |
(setf x (logand (logior (ash x -4) x) #x00FF00FF)) | |
(setf x (logand (logior (ash x -8) x) #x0000FFFF)) | |
x) |
This file contains hidden or 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 alist-from-plist (plist) | |
(trivia:match plist | |
((list) '()) | |
((list* (and key (type symbol)) value rest) | |
(list* (cons key value) (alist-from-plist rest))) | |
(_ (error "Not a plist:~%~S~%" plist)))) |
This file contains hidden or 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
;;;; Note: You should also put something like (ql:quickload :clouseau) in your initialization file. | |
(defun clouseau-inspect (string) | |
(interactive | |
(list (slime-read-from-minibuffer | |
"Inspect value (evaluated): " | |
(slime-sexp-at-point)))) | |
(let ((inspector 'cl-user::*clouseau-inspector*)) | |
(slime-eval-async | |
`(cl:progn |
This file contains hidden or 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-function-cell (value) | |
(check-type value function) | |
(values | |
(lambda () value) | |
(lambda (new-value) | |
(check-type new-value function) | |
(setf value new-value)))) | |
;; In order to make typed cells as fast as cons cells, | |
;; the compiler has to be able to inline the first value returned by |
This file contains hidden or 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 quickload-all () | |
(loop for system in (ql:provided-systems t) do | |
(ignore-errors | |
(trivial-timeout:with-timeout (20) | |
(ql:quickload (ql-dist:short-description system)))))) |
This file contains hidden or 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
(lambda | |
(#:x-1 &key ((:y #:y-2) nil #:suppliedp-3) ((:z #:z-4) nil #:suppliedp-5)) | |
(declare (ignorable #:x-1 #:y-2 #:suppliedp-3 #:z-4 #:suppliedp-5)) | |
(let ((sealable-metaobjects::.gf. #'keyword-function)) | |
(declare (ignorable sealable-metaobjects::.gf.)) | |
(declare (sb-ext:disable-package-locks call-method)) | |
(declare (sb-ext:disable-package-locks make-method)) | |
(declare (sb-ext:disable-package-locks sb-pcl::check-applicable-keywords)) |
This file contains hidden or 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-package :cl-user) | |
(defmacro debug-defun (name lambda-list &body body) | |
(multiple-value-bind (forms decls doc) | |
(alexandria:parse-body body :documentation t) | |
`(progn | |
(declaim (notinline ,name)) | |
(defun ,name (.debug-flag. ,@lambda-list) | |
,@(when doc (list doc)) | |
,@decls |
This file contains hidden or 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-package #:cl-user) | |
(defpackage #:list-iterators | |
(:use #:cl)) | |
(in-package #:list-iterators) | |
(declaim (inline make-read-iterator)) | |
(defun make-read-iterator (list terminate) | |
(lambda () |
NewerOlder