### Install a Library with Quicklisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/using-cl-implementation.md Use `ql:quickload` to install a library and its dependencies. Once loaded, the library is available in the current Lisp session. ```lisp (ql:quickload "drakma") ; Installs the Drakma HTTP client library ``` -------------------------------- ### Start Local Development Server Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/README.md Starts a local development server. Changes are reflected live without a server restart. ```bash yarn start ``` -------------------------------- ### Use an Installed Library with Quicklisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/using-cl-implementation.md After installing a library with `ql:quickload`, you can use its functions. Alternatively, specify it in your ASDF dependencies. ```lisp (ql:quickload "drakma") (drakma:http-request "http://www.google.com") ``` -------------------------------- ### Install Dependencies Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/README.md Run this command to install project dependencies using Yarn. ```bash yarn ``` -------------------------------- ### Install SLIME via Quicklisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/using-cl-implementation.md Use this command within your Lisp REPL to install the SLIME package using Quicklisp. ```lisp (ql:quickload "quicklisp-slime-helper") ``` -------------------------------- ### Update All Installed Libraries Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/using-cl-implementation.md Use `ql:update-all-dists` to update all installed libraries to their latest available versions. ```lisp (ql:update-all-dists) ``` -------------------------------- ### Install SBCL on Debian/Ubuntu Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/using-cl-implementation.md Use apt-get to install the SBCL Common Lisp implementation on Debian-based Linux systems. ```bash sudo apt-get install sbcl ``` -------------------------------- ### Install SBCL on Arch Linux Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/using-cl-implementation.md Use pacman to install the SBCL Common Lisp implementation on Arch Linux. ```bash sudo pacman -S sbcl ``` -------------------------------- ### Lisp Macro Parameter List Examples Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/macros.md Provides examples of various parameter list configurations for `defmacro`, including required, optional, rest, keyword, and auxiliary parameters. ```lisp (x y) ``` ```lisp (x &optional y) ``` ```lisp (x &optional (y 10)) ``` ```lisp (x &rest rest) ``` ```lisp (&key name age) ``` ```lisp (&key (name "default") (age 20)) ``` ```lisp (x &aux (z (+ x 1))) ``` -------------------------------- ### Summarized package usage example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/packages.md This example demonstrates defining a package that uses both Common Lisp and another custom package, switching to it, and then using exported symbols from the custom package. It also shows defining and exporting a new function within the application package. ```lisp (defpackage :my-application (:use :common-lisp :my-utils)) (in-package :my-application) (my-function 20) ; Uses my-function from my-utils (print my-variable) ; Uses my-variable from my-utils (defun application-function () (print "Application function")) (export 'application-function) ; Exports the application function ``` -------------------------------- ### Print Hello World in Common Lisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/blog/2023-11-12-mission-again.md A basic example of printing output to the console in Common Lisp. ```lisp (format T "Hello World!") ``` -------------------------------- ### Example: Reading from a File in a Specific Directory Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/io.md Demonstrates using `merge-pathnames` to construct a file pathname and then reading from that file. ```APIDOC ## Example: Reading from a File in a Specific Directory ### Description This example shows how to use `merge-pathnames` to construct a pathname from a directory path and a file name, and then read its content. ### Method Function calls ### Endpoint N/A (Lisp code) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp (let ((directory-path "/my/data/")) (let ((file-pathname (merge-pathnames "input.txt" directory-path))) (with-open-file (input file-pathname :direction :input) (when input (loop for line = (read-line input nil) while line do (print line)))))) ``` ### Response #### Success Response (200) - **Output** (string) - The lines read from the input file will be printed to the standard output. #### Response Example ```lisp "This is the first line." "This is the second line." ``` ``` -------------------------------- ### Get Documentation for a Package Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/documentation.md Retrieves the documentation string for a package. Use the 'package' doc-type. ```lisp (defpackage :my-utils (:use :common-lisp) (:export :my-function :my-variable) (:documentation "A package containing utility functions.")) (documentation :my-utils 'package) ``` -------------------------------- ### Check SBCL Installation Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/debugging.md Verify if SBCL is installed on your system by checking its version. ```sh sbcl --version ``` -------------------------------- ### Lisp-like Task and Echo Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/whylisp/whylispdevelopers.md A Lisp-style s-expression example representing a task with a name and an echo command. ```clojure (task (name "Test") (echo (message "Hello World!"))) (Test) ``` -------------------------------- ### Load a Common Lisp Project with Quicklisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/projects/packages-systems.md Use this command to load a project and its dependencies. Quicklisp will download the project if it's not already installed. ```lisp (ql:quickload :bobbin) ``` -------------------------------- ### Lisp Function Call Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/whylisp/whylispdevelopers.md Illustrates the standard syntax for calling a Lisp function with arguments. ```clojure (function-name arg1 arg2 arg3) ``` -------------------------------- ### Install SBCL on macOS Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/using-cl-implementation.md Use Homebrew to install the SBCL Common Lisp implementation on macOS. ```bash brew install sbcl ``` -------------------------------- ### Basic `let` Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/functions.md A simple `let` form demonstrating parallel binding of two variables and their use in an expression. ```lisp (let ((x 10) (y 20)) (+ x y)) ``` -------------------------------- ### Ant Task Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/whylisp/whylispdevelopers.md This is an example of an Ant task that would print 'Hello World!' if Ant supported the 'task' construct. It illustrates the concept of XML-based programming. ```xml ``` -------------------------------- ### Quickload Hunchentoot Library Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/howto/webdev-hunchentoot/start.md Use this command to load the Hunchentoot web server library via Quicklisp. Ensure Quicklisp is installed and configured. ```lisp (ql:quickload "hunchentoot") ``` -------------------------------- ### Lisp Macro Call Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/whylisp/whylispdevelopers.md Demonstrates how a Lisp macro is called, where arguments are not immediately evaluated. ```clojure (macro-name (+ 4 5)) ``` -------------------------------- ### Get Documentation for a Class Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/documentation.md Retrieves the documentation string for a class definition. Use the 'class' doc-type. ```lisp (defclass person () ((name :initarg :name :accessor person-name) (age :initarg :age :accessor person-age)) (:documentation "Represents a person with a name and age.")) (documentation 'person 'class) ``` -------------------------------- ### Lisp macroexpand Example with Nested Macros Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/macros.md Demonstrates using `macroexpand` to fully expand nested macro calls recursively. ```lisp (macroexpand '(my-when (> 5 0) (my-print "Hello"))) ; Returns: ; (IF (> 5 0) (PROGN (PRINT "Hello"))) ; T ``` -------------------------------- ### Load SLIME via Quicklisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/debugging.md Install the SLIME (Superior Lisp Interaction Mode) library using Quicklisp for Emacs integration. ```lisp (ql:quickload "slime") ``` -------------------------------- ### Load SLY via Quicklisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/debugging.md Install the SLY (Superior Lisp Interaction) library using Quicklisp, a modern alternative to SLIME for Emacs integration. ```lisp (ql:quickload "sly") ``` -------------------------------- ### Getting Quotient and Remainder in Common Lisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/informal-introduction-to-lisp.md Demonstrates how to retrieve both the quotient and remainder from the `floor` function using `multiple-value-bind`. ```lisp (multiple-value-bind (quotient remainder) (floor 17 3) (format t "Quotient: ~a, Remainder: ~a~%" quotient remainder)) ``` -------------------------------- ### Example C Function: add Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/using-cl-implementation.md A simple C function that takes two integers and returns their sum. This is a basic example for demonstrating CFFI integration. ```c #include int add(int a, int b) { return a + b; } ``` -------------------------------- ### Get Documentation for a Variable Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/documentation.md Retrieves the documentation string for a global variable. Use the 'variable' doc-type. ```lisp (defvar *my-global-variable* 42 "A global variable used for important calculations.") (documentation '*my-global-variable* 'variable) ``` -------------------------------- ### Call `describe` with `eql` Specializer Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/object-system.md Example of calling the generic function `describe` with an argument that matches the `eql` specializer. ```lisp (describe :hello) ; Prints "You said hello!" ``` -------------------------------- ### Documenting a Lisp Package (`defpackage`) Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/documentation.md Document packages by describing their purpose and the functionality they provide. This example defines a utility package for string manipulation. ```lisp (defpackage :my-utils (:use :common-lisp) (:export :my-function :my-variable) (:documentation "A package containing utility functions for string manipulation and data processing.")) ``` -------------------------------- ### Configure Emacs for SLIME Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/using-cl-implementation.md Add these lines to your Emacs initialization file to load and set up SLIME. Replace the path with your SLIME installation's correct location and 'sbcl' with your Lisp implementation. ```elisp (add-to-list 'load-path "~/.quicklisp/dists/quicklisp/software/slime-20231022/") ; Replace with correct path (require 'slime) (slime-setup '(sbcl)) ; Replace sbcl with your Lisp implementation of choice ``` -------------------------------- ### Define Dog Class with Combined Slot Options Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/object-system.md Example demonstrating the use of `:initarg`, `:initform`, and `:accessor` together for defining class slots with initialization and access methods. ```lisp (defclass dog () ((name :initarg :name :accessor dog-name) (breed :initarg :breed :initform "Unknown" :accessor dog-breed) (age :initarg :age :initform 0 :accessor dog-age))) (let ((my-dog (make-instance 'dog :name "Fido" :age 3))) (format t "Name: ~a, Breed: ~a, Age: ~a~%" (dog-name my-dog) (dog-breed my-dog) (dog-age my-dog))) (let ((another-dog (make-instance 'dog :name "Rover"))) (format t "Name: ~a, Breed: ~a, Age: ~a~%" (dog-name another-dog) (dog-breed another-dog) (dog-age another-dog))) ``` -------------------------------- ### Lisp Macro Expansion Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/macros.md Demonstrates the expansion of the `when-positive` macro, showing how the macro call is transformed into an `if` statement before evaluation. ```lisp (when-positive 5 (print "Positive!")) ``` ```lisp (if (> 5 0) (progn (print "Positive!"))) ``` -------------------------------- ### Create Default Hash Table Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/data-structures.md Creates a new hash table using the default `eql` equality test for keys. No specific setup is required. ```lisp (make-hash-table) ``` -------------------------------- ### Get Nth Tail with nthcdr Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/data-structures.md Use `nthcdr` to obtain the sublist starting from the nth element (zero-based index). It returns the `cdr` of the list `n` times. ```lisp (nthcdr 2 (list 'a 'b 'c 'd)) ; Returns (C D) ``` -------------------------------- ### Standard Method Combination Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/object-system.md Illustrates the use of :before, :after, :around, and :primary method qualifiers in CLOS. The :around method controls execution flow, calling :before, :primary, and :after methods via call-next-method. ```lisp (defgeneric operate (x y) (:documentation "Performs an operation on x and y.")) (defmethod operate :before ((x number) (y number)) (format t "Before operation: x = ~a, y = ~a~%" x y)) (defmethod operate :after ((x number) (y number)) (format t "After operation.~%")) (defmethod operate :around ((x number) (y number)) (format t "Around operation (before).~%") (let ((result (call-next-method))) ; Call the next most specific method (format t "Around operation (after). Result was ~a~%" result) result)) (defmethod operate ((x integer) (y integer)) (format t "Primary method (integers): ~%") (+ x y)) (defmethod operate ((x float) (y float)) (format t "Primary method (floats): ~%") (* x y)) (operate 5 3) (operate 2.5 4.0) ``` -------------------------------- ### Load and Use Animal Simulator Project Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/packages.md Loads the 'animal-simulator' system using Quicklisp and demonstrates its usage by creating and simulating animals. ```lisp (ql:quickload :animal-simulator) ``` ```lisp (in-package :animal-simulator) (let ((animals (list (make-animal 'dog "Rover") (make-animal 'cat "Whiskers") (make-animal 'animal "Generic")))) (simulate-round animals)) ``` -------------------------------- ### Create Local Projects Directory Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/using-cl-implementation.md Create a `local-projects` directory within `~/.quicklisp` to manage dependencies for individual projects. ```bash mkdir -p ~/.quicklisp/local-projects ``` -------------------------------- ### Load a Local Project with Quicklisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/using-cl-implementation.md Load your local project and its dependencies into the Lisp environment using `ql:quickload` with the project's system name. ```lisp (ql:quickload :my-project) ``` -------------------------------- ### Load and Use ASDF Project Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/using-cl-implementation.md Demonstrates loading an ASDF system and then calling a function defined within it. Ensure the project's .asd file and source files are correctly set up. ```lisp (asdf:load-system :my-project) (my-project:hello) ; Prints "Hello, world!" ``` -------------------------------- ### Create and Switch Packages in Common Lisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/projects/guide_to_packages.md Demonstrates creating new packages and switching the current package context. Use this to set up distinct namespaces for different modules or developers. ```lisp ? (make-package :bob) # ? (make-package :jane) # ? (in-package bob) # ? (defun foo () "This is Bob's foo") FOO ? (in-package jane) # ? (defun foo () "This is Jane's foo") FOO ? (foo) "This is Jane's foo" ? (in-package bob) # ? (foo) "This is Bob's foo" ? ``` -------------------------------- ### Lisp Highlighted Code Block Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/blog/2023-11-29.md Example of a Lisp code block with syntax highlighting. Ensure all Lisp code is formatted this way. ```lisp (defun hello-world () (print "Hello, World!")) ``` -------------------------------- ### Extract Substrings with `subseq` in Common Lisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/data-structures.md The `subseq` function extracts a portion of a string. Provide a start index, or both start and end indices. ```lisp (subseq "Hello, world!" 7) ; Returns "world!" (from index 7 to the end) ``` ```lisp (subseq "Hello, world!" 0 5) ; Returns "Hello" (from index 0 up to, but not including, index 5) ``` -------------------------------- ### More Comma Unquoting Examples Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/macros.md Provides additional examples of using the comma operator with backquote to dynamically insert evaluated expressions, including variables, symbols, and lists. ```lisp (let ((name "Alice")) `(hello ,name)) ; Evaluates to (HELLO "Alice") (let ((operation '+)) `(,operation 5 3)) ; Evaluates to (+ 5 3), which then evaluates to 8 (let ((list '(1 2 3))) `(a ,list b)) ; Evaluates to (A (1 2 3) B) ``` -------------------------------- ### Work with Property Lists (Plists) Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/data-structures.md Property lists (plists) are lists of alternating keys and values. Use `getf` to retrieve values by key. Plists are often used for metadata. ```lisp (let ((my-plist '(name "Bob" age 25 city "London"))) (print (getf my-plist 'name)) ; Prints "Bob" (print (getf my-plist 'age))) ; Prints 25 ``` -------------------------------- ### Define an ASDF System for a Local Project Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/using-cl-implementation.md Create a `.asd` file in the `local-projects` directory to define your project's system, version, description, author, license, and dependencies. ```lisp (asdf:defsystem :my-project :version "1.0.0" :description "My awesome project" :author "Your Name" :license "MIT" :depends-on ("drakma" "other-library")) ``` -------------------------------- ### Symbol Conflict Resolution Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/projects/guide_to_packages.md Demonstrates resolving a symbol conflict by first uninterning the conflicting symbol. This example also shows how MAKE-SYMBOL is called by the reader and its output can appear interleaved with other expressions. ```lisp ? (unintern 'my-symbol) T ? (eq symbol1 'my-symbol Calling (MAKE-SYMBOL "MY-SYMBOL") MAKE-SYMBOL returned #:MY-SYMBOL ) NIL ? ``` -------------------------------- ### Create Person Instance with make-instance Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/object-system.md Illustrates creating an object of the `person` class using `make-instance`, providing initial values for slots via keyword arguments. ```lisp (defclass person () ((name :initarg :name :accessor person-name) (age :initarg :age :initform 0 :accessor person-age))) (let ((alice (make-instance 'person :name "Alice" :age 30))) (print alice)) ``` -------------------------------- ### Get String Length in Common Lisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/data-structures.md The `length` function returns the number of characters in a string. ```lisp (length "Common Lisp") ; Returns 11 ``` -------------------------------- ### Get Method Combination Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/advanced_topics/mop.md Returns the method combination object of a generic function, usually `STANDARD`. ```lisp (method-combination (fdefinition 'greet)) ; Returns STANDARD ``` -------------------------------- ### Get Generic Function Name Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/advanced_topics/mop.md Retrieves the name of a generic function. Requires the function definition. ```lisp (defgeneric greet (x)) (generic-function-name (fdefinition 'greet)) ; Returns GREET ``` -------------------------------- ### Build Static Website Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/README.md Generates static website content into the 'build' directory for hosting. ```bash yarn build ``` -------------------------------- ### S-expression To-Do List Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/whylisp/whylispdevelopers.md The same to-do list represented using s-expressions, a Lisp data structure. ```clojure (todo "housework" (item (priority high) "Clean the house.") (item (priority medium) "Wash the dishes.") (item (priority medium) "Buy more soap.")) ``` -------------------------------- ### Lisp macroexpand-1 Nested Macro Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/macros.md Illustrates that `macroexpand-1` only expands the outermost macro in a nested call. ```lisp (defmacro my-print (x) `(print ,x)) (defmacro my-when (condition &body body) `(if ,condition (progn ,@body))) (macroexpand-1 '(my-when (> 5 0) (my-print "Hello"))) ; Returns: ; (IF (> 5 0) (PROGN (MY-PRINT "Hello"))) ; T ``` -------------------------------- ### Get Documentation for a Function Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/documentation.md Retrieves the documentation string for a function. Ensure the symbol and doc-type are correctly specified. ```lisp (defun greet (name) "Greets the given name." (format t "Hello, ~a!~%" name)) (documentation 'greet 'function) ``` -------------------------------- ### Documenting a Lisp Package Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/documentation.md Use the `:documentation` keyword within the options list for `defpackage` definitions. ```lisp (defpackage :my-utils (:use :common-lisp) (:export :my-function :my-variable) (:documentation "A package containing utility functions.")) ; Docstring ``` -------------------------------- ### Deploy Website (SSH) Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/README.md Deploys the website using SSH. Assumes GitHub Pages hosting. ```bash USE_SSH=true yarn deploy ``` -------------------------------- ### Initialize Slot with :initform Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/object-system.md Demonstrates initializing a slot using :initform when no :initarg is provided during instance creation. The :initform is used as the default value. ```lisp (let ((bob (make-instance 'person :name "Bob"))) (print (person-age bob))) ; Prints 0 because of the :initform ``` -------------------------------- ### Lisp macroexpand Non-Macro Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/macros.md Shows that `macroexpand` returns the form unchanged with NIL if the input contains no macros. ```lisp (macroexpand '(+ 1 2)) ; Returns: ; (+ 1 2) ; NIL ``` -------------------------------- ### Handle Missing Documentation with IF Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/documentation.md Demonstrates how to check if documentation exists for a symbol and handle the case where it doesn't, returning a default message. ```lisp (defun my-function-without-docs ()) (if (documentation 'my-function-without-docs 'function) (print (documentation 'my-function-without-docs 'function)) (print "No documentation found.")) ``` -------------------------------- ### Create Hash Table with Initial Size Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/data-structures.md Creates a hash table with an initial estimated capacity of 100 entries. This is a hint and does not limit the table's growth. ```lisp (make-hash-table :size 100) ``` -------------------------------- ### Lisp macroexpand-1 Non-Macro Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/macros.md Shows that `macroexpand-1` returns the form unchanged with NIL if the input is not a macro call. ```lisp (macroexpand-1 '(+ 1 2)) ; Returns: ; (+ 1 2) ; NIL ``` -------------------------------- ### Lisp Sharp-Sign Uninterned Symbol Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/advanced_topics/readtables.md Demonstrates the `#:symbol` reader macro for creating uninterned symbols (gensyms). ```lisp (read-from-string "#:foo") ; Returns a freshly generated symbol. ``` -------------------------------- ### Create and Display Inventory Items in Lisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/object-system.md Creates instances of 'book' and 'electronics' classes and uses the 'display-item' generic function to show their details. Demonstrates object instantiation and polymorphism. ```lisp ;; Create some inventory items (let ((my-book (make-instance 'book :name "The Lisp Cookbook" :price 29.99 :quantity 10 :author "Peter Seibel" :isbn "978-1484206773")) (my-laptop (make-instance 'electronics :name "Laptop X1" :price 1200.00 :quantity 5 :manufacturer "XYZ Corp" :warranty 12))) ;; Display the items (format t "--- Book Information ---~%") (display-item my-book) (format t "--- Laptop Information ---~%") (display-item my-laptop) ;; Restock the book (restock my-book 5) ;; Display again to confirm restock. (format t "--- Book Information after restock ---~%") (display-item my-book)) ) ``` -------------------------------- ### Get Generic Function Method Class Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/advanced_topics/mop.md Returns the class of the methods associated with a generic function, typically `standard-method`. ```lisp (generic-function-method-class (fdefinition 'greet)) ; Returns STANDARD-METHOD ``` -------------------------------- ### Get Generic Function Methods Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/advanced_topics/mop.md Returns a list of all methods associated with a generic function. Useful for counting methods. ```lisp (defmethod greet ((x number)) nil) (defmethod greet ((x integer)) nil) (length (generic-function-methods (fdefinition 'greet))) ; Returns 2 ``` -------------------------------- ### Use Loaded Functions and Variables Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/packages.md Shows how to use functions and variables defined in a previously loaded file. Requires switching to the appropriate package and using the desired symbols. ```lisp (in-package :cl-user) (use-package :my-utils) (greet "World") ; Prints "Hello, World!" (print *my-special-variable*) ; Prints 42 ``` -------------------------------- ### Get Documentation for a Method Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/documentation.md Retrieves documentation for a specific method of a generic function by providing the specialized parameter types. ```lisp (defgeneric my-generic (x)) (defmethod my-generic ((x integer)) "This is the integer method.") (documentation `(my-generic ,(find-class 'integer)) 'method) ``` -------------------------------- ### Access and Modify Hash Table Entries Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/data-structures.md Demonstrates using `setf gethash` to insert key-value pairs and `gethash` to retrieve values, showing how it returns both the value and a presence indicator. ```lisp (let ((my-hash (make-hash-table))) (setf (gethash 'a my-hash) 1) (setf (gethash 'b my-hash) 2) (multiple-value-bind (value present) (gethash 'a my-hash) (format t "Value of a: ~a, Present: ~a~%" value present)) ; Prints "Value of a: 1, Present: T" (multiple-value-bind (value present) (gethash 'c my-hash) (format t "Value of c: ~a, Present: ~a~%" value present)) ; Prints "Value of c: NIL, Present: NIL" ) ``` -------------------------------- ### Call Function with &allow-other-keys and &aux Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/functions.md Examples of calling a function that accepts extra keyword arguments and uses auxiliary variables. ```lisp (process-data '(:a 1 :b 2 :verbose nil :c 3)) ``` ```lisp (process-data '(:a 1 :b 2 :c 3)) ``` -------------------------------- ### Infinite Loop with Immediate Exit Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/control-flows.md Demonstrates the simplest form of `loop`, which creates an infinite loop. Use `return` or similar to exit. ```lisp (loop (print "This will print forever unless we stop it!") (return)) ``` -------------------------------- ### Configure Emacs for SLIME Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/debugging.md Set up Emacs to use SLIME by specifying the SBCL executable path and loading the SLIME library. ```lisp (setq inferior-lisp-program "/path/to/sbcl") ;; Path to SBCL (require 'slime) (slime-setup) ``` -------------------------------- ### Lisp Comma vs Comma-At Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/macros.md Demonstrates how comma (,) inserts the value of an expression and comma-at (,@) inserts the elements of a list. ```lisp (let ((numbers '(1 2 3))) `(a ,@numbers b)) ; Evaluates to (A 1 2 3 B) ``` -------------------------------- ### Switching Packages and Symbol Resolution Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/projects/guide_to_packages.md Demonstrates how changing the current package affects symbol resolution and how to refer to symbols in other packages using package qualifiers. ```lisp ? (in-package jane) # ? 'foo FOO ? 'jane::foo FOO ? (in-package bob) # ? 'foo FOO ? 'jane::foo JANE::FOO ? 'bob::foo FOO ? ``` -------------------------------- ### Get List Length Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/informal-introduction-to-lisp.md Calculates the number of elements in a list using the `length` function. This applies to lists and other sequence types. ```lisp (setf letters (list 'a 'b 'c 'd)) ``` ```lisp (length letters) ``` -------------------------------- ### Control Readtable with with-standard-io-syntax Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/io.md Use `with-standard-io-syntax` to establish a standard readtable for consistent parsing of input and output. Recommended for portable data reading and writing. ```lisp (with-standard-io-syntax (with-open-file (output "data.lisp" :direction :output :if-exists :supersede) (print '(a b c) output))) (with-standard-io-syntax (with-open-file (input "data.lisp" :direction :input) (print (read input)))) ; prints (A B C) ``` -------------------------------- ### Get Character from Code in Common Lisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/data-structures.md The `code-char` function converts a numeric character code back into its corresponding character. ```lisp (code-char 97) ; Returns #\a (in most implementations using ASCII or UTF-8) ``` -------------------------------- ### Opening a File for Writing Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/io.md Use the `open` function to open a file for writing. Specify the `:output` direction. This will create the file if it doesn't exist or truncate it if it does. ```lisp ;; Open a file for writing (let ((file-stream (open "output.txt" :direction :output))) ;; Write to the file stream here (close file-stream)) ``` -------------------------------- ### Get the class of an object Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/advanced_topics/mop.md The `class-of` function returns the class object of a given instance. This is a fundamental MOP operation for introspection. ```lisp (defclass person () ((name :initarg :name :accessor person-name))) (let ((p (make-instance 'person :name "Alice"))) (class-of p)) ; Returns the class object for PERSON. ``` -------------------------------- ### Load ASDF using Quicklisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/using-cl-implementation.md Loads the ASDF library using Quicklisp. This is a prerequisite for managing Lisp projects with ASDF. ```lisp (ql:quickload "asdf") ``` -------------------------------- ### S-expression Equivalent of XML Copy Operation Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/whylisp/whylispdevelopers.md Translates the XML file copying example into an s-expression format, demonstrating reduced verbosity. ```clojure (copy (todir "../new/dir") (fileset (dir "src\_dir"))) ``` -------------------------------- ### Configure Emacs for SLY Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/debugging.md Set up Emacs to use SLY by specifying the SBCL executable path and loading the SLY library. ```lisp (setq inferior-lisp-program "/path/to/sbcl") ;; Path to SBCL (require 'sly) (sly-setup) ``` -------------------------------- ### Read File Content Using Merged Pathname Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/io.md This example demonstrates constructing a full file pathname using `merge-pathnames` and then opening and reading from that file. It shows a practical application of pathname merging for file I/O. ```lisp (let ((directory-path "/my/data/")) (let ((file-pathname (merge-pathnames "input.txt" directory-path))) (with-open-file (input file-pathname :direction :input) (when input (loop for line = (read-line input nil) while line do (print line)))))) ``` -------------------------------- ### Create a 2D array (matrix) Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/data-structures.md Define a multi-dimensional array by providing a list of dimensions to `make-array`. This example creates a 3x4 matrix. ```lisp (make-array '(3 4)) ``` -------------------------------- ### Lisp Sharp-Sign Block Comment Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/advanced_topics/readtables.md Illustrates the `#| ... |#` reader macro for block comments, where the reader ignores content between these delimiters. ```lisp (read-from-string "#| This is a block comment |# 123") ; Returns 123 ``` -------------------------------- ### Lisp Quote Reader Macro Example Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/advanced_topics/readtables.md Illustrates the quote reader macro, which transforms `'x` into `(quote x)` when reading from a string. ```lisp (read-from-string "'hello") ; Returns (QUOTE HELLO) ``` -------------------------------- ### Lisp Escape Character Examples Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/advanced_topics/readtables.md Demonstrates the use of backslash and vertical bars as escape characters within symbols and strings in Lisp. ```lisp 'My\ Symbol ; Reads as the symbol My Symbol '|My Symbol| ; Reads as the symbol My Symbol (preserves case) "This is a \"quoted\" string.\n" ; String with escaped quotes and newline ``` -------------------------------- ### Handle Custom Options in Class Creation with Lisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/advanced_topics/mop.md Use &key parameters in initialize-instance to handle custom options passed to defclass. This allows for dynamic configuration during class definition. ```lisp (defclass my-metaclass (standard-class) ((custom-option :initarg :custom-option :accessor custom-option))) (defmethod initialize-instance ((class my-metaclass) &rest initargs &key custom-option &allow-other-keys) (call-next-method) (when custom-option (setf (custom-option class) custom-option)) class) (defclass my-class () () (:metaclass my-metaclass) (:custom-option "A custom value")) (custom-option (find-class 'my-class)) ; Returns "A custom value" ``` -------------------------------- ### Access String Characters by Index in Lisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/informal-introduction-to-lisp.md Use `aref` to access characters by index, starting from 0. Negative indices are not supported. ```lisp (defvar word nil) (setf word "Lisp") (aref word 0) ; character in position 0 ``` ```lisp (aref word 2) ; character in position 5 ``` -------------------------------- ### Opening a File for Reading Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/io.md Use the `open` function to open a file for reading. Specify the `:input` direction. Ensure the file exists. ```lisp ;; Open a file for reading (let ((file-stream (open "my-file.txt" :direction :input))) ;; Process the file stream here (close file-stream)) ``` -------------------------------- ### Get Character Code in Common Lisp Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/data-structures.md The `char-code` function returns the numeric representation (e.g., ASCII or Unicode value) of a character. ```lisp (char-code #\a) ; Returns 97 (in most implementations using ASCII or UTF-8) ``` -------------------------------- ### Get Direct Superclasses Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/advanced_topics/mop.md Fetches the direct superclasses of the 'employee' class using `class-direct-superclasses`. This function returns a list of class metaobjects. ```lisp (class-direct-superclasses (find-class 'employee)) ; Returns (PERSON) ``` -------------------------------- ### Access and modify array elements Source: https://github.com/lisp-docs/lisp-docs.github.io/blob/main/docs/tutorial/data-structures.md Use `aref` to get or set elements in an array. For multi-dimensional arrays, provide indices for each dimension. ```lisp (let ((my-vector (make-array 5 :initial-element 0))) (setf (aref my-vector 2) 10) ; Sets the element at index 2 to 10 (print (aref my-vector 2)) ; Prints 10 (print (aref my-vector 0))) ; Prints 0 ``` ```lisp (let ((my-matrix (make-array '(3 4)))) (setf (aref my-matrix 1 2) 42) ; Sets the element at row 1, column 2 to 42 (print (aref my-matrix 1 2))) ; Prints 42 ```