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 |$-reader| (s c) | |
(declare(ignore c)) | |
(let((op(read s t t t)) | |
(args(read s t t t))) | |
(cons op args))) | |
(set-macro-character #\$ #'|$-reader|) | |
;; cl-user> (append (list 1 2 3) $list(4 5 6)) | |
;; => (1 2 3 4 5 6) |
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
(defpackage :alpaka-debugger(:use :cl)) | |
(in-package :alpaka-debugger) | |
(defun alpaka-debugger(condition function) | |
(declare(ignore function)) | |
(format t | |
" 「\ /`ヽ | |
| \'゙゙゙\"\"\"\"\"\"\"゙゙; / l | |
レ'´ ィ` ̄ ̄ ̄ `ヽ`く l | |
/〃 〃 \\ / |
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-package-name(pathname) | |
(values ; to discard second value. | |
(read-from-string ; to use implementation dependent readtable case. | |
(namestring(make-pathname :type nil :defaults pathname))))) | |
(defun load-as-package(pathname) | |
(let((package-name(make-package-name(enough-namestring pathname (uiop:getcwd))))) | |
(let((*package*(or (find-package package-name) | |
(make-package package-name :use '(:cl))))) | |
(uiop:load* pathname)))) |
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
(defmacro with-random-var((var num)&body body) | |
(let((gvar(gensym "VAR"))) | |
`(LET((,gvar ,num)) | |
(SYMBOL-MACROLET((,var (RANDOM ,gvar))) | |
,@body)))) | |
#+usage | |
(with-random-var(symbol 100) | |
(+ symbol symbol)) | |
; => (+ (random 100)(random 100)) |
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
(declaim(ftype(function((mod #.most-positive-fixnum))(mod #.most-positive-fixnum))fib)) | |
(eval-when(:execute :load-toplevel :compile-toplevel) | |
(defun fib (n) | |
(declare(optimize (speed 3)(safety 0))) | |
(if (< n 2) | |
n | |
(+ (fib (- n 2)) | |
(fib (- n 1))))) |
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
(defmacro my-let(binds &body body) | |
`((lambda,(mapcar #'ensure-car binds) | |
,@body) | |
,@(mapcar #'init-form binds))) | |
(defun ensure-car (arg) | |
(if(listp arg) | |
(car arg) | |
arg)) |
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 packages-made-by(system) | |
(if(find system (asdf:already-loaded-systems):test #'string-equal) | |
(warn "System ~S is already loaded."system) | |
(let((depends-on(asdf:system-depends-on(asdf:find-system system)))) | |
(when depends-on | |
(ql:quickload depends-on :silent t)) ; setup | |
(let((old(list-all-packages))) ; keep olds state | |
(ql:quickload system :silent t) ; install new | |
(set-difference(list-all-packages)old))))) |
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 zundoko() | |
(do((bit(random 2)(random 2)) | |
(memory 0 (shift memory bit))) | |
((= #b11110 memory)(princ :kiyoshi!)) | |
(if(zerop bit) | |
(princ :doko) | |
(princ :zun)))) | |
(defun shift(memory bit) | |
(ldb(byte 5 0)(dpb bit(byte 1 0)(ash memory 1)))) |
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
;;; $ cat /dev/urandom | tr -cd [:alnum:] | fold -w 15 | head -n 5 | |
;;; See CLHS especially alpha-char-p digit-char-p upper-case-p lower-case-p graphic-char-p alphanumericp | |
;;; when you need get radix 16 strings, you can use (lambda(c)(digit-char-p c 16)) | |
(loop :repeat 5 :do (write-line(random-string 15 #'alphanumericp))) | |
(defun random-string(length &optional (pred #'characterp)) | |
(with-open-file(s "/dev/urandom" :element-type '(signed-byte 8)) | |
(loop :with string = (make-string length) | |
:for index :upfrom 0 :below length |
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
;;;; design | |
;;; (enable-literal-hash) => T ; implementation dependent. | |
;;; (gethash :a #H((:a . :b))) => :B ; T | |
;;; (princ #H((:a . :b))) | |
;;; #H((:a . :b)) ; side effect. | |
;;; => #<HASHTABLE 12345678> | |
(in-package :cl-user) | |
(defpackage :literal-hash(:use :cl) |