Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun make-game ()
- (let ((game (make-hash-table :test #'equal)))
- (iter (for p in '(t nil))
- (setf (gethash p game) (make-hash-table :test #'equal))
- (iter (for location in '("deck" "hand"))
- (setf (gethash location (gethash p game)) nil)))
- game))
- (defvar x (make-game))
- (setf (gethash "deck" (gethash t x)) '(0 1 2 3 4 5 6 7 8 9 10))
- (defmacro let-game ((game player) &body body)
- (let ((deck (intern "DECK"))
- (hand (intern "HAND")))
- `(let* ((player (gethash ,player ,game))
- (opponent (gethash (not ,player) ,game)))
- (declare (ignorable player))
- (declare (ignorable opponent))
- (macrolet ((,hand (p) `(gethash "hand" (gethash ,p ,,game)))
- (,deck (p) `(gethash "deck" (gethash ,p ,,game))))
- ,@body))))
- (let-game (x t) (print (deck t)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement