https://www.cliki.net/naming+conventions CLiki - Naming conventions Naming conventions Some symbol naming conventions, distilled from CLHS, the Lisp FAQ, and comp.lang.lisp. Widely used "need-to-know" conventions: foo-bar "-" is used as a word delimiter *foo* (global) special variable foo* slightly different variant of the foo operator &foo lambda list keyword. These symbols will be in the lambda-list-keywords list. nfoo (possibly) destructive (non-consing) function foop predicate (also foo-p); see notes below for when to hyphenate foof place changing (like in SETF, INCF, ...) (also foo-f) +foo+ constant, or single CLOS instance %foo low-level, fast, dangerous function, or Lisp system specific implementation of foo make-foo create a foo and return it define-foo (globally) define a new foo (also short version: "deffoo") with-foo create a dynamic context with a foo do-foo iterate through a foo foo-case foo-specific case expression foo-bar type-slot, converting FOO to BAR foo-to-bar converting FOO to BAR Often seen, but not-quite-so-common conventions: bar-of slot bar of an object foo/bar type/operation, foo with bar, bar version of foo foo.bar type.slot or, in some implementations conventional hierarchical package (e.g. ACL and CMUCL) ?foo variable in embedded language class %foo% local special variable .foo. internal special variable .foo. private macro symbol /foo/ global lexical variable $foo function visible from Macsyma foo& foo, operating on fixnums foo$ foo, operating on floats Conventions in Scheme: foo! destructive function foo? predicate $foo constant call-with-foo Invoke a thunk in some dynamic context foo->bar Coerce object of type foo to object of type bar This is standard syntax, not convention: :bar keyword foo:bar external symbol bar in package foo foo::bar internal symbol bar in package foo (don't try this at home, kids!) #:bar uninterned symbol (does not belong to any package) These will annoy people: CamelCaseIdentifiers Use identifiers-like-this identifiers_with_underscores are harder to type hungarian-identifiers-pcsnsi abbrv-idntfrs Use Emacs to expand them. Unless there is a good reason to use them (for instance, you need to interface to a third-party package that uses them), they should be avoided. Some additional style notes: * A function that tests for something involving its arguments is called a predicate and usually ends in p or -p. CLTL2 explains the rationale for each suffix: By convention, the names of predicates usually end in the letter p (which stands for "predicate"). Common Lisp uses a uniform convention in hyphenating names of predicates. If the name of the predicate is formed by adding a p to an existing name, such as the name of a data type, a hyphen is placed before the final p if and only if there is a hyphen in the existing name. For example, number begets numberp but standard-char begets standard-char-p. On the other hand, if the name of a predicate is formed by adding a prefixing qualifier to the front of an existing predicate name, the two names are joined with a hyphen and the presence or absence of a hyphen before the final p is not changed. For example, the predicate string-lessp has no hyphen before the p because it is the string version of lessp (a MACLISP function that has been renamed < in Common Lisp). The name string-less-p would incorrectly imply that it is a predicate that tests for a kind of object called a string-less, and the name stringlessp would connote a predicate that tests whether something has no strings (is "stringless")! * There are useful conventions for macros: deffoo or define-foo defines objects of type foo. Setting up a context for some actions, usually performing some binding, and including setup and teardown code, is usually a with-foo. Iterating macros are defined usually as do-foo. * deffoo vs. define-foo used to be, and is in the spec, determined by foo. If foo is a hyphenated name, then the define-foo format is used, otherwise deffoo is used. For example, defmethod and defsetf vs. define-method-combination and define-setf-expander. * Occasionally, there will be a pair of operator functions, and one is a destructive version of the other. Historical tradition will name the destructive variant nfoo for the basic non-destructive function, but this is inconsistently used. * The CLIM specification supports a rather large protocol, and has a "spread arguments" convention for functions where there is a desire not to have to construct a large object just to call one function with it. A spread function takes many small constituent arguments and is named foo* for a basic function foo. * There are some various methods ending in f, notably setf (but some advanced ones include locf for old ZetaLisp). The f stands for a generic field of an object, like a part of a cons cell, structure, vector, array, class instance, and so forth. Kent M. Pitman explained the origin of it on comp.lang.lisp. * Note that nested conversions (e.g., (bar-to-baz (foo-to-bar x)) or (bar->baz (foo->bar x))) compose nicer if written the other way around: (baz-from-bar (bar-from-foo x)), (baz<-bar (bar<-foo x)). * Current version * History * Backlinks * Edit * Create * Home * Recent Changes * About * Text Formatting * Tools Search CLiki [ ] [search] CLiki the common lisp wiki Account name [ ] Password [ ] [login] register [reset password]