Hasty Briefsbeta

Bilingual

They Called It LISP For A Reason (2005)

9 hours ago
  • #Lisp
  • #Functional Programming
  • #Data Structures
  • Lists in Lisp are historically significant as the original composite data type, though modern Common Lisp uses various data structures.
  • Lists remain valuable for representing heterogeneous or hierarchical data, supporting functional programming and macros.
  • Lists are an illusion built on cons cells (created by CONS), which store pairs of values accessed via CAR and CDR.
  • Lists are formed by linking cons cells through their CDRs, with the last CDR being NIL, and can be printed as parenthesized lists.
  • Common functions like LIST, FIRST, and REST abstract cons cell manipulation, allowing lists to hold diverse element types.
  • Functional programming emphasizes side-effect-free functions; many list functions (e.g., REVERSE) return results sharing cons cells with arguments.
  • Destructive operations include for-side-effect (e.g., SETF) and recycling functions (e.g., NREVERSE), which reuse cons cells but require caution.
  • Idiomatic uses of recycling functions include PUSH/NREVERSE for building lists and SETF/DELETE for modifying lists in place.
  • Shared structure and recycling functions can conflict, so functional style is recommended, with optimization via recycling only when safe.
  • List-manipulation functions include NTH, NTHCDR, composite CAR/CDR functions, and mapping functions like MAPCAR and MAPLIST.
  • Sorting functions (SORT, STABLE-SORT) are recycling on lists and may destroy arguments, requiring COPY-LIST for nondestructive sorting.