Lisp

Lisp


Beginner

Q1: What is Lisp?

Lisp is a family of programming languages known for simple syntax, symbolic processing, and code-as-data.

Example:

(+ 1 2 3) ; => 6

Q2: Why is Lisp syntax full of parentheses?

Parentheses represent lists, which are the core data structure and syntax form in Lisp.

Q3: What does “code is data” mean in Lisp?

Lisp code is written as lists, and lists are regular data you can manipulate programmatically.

Q4: What is an s-expression?

An s-expression (symbolic expression) is either an atom (number, symbol, string) or a list.

Q5: What is a symbol?

A symbol is an identifier, like x, my-function, or +.

Q6: How do I run Lisp code?

Use a REPL (Read-Eval-Print Loop), such as SBCL REPL, where you type expressions and get immediate results.

Q7: What is the REPL?

An interactive environment that reads input, evaluates it, prints output, and loops.

Q8: What are atoms?

Basic non-list values: numbers, strings, symbols, characters, etc.

Q9: What is a list?

An ordered sequence, written in parentheses.

Example:

'(1 2 3) ; a literal list

Q10: Why quote with apostrophe (')?

Quote prevents evaluation and treats expression as literal data.

Example:

'( + 1 2 ) ; list containing symbols and numbers

Q11: What happens without quote?

Lisp tries to evaluate it as code.

Example:

(+ 1 2) ; => 3

Q12: What is nil?

nil means false and also the empty list in Common Lisp.

Q13: What is t?

t is the canonical true value.

Q14: How do I define a variable?

Use let for local bindings or ~defparameter/~defvar for globals.

Example:

(let ((x 10)) (+ x 5)) ; => 15

Q15: Difference between defparameter and defvar?

defparameter always assigns; defvar assigns only if variable is unbound.

Q16: How do I define a function?

Use defun.

Example:

(defun square (x) (* x x))
(square 4) ; => 16

Q17: What is function application syntax?

(function arg1 arg2 ...).

Q18: Are operators like + functions?

Yes, in Common Lisp arithmetic operators are functions.

Q19: How do conditionals work?

Use if, cond, or ~when/~unless.

Example:

(if (> 5 3) "yes" "no") ; => "yes"

Q20: What is cond?

Multi-branch conditional with test-result clauses.

Example:

(cond ((< x 0) :negative)
      ((= x 0) :zero)
      (t :positive))

Q21: What is lexical scope?

Variables are visible where they are textually defined (and nested inside).

Q22: What is dynamic scope?

Variable resolution based on call chain (special variables in Common Lisp).

Q23: What are special variables?

Dynamically scoped variables, usually named with stars: *print-base*.

Q24: What is setq?

Assigns to an existing variable.

Example:

(let ((x 1))
  (setq x 9)
  x) ; => 9

Q25: What is setf?

Generalized assignment to many “places” (variables, array slots, object fields).

Example:

(setf (car my-list) 42)

Q26) What are car and cdr?

car returns first element; cdr returns rest of list.

Example:

(car '(a b c)) ; => A
(cdr '(a b c)) ; => (B C)

Q27: What is cons?

Constructs a new cons cell from head and tail.

Example:

(cons 'a '(b c)) ; => (A B C)

Q28: What is a cons cell?

A pair of pointers: first part and rest part; lists are chains of cons cells.

Q29: How do I check types?

Use predicates like numberp, symbolp, listp, stringp.

Q30: What are predicates?

Functions returning truth values, often ending in p.

Q31: How do I loop?

Use loop, dolist, dotimes, recursion, or mapping functions.

Q32: What is dolist?

Iterates over list elements.

Example:

(dolist (x '(1 2 3))
  (format t "~A " x))

Q33: What is dotimes?

Repeats a fixed number of times.

Example:

(dotimes (i 3) (print i))

Q34: What is recursion?

Function calling itself with smaller input until a base case.

Q35: Example of recursion?

Example:

(defun fact (n)
  (if (<= n 1) 1 (* n (fact (- n 1)))))

Q36: What is tail recursion?

Recursive call is final operation; can be optimized in some Lisps (not guaranteed in Common Lisp).

Q37: How do I print output?

Use format.

Example:

(format t "Hello, ~A!~%" "Lisp")

Q38: Difference between print, princ, and prin1?

print adds newline and escapes; prin1 readable representation; princ user-friendly display.

Q39: How do I make strings?

Use double quotes: "hello".

Q40: How do I concatenate strings?

Use concatenate.

Example:

(concatenate 'string "Hello, " "world")

Q41: How do I compare numbers?

Use =, <, >, <=, >=.

Q42: How do I compare symbols/objects?

Use eq, eql, equal, or equalp depending on semantics.

Q43: Difference: eq, eql, equal, equalp?

Increasingly deep/permissive equality checks; equalp is most lenient.

Q44: What is a keyword?

A self-evaluating symbol in KEYWORD package, written like :name.

Q45: What is a property list (plist)?

Flat key-value list: (:name "Ana" :age 30).

Q46: How do I access plist values?

Use getf.

Example:

(getf '(:name "Ana" :age 30) :age) ; => 30

Q47: What is an association list (alist)?

List of key-value pairs, each pair typically a cons cell.

Q48: What is lambda?

Anonymous function expression.

Example:

(funcall (lambda (x) (+ x 10)) 5) ; => 15

Q49: What does funcall do?

Calls a function object with arguments.

Q50: What does apply do?

Calls a function with argument list where last arg is a list.

Example:

(apply #'+ '(1 2 3 4)) ; => 10

Intermediate

Q51: What is a package in Common Lisp?

Namespace for symbols to avoid naming conflicts.

Q52: How do I define a package?

With defpackage, then in-package.

Q53: What is :use in packages?

Imports external symbols from other packages (commonly :cl).

Q54: What is shadowing?

Creating a local symbol with same name as imported one.

Q55: How do I write modules/files?

Organize code into packages/files and load with ASDF systems.

Q56: What is ASDF?

Build/load system for Common Lisp projects.

Q57: What is Quicklisp?

Package manager/distribution for Common Lisp libraries.

Q58: What are multiple return values?

A function can return several values, not just one.

Example:

(floor 7 3) ; => 2, 1

Q59: How do I capture multiple values?

Use multiple-value-bind.

Example:

(multiple-value-bind (q r) (floor 7 3)
  (list q r)) ; => (2 1)

Q60: What is values?

Explicitly returns multiple values.

Q61: What is destructuring?

Binding parts of structured data (lists) to variables.

Q62: Example of destructuring in args?

Example:

(defun sum-pair ((a b)) (+ a b)) ; implementation-dependent style

(Usually use destructuring-bind explicitly.)

Q63: What is destructuring-bind?

Binds variables to list structure.

Example:

(destructuring-bind (a b &optional c) '(1 2 3)
  (+ a b c))

Q64: What are optional arguments?

&optional parameters may be omitted.

Q65: What are rest arguments?

&rest gathers remaining args into a list.

Q66: What are keyword arguments?

&key named args like :verbose t.

Q67: What is &aux?

Declares local auxiliary variables in parameter list.

Q68: What is mapcar?

Applies function to each list element, returns list.

Example:

(mapcar #'1+ '(1 2 3)) ; => (2 3 4)

Q69: Difference: mapcar vs dolist?

mapcar builds result list; dolist is usually for side effects.

Q70: What is reduce?

Combines sequence elements with binary function.

Example:

(reduce #'+ '(1 2 3 4)) ; => 10

Q71: What is remove-if?

Returns sequence removing elements matching predicate.

Q72: What is find-if?

Returns first element satisfying predicate.

Q73: What is sort?

Destructively sorts sequence.

Example:

(sort (copy-list '(3 1 2)) #'<) ; => (1 2 3)

Q74: Why copy before sort?

sort may mutate original sequence.

Q75: What is hash table?

Key-value structure with fast average lookup.

Q76: How to create hash table?

Example:

(defparameter *h* (make-hash-table :test 'equal))
(setf (gethash "name" *h*) "Lisp")

Q77: What does gethash return?

Value and a boolean for presence.

Q78: What are arrays/vectors?

Indexed sequences; vectors are 1D arrays.

Q79: How to make vector?

Example:

(make-array 3 :initial-contents '(10 20 30))

Q80: What is adjustable array?

Array that can change size with adjust-array.

Q81: What are fill pointers?

Logical length for vectors supporting efficient append-like behavior.

Q82: What is a structure (defstruct)?

Lightweight user-defined record type.

Q83: Example defstruct?

Example:

(defstruct person name age)
(make-person :name "Ana" :age 30)

Q84: What is CLOS?

Common Lisp Object System: classes, generic functions, methods, multimethod dispatch.

Q85: Class vs structure?

Classes are more dynamic/extensible; structures are lightweight/faster for simple records.

Q86: What is defclass?

Defines a class.

Q87: What is defmethod?

Defines method on generic function based on parameter specializers.

Q88: What is multimethod dispatch?

Method selection based on types of multiple arguments.

Q89: What is method combination?

Combining :before, primary, :after, :around methods.

Q90: What is slot-value?

Accesses object slot dynamically (less encapsulated than accessors).

Q91: What are accessors?

Functions generated for slot read/write access.

Q92: What are conditions in Lisp?

Lisp error/signaling system with restarts and handlers.

Q93: Difference exception vs condition system?

Lisp allows recovery strategies (restarts), not only unwind-and-abort.

Q94: What is handler-case?

Handles signaled conditions similarly to try/catch.

Q95: What is ignore-errors?

Catches errors and returns nil + condition.

Q96: What is a restart?

Named recovery action that can continue execution from error context.

Q97: What is unwind-protect?

Ensures cleanup code runs even on non-local exits.

Q98: What are declarations?

Hints to compiler (types, optimization qualities).

Q99: What is proclaim~/~declaim?

Global declarations affecting compilation/runtime behavior.

Q100: How to optimize performance?

Add type declarations, reduce consing, profile, and tune algorithms/data structures.

Advanced

Q101: What is a macro?

A compile-time code transformer from input forms to output forms.

Q102: Why use macros?

Create new syntactic abstractions and eliminate boilerplate elegantly.

Q103: Macro vs function?

Functions evaluate arguments first; macros receive raw forms.

Q104: How to define macro?

Example:

(defmacro when-not (test &body body)
  `(if (not ,test) (progn ,@body)))

Q105: What is backquote (`)?

Template syntax for building lists with selective evaluation.

Q106: What do comma (,) and comma-at (,@) do?

, insrts value; ,@ splices list elements.

Q107: What is macro expansion?

Resultig code after macro transforms input.

Exampl: #+beginsrc lisp (macroepand-1 '(when-not x (print "hi"))) #+endsc

Q108: What is macro hygiene?

Avoidin accidental variable capture/name collisions in macro-generated code.

Q109: How avoid variable capture?

Use gesym for unique temporary symbols.

Q110: What is symbol capture?

Macro-itroduced symbol accidentally binds/conflicts with user symbol.

Q111: What are compiler macros?

Optiona source transformations for function calls to optimize compiled code.

Q112: What is reader macro?

Extendsread syntax (at read-time), e.g., quote shorthand.

Q113: Why are reader macros powerful/dangerous?

Can impove DSL syntax but reduce readability/tool compatibility.

Q114: What is eval?

Evaluats Lisp form at runtime in dynamic environment contexts.

Q115: Why avoid excessive eval?

Harder easoning, security/performance/debugging costs.

Q116: What is closure?

Functio capturing lexical variables from defining environment.

Exampl: #+beginsrc lisp (defun ake-counter () (let (n 0)) (labda () (incf n)))) #+endsc

Q117: What is lexical environment?

Binding visible where function/macro is defined.

Q118: What is dynamic environment?

Runtimecontext for special variables, handlers, restarts.

Q119: What is continuation (conceptually)?

“Rest o computation” from a point; explicit first-class continuations are not standard CL.

Q120: What is non-local exit?

Controltransfer out of current context (throw, return-from, errors).

Q121: What are catch and throw?

Tagged on-local control transfer constructs.

Q122: What is block/return-from?

Named lxical exit points.

Q123: What is tagbody/go?

Low-levl goto-like flow constructs.

Q124: What is MOP?

Metaobjct Protocol for customizing CLOS behavior (implementation-dependent).

Q125: What is method dispatch cost?

Runtimeoverhead of selecting applicable method(s); often acceptable, sometimes optimizable.

Q126: What is generic function redefinition impact?

Can updte behavior interactively in running image.

Q127: What is image-based development?

Long-lived Lisp process where definitions are incrementally reloaded.

Q128: What are fasl files?

Compiled Lisp binary artifacts loaded faster than source.

Q129: compile-file vs load?

compil-file produces fasl; load loads source or fasl.

Q130: What is separate compilation?

Compilig modules independently with clear package interfaces.

Q131: What is foreign function interface (FFI)?

Mechanim to call C/native libraries from Lisp.

Q132: Common FFI caveats?

Memory wnership, ABI compatibility, struct layout, threading boundaries.

Q133: What is bignum support?

Arbitrry-precision integers built into Common Lisp numeric tower.

Q134: What is numeric tower?

Hierarhy: integers, rationals, reals, complex numbers.

Q135: Why are ratios useful?

Exact ational arithmetic avoids floating-point rounding where possible.

Q136: How does coercion work?

Use cerce or numeric contagion rules in operations.

Q137: What are readtables?

Readersyntax configuration tables.

Q138: What is pretty printing?

Structred formatted output via printer control and pprint facilities.

Q139: What is introspection in Lisp?

Queryig runtime metadata: function definitions, classes, packages, etc.

Q140: What is reflection?

Inspecing/modifying program structure/behavior at runtime.

Q141: What is disassemble?

Inspec compiled machine code for functions (implementation-dependent detail).

Q142: What is profiling?

Measurng time/allocation hot spots for optimization.

Q143: What is allocation pressure (consing)?

Frequet temporary object creation causing GC overhead.

Q144: How reduce consing?

Reuse tructures, destructive ops carefully, better algorithms, declarations.

Q145: What is garbage collection tuning?

Adjustimplementation-specific GC parameters for workload.

Q146: What is weak hash table?

Entrie can disappear when keys/values are no longer strongly referenced.

Q147: What is memoization idiom?

Cache unction results (often hash table keyed by args).

Q148: What is DSL in Lisp?

Domainspecific language built naturally with macros and reader extensions.

Q149: What is staging (compile-time/runtime split)?

Decidig what computations happen during macro expansion vs runtime.

Q150: What is “Lisp style”?

Data-driven design, small composable functions, macros for abstractions, interactive development.

Expert

Q151: How do I design robust macros for large systems?

Keep mcro surface minimal, expand into simple primitives, document expansion contracts, and test macroexpansions.

Q152: When should I not use a macro?

If a fnction (or higher-order function) is enough; prefer simpler runtime abstractions first.

Q153: How do I version macro APIs safely?

Presere old expansion behavior when possible; provide compatibility layers and deprecation phases.

Q154: What is phase separation risk in macros?

Confusng compile-time and runtime dependencies can break builds/load order.

Q155: How to manage compile-time side effects?

Avoid nless necessary; isolate with eval-when and clear module boundaries.

Q156: What is eval-when for?

Contros when forms are evaluated: compile-toplevel, load-toplevel, execute.

Q157: How can declarations backfire?

Incorrct type/safety claims may cause undefined behavior or hard-to-debug bugs.

Q158: What optimization policy is common?

Duringdevelopment: high debug/safety; production hotspots: higher speed with validated assumptions.

Q159: How do I benchmark Lisp correctly?

Warm u, avoid measuring compilation, isolate GC effects, run multiple trials, report variance.

Q160: How to reason about GC pauses?

Track llocation rate, object lifetimes, heap sizing, and generation behavior of implementation.

Q161: How do I design stable package APIs?

Exportminimal symbols, keep internals private, provide clear compatibility guarantees.

Q162: How do I avoid package conflicts in ecosystems?

Use exlicit imports, qualified symbols, and avoid overly generic exported names.

Q163: What is protocol-oriented design in CLOS?

Definegeneric operations and behavioral contracts rather than rigid class trees.

Q164: CLOS vs algebraic data types (tradeoff)?

CLOS ecels in open extension; ADTs excel in closed exhaustive pattern handling.

Q165: How to structure large Common Lisp systems?

Layere ASDF systems, strict package boundaries, integration tests, and development image scripts.

Q166: How to reload code safely in live systems?

Minimie global mutable state, version migrations for object slots, and controlled restart workflows.

Q167: What are class redefinition pitfalls?

Existig instances require updates; slot changes may need migration logic.

Q168: How to implement plugin architectures?

Use geeric functions, registries, packages, and capability-based protocols.

Q169: How to build debuggable DSLs?

Presere source locations where possible, keep expansions readable, provide macroexpand tooling.

Q170: Reader macros in production: yes or no?

Use springly; prefer plain macros unless syntax gain clearly outweighs tooling/readability costs.

Q171: How to integrate Lisp with polyglot systems?

Defineclear service boundaries (RPC/HTTP/message bus), stable schemas, and observability hooks.

Q172: How do restarts improve resilience?

They eable interactive or programmatic recovery strategies without full failure teardown.

Q173: How to design condition hierarchies?

Createspecific condition types for actionable handling; avoid overly generic error signaling.

Q174: How to audit for undefined behavior risks?

Reviewdeclarations, type assumptions, destructive updates, and implementation-specific dependencies.

Q175: Portability across CL implementations?

Stick o ANSI CL + portability libs; isolate implementation-specific code paths.

Q176: What is the role of test strategy in macro-heavy codebases?

Test a three levels: expansion shape, runtime behavior, and integration semantics.

Q177: How to document metaprogramming-heavy systems?

Documet both user-facing forms and generated runtime contracts/invariants.

Q178: What is a good performance workflow for expert Lisp?

Profil first, optimize hottest 5%, verify with benchmarks, re-check correctness invariants.

Q179: What distinguishes expert Lisp developers?

Strongmacro discipline, runtime insight, architectural clarity, and pragmatic simplicity.

Q180: Final mastery advice?

Build real systems, read great Lisp code, inspect expansions, and iterate interactively with rigor.