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
;;; Compare descriptions of two objects and report the number of common features. Descriptions are lists of features | |
;;; separated by the symbol -VS- (e.g. (large red shiny cube -vs- small shiny red four-sided pyramid)). | |
(defun right-side (descriptions) | |
"The features of the object to the right of the separator." | |
(cdr (member '-vs- descriptions))) | |
(defun left-side (descriptions) | |
"The features of the object to the left of the separator." | |
(right-side (reverse descriptions))) |
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 throw-die () | |
"Simulate the throw of a regular die; returns a number between 1 and 6, inclusive." | |
(1+ (random 6))) | |
(defun throw-dice () | |
"Simulate the throwing of two dice; returns a list." | |
(list (throw-die) (throw-die))) | |
(defun snake-eyes-p (throw) | |
"Is THROW snake-eyes (two ones)?" |
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
(defmodule lfe-tut-20 | |
(export (start 0) | |
(ping 1) | |
(pong 0))) | |
(defun ping | |
([0] | |
(! 'pong 'finished) | |
(lfe_io:format "ping finished~n" ())) | |
([n] |
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
(defmodule lfe-tut-19 | |
(export (start 0) | |
(ping 2) | |
(pong 0))) | |
(defun ping | |
([0 pong-pid] | |
(! pong-pid 'finished) | |
(lfe_io:format "ping finished~n" ())) | |
([n pong-pid] |
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
(defmodule sqrt | |
(export (sqrt 1))) | |
(defun sqrt [x] | |
(sqrt (* 0.5 x) | |
x)) | |
(defun sqrt [guess x] | |
(if (good-enough? guess x) | |
guess |
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
(defmodule lfe-tut-18 | |
(export (start 0) | |
(say-something 2))) | |
(defun say-something | |
([what 0] | |
'done) | |
([what times] | |
(lfe_io:format "~p~n" (list what)) | |
(say-something what (- times 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
(defconstant +fail+ nil | |
"Indicates PAT-MATCH failure.") | |
(defconstant +no-bindings+ '((t . t)) | |
"Indicates PAT-MATCH success, but with no variables.") | |
;;; Utilities | |
(defun starts-with (lst x) | |
"Is X the first element of 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
;;;; | |
(defmacro lazy (&body body) | |
"Lazily evaluate BODY." | |
(let ((forced (gensym)) | |
(value (gensym))) | |
`(let ((,forced nil) | |
(,value nil)) | |
(lambda () | |
(unless ,forced |
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 pairs (lst) | |
(loop for i on lst by #'cddr | |
collect (cons (car i) | |
(cadr i)))) | |
(defun print-tag (name attributes closing-p) | |
"" | |
(princ #\<) | |
(when closing-p | |
(princ #\/)) |
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
(defparameter *num-players* 2) | |
(defparameter *max-dice* 3) | |
(defparameter *board-size* 3) | |
(defparameter *board-hexnum* | |
(* *board-size* *board-size*)) | |
(defun board-array (lst) | |
"To allow faster access, create an array containing LST's contents." | |
(make-array *board-hexnum* :initial-contents lst)) |