Wave 4: add sequences/vectors/files chapters, 23 exercises, quiz3, finish ceremony, PCL table

This commit is contained in:
venomade committed 2026-11-22 11:15:35 +00:00
1 parent 77843402fa
commit 4675bd1106
76 files changed
+2505 -14

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
;;; PACKAGES 4: FIND-SYMBOL AND INTERN
;;;
;;; FIND-SYMBOL answers "does this package keep a symbol with this
;;; spelling?" - two values: the symbol, and how it is kept -
;;; :EXTERNAL for exported, :INTERNAL for the rest, NIL and NIL
;;; when there is no such name:
;;;
;;; (find-symbol "CAR" 'common-lisp) => CAR, :EXTERNAL
;;;
;;; With no package argument it searches *PACKAGE*, the current
;;; one - what IN-PACKAGE last set. INTERN finds the symbol or
;;; MAKES it; SYMBOL-NAME is a symbol's spelling as a string.
(defpackage #:attic
(:use #:common-lisp)
(:export #:heirloom))
(in-package #:attic)
(defun heirloom ()
'grandmas-ring)
(in-package #:common-lisp-user)
;; TODO: The symbol ATTIC keeps under the string NAME, with how it
;; is kept as a second value - (NIL NIL) when there is none.
(defun attic-lookup (name)
(find-symbol name))
;; TODO: The ATTIC symbol called NAME - interning a fresh one when
;; the attic does not keep that name yet.
(defun attic-intern (name)
(find-symbol name 'attic))
;;; ------------------------------------------------------------------
;;; Checks. Read them - they tell you what to aim for - but leave
;;; them unchanged.
;;; ------------------------------------------------------------------
(check-equal '(attic:heirloom :external)
(multiple-value-list (attic-lookup "HEIRLOOM")))
(check-equal '(nil nil)
(multiple-value-list (attic-lookup "GHOST")))
(check (attic-intern "SPARE-KEY"))
(check-equal "SPARE-KEY" (symbol-name (attic-intern "SPARE-KEY")))
(check (eq 'attic:heirloom (attic-intern "HEIRLOOM")))
+51
View File
@@ -0,0 +1,51 @@
;;; PACKAGES 5: INTERNALS, NICKNAMES, SHADOWING
;;;
;;; A single colon reaches only EXPORTED symbols. The double colon
;;; shop::secret-sale reaches the internal ones too. :NICKNAMES
;;; gives a package extra names to call it by. And :SHADOW keeps a
;;; name a package USEs from colliding with your own - without it,
;;; defining FILL below would quietly redefine COMMON-LISP's FILL
;;; for everyone.
(defpackage #:shop
(:use #:common-lisp)
(:nicknames #:store)
(:export #:price))
(in-package #:shop)
(defun price ()
5)
(defun secret-sale ()
2)
(in-package #:common-lisp-user)
;; TODO: The secret sale price SHOP keeps for regulars only.
(defun best-deal ()
(shop:price))
;; TODO: The defpackage below is missing its (:shadow #:fill).
;; Add it, or DEFUN FILL under POST-OFFICE redefines COMMON-LISP's
;; FILL for everyone.
(defpackage #:post-office
(:use #:common-lisp))
(in-package #:post-office)
(defun fill (box)
(list 'stuffed box))
(in-package #:common-lisp-user)
;;; ------------------------------------------------------------------
;;; Checks. Read them - they tell you what to aim for - but leave
;;; them unchanged.
;;; ------------------------------------------------------------------
(check-equal 5 (store:price))
(check-equal 2 (best-deal))
(check-equal (list 0 0 0) (fill (list 1 2 3) 0))
(check-equal '(post-office::stuffed crate)
(funcall (find-symbol "FILL" '#:post-office) 'crate))