


When learning a new language, building real-world applications—no matter how simple—is a powerful way to understand its core features. In this post, we will implement a console-based doctor appointment scheduling system in Common Lisp. It will allow users to book, cancel, and view appointments using a clean menu-driven interface.
View Available Time Slots
Book an Appointment
Cancel an Appointment
View All Booked Appointments
Exit the System
📦 The Core Components
Let’s walk through how each part of the code contributes to the functionality:
(defparameter *time-slots*
'("9:00 AM" "10:00 AM" "11:00 AM" "12:00 PM"
"2:00 PM" "3:00 PM" "4:00 PM" "5:00 PM"))
These are our fixed time slots. The user can choose from these to book an appointment.
(defparameter *appointments* (make-hash-table :test 'equal))
A hash table is used to store appointments, mapping each slot to a user's name.
(defun view-available-slots ()
(format t "~%Available Slots:~%")
(dolist (slot *time-slots*)
(unless (gethash slot *appointments*)
(format t "~A~%" slot))))
This function filters out already booked slots and shows only the available ones.
(defun book-appointment ()
;; code continues...
)
The user enters their name and picks a slot. The function validates the input and checks availability before booking.
(defun cancel-appointment ()
;; code continues...
)
Users can cancel their appointments by providing their name. It searches the hash table and removes matching entries.
(defun view-appointments ()
;; code continues...
)
Prints a list of all booked slots along with the names of users who booked them.
(defun main-menu ()
;; loop with case options
)
A looping text interface that allows the user to interact with the system repeatedly until they choose to exit.