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 converter (d20 d12 d10 d8 d4) | |
(let ((prod (+ (* 3840 (1- d20)) | |
(* 320 (1- d12)) | |
(* 32 (1- d10)) | |
(* 4 (1- d8)) | |
(1- d4)))) | |
(if (> prod 65535) | |
nil | |
(format nil "~4,'0X" prod)))) |
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
> (apply #'append '((1 2) (3 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
(defun flatten (x) | |
(labels ((rec (x acc) | |
(cond ((null x) acc) | |
((atom x) (cons x acc)) | |
((null (car x)) (cons nil (rec (cdr x) acc))) | |
(t (rec (car x) (rec (cdr x) acc)))))) | |
(rec x nil))) |
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 macro-caller (x y) | |
(eval `(macro-in-question ,x ,y))) |
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
CL-USER> (repl) | |
> ((label my-append (lambda (x y) (cond (eq '() x) y | |
't (cons (car x) (my-append (cdr x) y))))) | |
(cons '1 (cons '2 '())) | |
(cons '3 (cons '4 '()))) | |
(1 . (2 . (3 . (4 . NIL)))) |
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
;Lisp in Lisp in Golomb forests. Includes use of linked lists. | |
;Based on Paul Graham's version of McCarthy's paper and code. | |
;Uses only eq, cond, atom, quote, cons, car, and cdr. | |
(defun null. (x) | |
(eq x '())) | |
(defun and. (x y) | |
(cond (x | |
(cond (y 't) |
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 golomb-forest (&rest args) | |
(if (and (oddp (length args)) (null (car (last args)))) | |
(sentinel-change. (golomb-forest-1 0 args)) | |
(golomb-forest-1 0 args))) | |
(defun golomb-forest-1 (size lst) | |
(cond ((null lst) nil) | |
((= size 0) (cons (car lst) (golomb-forest-1 1 (cdr lst)))) | |
(t (let ((siz (expt 2 size))) | |
(if (> siz (length lst)) |
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
CL-USER> (repl '((a . 1) (b . 2) (c . 3))) | |
> (cons a (cons b c)) | |
(1 . (2 . 3)) |
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
> (cdr '(1 2 3)) | |
((2 . 3) . NIL) |
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
((label conser (lambda (x) (cons x x))) '1) |
NewerOlder