Definer Syntax

angavrilov edited this page Sep 13, 2010 · 1 revision

The hu.dwim.def package implements a def macro that is a generic wrapper for defining macros. The basic use case looks very similar to ordinary definitions:

(def method foo (bar)
  (print bar))

However, the def macro also allows passing meta flags to the definer:

(def (method :export t :inline t) foo (bar)
  (print bar))

which can also be abbreviated as

(def (method ei) foo (bar)
  (print bar))

Standard meta flags

  • :export (e) – export the defined symbol from its package.
  • :export-accessor-name (a) – export accessors of the defined class or structure.
  • :export-slot-names (s) – export the slot names of the defined class.
  • :inline (i) – mark the defined function as inline.
  • :optimize (o) – use high optimize settings for the defined function.
  • :debug (d) – use high debugging settings; overrides optimize.

Definer definition

This defines a new definer macro name:

  • (def definer name (args…) code…)

The definer definer supports the following meta flags:

  • :export (e) – exports the definer name.
  • :available-flags – specifies which standard flag abbreviations are allowed for the new definer.

The expansion code has access to the following lexical variables:

  • -whole- → the definition being expanded.
  • -environment- → the compiler environment.
  • -options- → the meta flag plist.

Standard definers

  • function (ioed)
  • generic (eod)
  • method (eod)
  • methods (eod)
    (accepts multiple method in defgeneric syntax)
  • macro (eod)
  • compiler-macro (eod)
  • symbol-macro (e)
  • type (e)
  • class (eas)
  • condition (eas)
  • structure (eas)
  • constant (e)
  • special-variable (e)

Emacs integration

Syntax highlighting is defined in hu.dwim.def/emacs/hu.dwim.def.el.

Acceptable indentation may be defined as follows:

(put 'def 'common-lisp-indent-function '(4 4 2 2 2 2 2 &body))