lambda

fn is ok; but we prefer ? or lambda.



Documentation

README

Motivation

fn is ok, but we prefer λ or lambda; for instance:

(def identity
  "Returns its argument."
  (λ [x] x))

or even defλ:

(defλ identity
  "Returns its argument."
  [x] x)

Usage

See Clojars; in Leiningen, add the following to your dependencies in project.clj:

[lambda "1.0.1-SNAPSHOT"]

or in Maven, to your pom.xml:

<dependency>
  <groupId>lambda</groupId>
  <artifactId>lambda</artifactId>
  <version>1.0.1-SNAPSHOT</version>
</dependency>

Typing λ

Enable λ as the result of typing Compose-l-l (or Multikey-l-l) by adding the following to ~/.Xcompose:

<Multi_key> <l> <l> : "λ" U03BB # GREEK SMALL LETTER LAMBDA

Emacs

Add the following to ~/.emacs to make lambda, λ and defλ behave like e.g. fn and defn with respect to highlighting and indentation:

(add-hook
 'clojure-mode-hook
 (lambda ()
   (font-lock-add-keywords
    nil
    `((,(concat "(\\(?:lambda.core/\\)?\\(defλ\\)\\>"
                ;; Any whitespace
                "[ \r\n\t]*"
                ;; Possibly type or metadata
                "\\(?:#?^\\(?:{[^}]*}\\|\\sw+\\)[ \r\n\t]*\\)*"
                "\\(\\sw+\\)?")
       (1 font-lock-keyword-face)
       (2 font-lock-function-name-face nil t))
      (,(concat "(\\(?:lambda.core/\\)?"
                (regexp-opt '("defλ"
                              "λ"
                              "lambda") t)
                "\\>"
                )
       1 font-lock-builtin-face)))))

(put 'defλ 'clojure-doc-string-elt 2)
(put 'defλ 'clojure-indent-function 'defun)
(put'clojure-indent-function 'defun)
(put 'lambda 'clojure-indent-function 'defun)