Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Zero to Common Lisp

Sean Bryant
December 05, 2011

Zero to Common Lisp

How common lisp projects are put together.

Sean Bryant

December 05, 2011
Tweet

More Decks by Sean Bryant

Other Decks in Programming

Transcript

  1. About Me. •Programmer at Vitrue. •One of the resident “lisp

    dudes” •A new lisper •First lisp presentation
  2. Going to Talk About: Files, Images and Packages CLOS -

    Just the basics. Asdf & Quicklisp.
  3. Going to Talk About: Files, Images and Packages CLOS -

    Just the basics. Asdf & Quicklisp. Quickproject
  4. Files Lisp doesn’t care about your files. Maybe it cares

    a little. ASDF cares. More on that later.
  5. Packages Mapping of symbols *package* - Current package. Symbol Import/

    Export interface No global package Common-Lisp-User Supports Inheritance Using a package Importing Shadowing
  6. Images Dump/load frozen state Distribute a “native” app. Always working

    with one Similar to Smalltalk FFI is a pain the ass.
  7. CLOS Common Lisp Object System Objects do not have methods

    Instead Lisp has generic functions The worst introduction ever.
  8. CLOS Common Lisp Object System Objects do not have methods

    Instead Lisp has generic functions defgeneric The worst introduction ever.
  9. CLOS Common Lisp Object System Objects do not have methods

    Instead Lisp has generic functions defgeneric declares options and arguments for methods The worst introduction ever.
  10. CLOS Common Lisp Object System Objects do not have methods

    Instead Lisp has generic functions defgeneric declares options and arguments for methods defmethod The worst introduction ever.
  11. (defclass my-class () ((my-slot :initform t :accessor my-slot :documentation “A

    simple slot.”)) (:documentation “A simple class”))
  12. defmethod specializes generic function based on type of object not

    restricted a single type multi-methods eql specializers, specialize to particular instances of objects.
  13. defmethod specializes generic function based on type of object not

    restricted a single type multi-methods eql specializers, specialize to particular instances of objects. combinators :before, :around, :after allow for hooking into method calls.
  14. (defmethod initialize-instance :after ((o my-class) &key) ...) Custom constructor (defmethod

    slot->nil ((o my-class)) (setf (my-slot o) nil)) A simple method. method combinator
  15. ASDF Another System Definition Facility Organize your code, through files...

    Understanding the object model is key. Almost a standard*
  16. ASDF Another System Definition Facility Organize your code, through files...

    Understanding the object model is key. Components Almost a standard*
  17. ASDF Another System Definition Facility Organize your code, through files...

    Understanding the object model is key. Components Operations Almost a standard*
  18. ASDF Another System Definition Facility Organize your code, through files...

    Understanding the object model is key. Components Operations Extensible Almost a standard*
  19. (defsystem #:clcss :name "clcss" :version "0.0.0" :depends-on (:cl-ppcre) :in-order-to ((test-op

    (load-op clcss-tests))) :components ((:module "src" :components ((:file "package") (:file "clcss" :depends-on ("package")))))) (defmethod perform ((o asdf:test-op) (c (eql (asdf:find-system :clcss)))) (funcall (intern (symbol-name :run-all) :clcss-tests))) Example ASD
  20. defsystem form Usual meta-data :author :description :version :maintainer :perform -

    stub out custom functionality Components root of all other components.
  21. defsystem form Usual meta-data :author :description :version :maintainer :perform -

    stub out custom functionality Components root of all other components. :serial :depends-on :in-order to
  22. defsystem form Usual meta-data :author :description :version :maintainer :perform -

    stub out custom functionality Components root of all other components. :serial :depends-on :in-order to Grammar is short, easy to reference.
  23. Components Modules - Directories. Files Defaults to cl-source-file Static files

    - README, ChangeLog etc. Systems* *Systems are actually special modules
  24. Perform (defgeneric perform (operation component)) Now all together! Because it’s

    CLOS we can change it. Test operations are the most common.
  25. (defsystem #:clcss :name "clcss" :version "0.0.0" :depends-on (:cl-ppcre) :in-order-to ((test-op

    (load-op clcss-tests))) :components ((:module "src" :components ((:file "package") (:file "clcss" :depends-on ("package")))))) (defmethod perform ((o asdf:test-op) (c (eql (asdf:find-system :clcss)))) (funcall (intern (symbol-name :run-all) :clcss-tests)))
  26. Most likely you don’t. Shove configuration files in: ~/.config/common-lisp/source-registry.conf.d/ Or

    set CL_SOURCE_REGISTRY Files end in .conf by convention Examples directives (:directory “/path/to/source/”) (:tree “/path/to/tree/of/sources/”)
  27. Quicklisp It’s your gem, pip, lenin, cabal... Speaks ASDF ASDF

    + Quicklisp == Bundler-ish ASDF + Quicklisp == pip + requirements.txt
  28. Quickproject From the guy who brought you quicklisp Bare-bones project

    skeleton. Great starting point. https:/ /github.com/xach/quickproject