(defmethod greet ((p person))
(format t "Hello, a!%" (person-name p)))
(defmethod greet :around ((p person))
(format t "[Start]%")
(call-next-method)
(format t "[End]%"))
;; In my-project/main.lisp:
(defpackage #:my-project/main
(:use #:cl)
(:import-from #:my-project/utils #:helper))
(sb-ext:save-lisp-and-die "my-app"
:toplevel #'main
:executable t
:compression t)
(let ((thread (sb-thread:make-thread
(lambda ()
(setf result (heavy-computation)))
:name "worker")))
(sb-thread:join-thread thread))
;; Mutex
(defvar lock (sb-thread:make-mutex))
(sb-thread:with-mutex (lock)
(critical-section))
(strlen "hello") ; => 5
;; Execute external programs
(sb-ext:run-program "/bin/ls" '("-l"))
;; Trigger garbage collection
(sb-ext:gc)
;; POSIX interface: sb-posix
;; Network sockets: sb-bsd-sockets
(declare safe-div (Integer -> Integer -> (Maybe Integer)))
(define (safe-div x y)
(if (== y 0)
None
(Some (/ x y)))))
(define-instance (Printable Integer)
(define (print-it x)
(into x))))
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: common-lisp-ecosystem3description: This skill should be used when the user asks to "write common lisp", "CLOS", "ASDF", "defpackage", "defsystem", or works with Common Lisp, SBCL, or Coalton. Provides comprehensive Common Lisp ecosystem patterns and best practices. Use when this capability is needed.4---56<purpose>7Provide comprehensive patterns for Common Lisp, CLOS, ASDF system definition, SBCL-specific features, and Coalton integration.8</purpose>910<common_lisp_fundamentals>11<concept name="s_expressions">12<description>Code and data share the same syntax (homoiconicity). Enables powerful macro systems for code transformation.</description>13</concept>1415<concept name="symbols">16<description>First-class named objects used for identifiers. Interned in packages, can have value, function, and property list.</description>17</concept>1819<concept name="multiple_values">20<description>Functions can return multiple values using values, multiple-value-bind, multiple-value-list.</description>21</concept>2223<concept name="dynamic_binding">24<description>Special variables with dynamic scope using defvar/defparameter. Convention: *earmuffs* for special variables.</description>25</concept>26</common_lisp_fundamentals>2728<clos>29<description>Common Lisp Object System - Generic functions and multiple dispatch</description>3031<pattern name="defclass">32<description>Define a class with slots. Slot options: :initarg, :initform, :accessor, :reader, :writer, :type, :documentation.</description>33<example>34(defclass person ()35 ((name :initarg :name :accessor person-name)36 (age :initarg :age :accessor person-age))37 (:documentation "Represents a person."))38</example>39</pattern>4041<pattern name="defgeneric_defmethod">42<description>Define generic functions with multiple method implementations.</description>43<example>44(defgeneric greet (entity)45 (:documentation "Greet an entity."))4647(defmethod greet ((p person))48(format t "Hello, ~a!~%" (person-name p)))49</example>50</pattern>5152<pattern name="method_combination">53<description>Method qualifiers (:before, :after, :around) for aspect-oriented programming.</description>54<example>55(defmethod greet :before ((p person))56 (format t "Preparing to greet...~%"))5758(defmethod greet :around ((p person))59(format t "[Start]~%")60(call-next-method)61(format t "[End]~%"))62</example>63</pattern>6465<pattern name="multiple_inheritance">66<description>Classes can inherit from multiple parent classes. Uses C3 linearization for method resolution order.</description>67<example>68(defclass employee (person job-holder)69 ((employee-id :initarg :id :accessor employee-id)))70</example>71</pattern>72</clos>7374<conditions>75<description>Common Lisp condition system - Restarts and handlers</description>7677<pattern name="handler_case">78<description>Handle conditions similar to try-catch</description>79<example>80(handler-case81 (/ 1 0)82 (division-by-zero (c)83 (format t "Caught: ~a~%" c)84 0))85</example>86</pattern>8788<pattern name="handler_bind">89<description>Handle conditions without unwinding stack</description>90<example>91(handler-bind92 ((error #'(lambda (c)93 (format t "Error occurred: ~a~%" c)94 (invoke-restart 'use-value 0))))95 (restart-case96 (error "Something went wrong")97 (use-value (v) v)))98</example>99</pattern>100101<pattern name="restart_case">102<description>Define recovery points</description>103<example>104(defun parse-entry (entry)105 (restart-case106 (parse-integer entry)107 (use-value (v)108 :report "Use a different value"109 :interactive (lambda () (list (read)))110 v)111 (skip-entry ()112 :report "Skip this entry"113 nil)))114</example>115</pattern>116117<pattern name="define_condition">118<description>Define custom condition types for structured error handling.</description>119<example>120(define-condition invalid-input (error)121 ((value :initarg :value :reader invalid-input-value))122 (:report (lambda (c stream)123 (format stream "Invalid input: ~a"124 (invalid-input-value c)))))125</example>126</pattern>127</conditions>128129<packages>130<pattern name="defpackage">131<description>Define packages with explicit dependencies and exports.</description>132<example>133(defpackage #:my-project134 (:use #:cl)135 (:import-from #:alexandria #:when-let #:if-let)136 (:export #:main137 #:process-data))138</example>139</pattern>140141<pattern name="package_local_nicknames">142<description>Define local package nicknames for shorter, clearer references.</description>143<example>144(defpackage #:my-project145 (:use #:cl)146 (:local-nicknames (#:a #:alexandria)147 (#:s #:serapeum)))148</example>149</pattern>150</packages>151152<asdf>153<description>Another System Definition Facility - Build system for Common Lisp</description>154155<pattern name="basic_defsystem">156<description>Basic ASDF system definition with metadata and component dependencies.</description>157<example>158(defsystem "my-project"159 :description "My project description"160 :version "0.1.0"161 :author "Author Name"162 :license "MIT"163 :depends-on ("alexandria" "cl-ppcre")164 :components ((:file "package")165 (:file "utils" :depends-on ("package"))166 (:file "main" :depends-on ("utils"))))167</example>168</pattern>169170<pattern name="module_organization">171<description>Organize system components into modules for better structure.</description>172<example>173(defsystem "my-project"174 :components175 ((:module "src"176 :components ((:file "package")177 (:file "core" :depends-on ("package"))))178 (:module "tests"179 :depends-on ("src")180 :components ((:file "test-suite")))))181</example>182</pattern>183184<pattern name="package_inferred_system">185<description>Infer dependencies from defpackage forms for modern, maintainable systems.</description>186<example>187(defsystem "my-project"188 :class :package-inferred-system189 :depends-on ("my-project/main"))190191;; In my-project/main.lisp:192(defpackage #:my-project/main193(:use #:cl)194(:import-from #:my-project/utils #:helper))195</example>196</pattern>197198<pattern name="test_system">199<description>Define test system with automatic test execution using test-op.</description>200<example>201(defsystem "my-project/test"202 :depends-on ("my-project" "fiveam")203 :components ((:file "tests"))204 :perform (test-op (o s)205 (uiop:symbol-call :fiveam '#:run!206 (uiop:find-symbol* '#:my-test-suite :my-project/test))))207</example>208</pattern>209210<pattern name="project_structure">211<description>Recommended directory layout for Common Lisp projects.</description>212<example>213my-project/214├── my-project.asd215├── src/216│ ├── package.lisp217│ ├── utils.lisp218│ └── main.lisp219└── tests/220└── test-suite.lisp221</example>222</pattern>223</asdf>224225<sbcl>226<description>Steel Bank Common Lisp - High-performance implementation</description>227228<pattern name="save_executable">229<description>Create standalone executable with SBCL.</description>230<example>231(defun main ()232 (format t "Hello, World!~%")233 (sb-ext:exit :code 0))234235(sb-ext:save-lisp-and-die "my-app"236:toplevel #'main237:executable t238:compression t)239</example>240</pattern>241242<pattern name="threading">243<description>SBCL threading support with make-thread and mutex synchronization.</description>244<example>245(defvar *result* nil)246247(let ((thread (sb-thread:make-thread248(lambda ()249(setf _result_ (heavy-computation)))250:name "worker")))251(sb-thread:join-thread thread))252253;; Mutex254(defvar _lock_ (sb-thread:make-mutex))255(sb-thread:with-mutex (_lock_)256(critical-section))257</example>258</pattern>259260<pattern name="foreign_function">261<description>Call C functions from SBCL using sb-alien interface.</description>262<example>263(sb-alien:define-alien-routine "strlen" sb-alien:int264 (str sb-alien:c-string))265266(strlen "hello") ; => 5267</example>268</pattern>269270<pattern name="optimization">271<description>Use declarations for type information and optimization settings. Options: type, ftype, inline, optimize.</description>272<example>273(defun fast-add (x y)274 (declare (type fixnum x y)275 (optimize (speed 3) (safety 0)))276 (the fixnum (+ x y)))277</example>278</pattern>279280<pattern name="sbcl_extensions">281<description>SBCL-specific extensions for system interaction and performance tuning.</description>282<example>283;; Command-line arguments284sb-ext:*posix-argv*285286;; Execute external programs287(sb-ext:run-program "/bin/ls" '("-l"))288289;; Trigger garbage collection290(sb-ext:gc)291292;; POSIX interface: sb-posix293;; Network sockets: sb-bsd-sockets294</example>295</pattern>296</sbcl>297298<coalton>299<description>Statically typed functional programming on Common Lisp</description>300301<pattern name="basic_types">302<description>Define algebraic data types in Coalton with type-safe operations.</description>303<example>304(coalton-toplevel305 (define-type (Maybe a)306 None307 (Some a))308309(declare safe-div (Integer -> Integer -> (Maybe Integer)))310(define (safe-div x y)311(if (== y 0)312None313(Some (/ x y)))))314</example>315</pattern>316317<pattern name="type_classes">318<description>Define type classes for polymorphic behavior in Coalton.</description>319<example>320(coalton-toplevel321 (define-class (Printable a)322 (print-it (a -> String)))323324(define-instance (Printable Integer)325(define (print-it x)326(into x))))327</example>328</pattern>329330<pattern name="coalton_integration">331<description>Coalton compiles to efficient Common Lisp code and is interoperable with regular CL.</description>332<note>Use coalton-toplevel for type-safe code sections</note>333<note>Coalton functions can call CL functions and vice versa</note>334<note>Provides Hindley-Milner type inference with type classes</note>335</pattern>336</coalton>337338<context7_libraries>339<description>Available Context7 documentation libraries for Common Lisp ecosystem.</description>340341<tool name="context7_common_lisp_docs">342<description>Common Lisp Docs - General Common Lisp documentation</description>343<param name="library_id">/lisp-docs/lisp-docs.github.io</param>344<param name="trust_score">4.7</param>345<param name="snippets">580</param>346</tool>347348<tool name="context7_asdf">349<description>ASDF - Another System Definition Facility documentation</description>350<param name="library_id">/websites/asdf_common-lisp_dev</param>351<param name="trust_score">7.5</param>352<param name="snippets">190</param>353</tool>354355<tool name="context7_sbcl">356<description>SBCL - Steel Bank Common Lisp documentation</description>357<param name="library_id">/sbcl/sbcl</param>358<param name="trust_score">8.0</param>359<param name="snippets">86</param>360</tool>361362<tool name="context7_cffi">363<description>CFFI - Common Foreign Function Interface documentation</description>364<param name="library_id">/websites/cffi_common-lisp_dev</param>365<param name="trust_score">7.5</param>366<param name="snippets">198</param>367</tool>368369<tool name="context7_fiveam">370<description>FiveAM - Testing framework documentation</description>371<param name="library_id">/websites/fiveam_common-lisp_dev</param>372<param name="trust_score">7.5</param>373<param name="snippets">164</param>374</tool>375376<tool name="context7_coalton">377<description>Coalton - Statically typed functional programming documentation</description>378<param name="library_id">/coalton-lang/coalton</param>379<param name="trust_score">6.6</param>380<param name="snippets">568</param>381</tool>382383<pattern name="retrieve_documentation">384<description>Use resolve-library-id then get-library-docs for latest documentation.</description>385<example>386;; Get ASDF documentation387mcp__context7__get-library-docs388 context7CompatibleLibraryID="/websites/asdf_common-lisp_dev"389 topic="defsystem"390</example>391</pattern>392</context7_libraries>393394<common_patterns>395<pattern name="with_macro">396<description>Resource management with unwind-protect for cleanup.</description>397<example>398(defmacro with-open-socket ((var host port) &body body)399`(let ((,var (make-socket ,host ,port)))400(unwind-protect401(progn ,@body)402(close-socket ,var))))403</example>404</pattern>405406<pattern name="loop_macro">407<description>Loop macro for iteration with collection, filtering, and accumulation.</description>408<example>409(loop for item in list410 for i from 0411 when (evenp i)412 collect item into evens413 finally (return evens))414</example>415</pattern>416417<pattern name="format_directives">418<description>Common format directives: ~a (aesthetic), ~s (standard), ~d (decimal), ~f (float), ~% (newline), ~{~} (iteration), ~[~] (conditional).</description>419<example>420(format t "~a is ~d years old~%" name age)421</example>422</pattern>423424<pattern name="documentation">425<description>Document functions with docstrings explaining purpose and parameters.</description>426<example>427(defun my-function (arg)428 "Docstring describing the function.429ARG is the argument description."430 (process arg))431</example>432</pattern>433</common_patterns>434435<best_practices>436<practice priority="high">Use `*earmuffs*` for special variables</practice>437<practice priority="high">Use +plus-signs+ for constants</practice>438<practice priority="high">Prefer functional style, minimize mutation</practice>439<practice priority="high">Provide restarts for recoverable situations</practice>440<practice priority="high">Document exported symbols</practice>441<practice priority="medium">Use appropriate condition types, not just error</practice>442<practice priority="medium">Use check-type for argument validation</practice>443<practice priority="medium">Prefer ASDF package-inferred-system for new projects</practice>444<practice priority="medium">Consider Qlot for per-project dependency management</practice>445<practice priority="medium">Use Roswell for portable script execution</practice>446</best_practices>447448<modern_tooling>449<tool name="qlot">450<description>Per-project dependency manager (like bundler/npm)</description>451<use_case>Install dependencies from qlfile</use_case>452<use_case>Run commands with project dependencies</use_case>453<example>454qlot install455qlot exec ros run456</example>457</tool>458459<tool name="roswell">460<description>Lisp implementation manager and script runner</description>461<use_case>Install Lisp implementations or libraries</use_case>462<use_case>Start REPL with specified implementation</use_case>463<use_case>Build standalone executable</use_case>464<example>465ros install sbcl466ros run467ros build myapp.ros468</example>469</tool>470</modern_tooling>471472<anti_patterns>473<avoid name="global_state">474<description>Global mutable state makes code harder to test and reason about.</description>475<instead>Pass state explicitly or use closures to encapsulate mutable state.</instead>476</avoid>477478<avoid name="bare_use">479<description>Using :use for packages other than :cl creates namespace pollution.</description>480<instead>Use :import-from or package-local-nicknames for clearer dependencies.</instead>481</avoid>482483<avoid name="ignore_conditions">484<description>Ignoring conditions loses error context and recovery opportunities.</description>485<instead>Handle conditions with handler-case or handler-bind, and provide appropriate restarts.</instead>486</avoid>487488<avoid name="deep_nesting">489<description>Deeply nested code reduces readability and maintainability.</description>490<instead>Extract helper functions and use early returns to reduce nesting depth.</instead>491</avoid>492493<avoid name="eval_usage">494<description>Using eval in application code is slow and defeats compile-time optimization.</description>495<instead>Use macros for compile-time code generation or first-class functions for runtime dispatch.</instead>496</avoid>497498<avoid name="read_macros_overuse">499<description>Custom reader macros make code harder to read for others.</description>500<instead>Use reader macros sparingly and document them clearly when necessary.</instead>501</avoid>502</anti_patterns>503504---505> Converted and distributed by [TomeVault](https://tomevault.io/claim/mtaku3) — claim your Tome and manage your conversions.506<!-- tomevault:4.0:skill_md:2026-04-13 -->