From f4b43031adf1094d007ce9e44b191255909d178c Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Fri, 14 Feb 2025 16:59:46 +0000 Subject: Add a package for modelling cards Time to do the fun non-yakshaving part. I'll start out by writing some custom types for the objects of concern: ranks, suits, cards and sets of cards. --- model.lisp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 model.lisp (limited to 'model.lisp') diff --git a/model.lisp b/model.lisp new file mode 100644 index 0000000..7ce8b99 --- /dev/null +++ b/model.lisp @@ -0,0 +1,37 @@ +;;; model.lisp - 2025-02-14 + +;; Copyright (C) 2025 Aryadev Chavali + +;; This program is distributed in the hope that it will be useful, but WITHOUT +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +;; FOR A PARTICULAR PURPOSE. See the GNU General Public License Version 2 for +;; details. + +;; You may distribute and modify this code under the terms of the GNU General +;; Public License Version 2, which you should have received a copy of along with +;; this program. If not, please go to . + +;;; Commentary: + +;; Model of cards and sets of cards in Lisp. + +;;; Code: + +(in-package :cantedraw.model) + +(deftype rank () + `(or (member :Jack :Queen :King :Ace) + (integer 2 10))) + +(deftype suit () + `(member :Diamonds :Clubs :Hearts :Spades :Joker)) + +(deftype card () `(cons rank suit)) + +(deftype int-card () `(integer 0 51)) + +(fn cardsetp (lst) (-> (list) boolean) + (every #'(lambda (x) (typep x 'card)) lst)) + +(deftype cardset () `(and list (satisfies cardsetp))) + -- cgit v1.2.3-13-gbd6f