Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Anonymous function helpers for Common Lisp
Common Lisp
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
README.markdown Changed fn and fnn interface.
anonfun.lisp
cl-anonfun.asd
package.lisp

README.markdown

cl-anonfun

cl-anonfun is a Common Lisp library that provides a simple anonymous function notation.

Usage

fn

fn form => lambda-form

fn macro returns lambda form of anonymous function form. If special symbols starting with % are found in form, its symbols will be placed to lambda-list of lambda form. Special symbol % represents its first argument. Special symbol formed %<n> represents its n'th argument. Special symbol %& represents its rest of arguments.

Examples

(macroexpand '(fn (* % %)))
; => #'(LAMBDA (%) (* % %))

(funcall (fn (* % %)) 3)
; => 9

(macroexpand '(fn (mapcar %2 %1)))
; => #'(LAMBDA (%1 %2) (MAPCAR %2 %1))

(funcall (fn (mapcar %2 %1)) '(1 2 3) (fn (* % %)))
; => 1 4 9

(macroexpand '(fn (apply #'+ 1 2 3 %&)))
; => #'(LAMBDA (&REST %&) (APPLY #'+ 1 2 3 %&))

(funcall (fn (apply #'+ 1 2 3 %&)) 4 5)
; => 15

fnn

fnn narg form => lambda-form

Like fn except that fnn macro can take the number of arguments of the anonymous function.

Examples

(macroexpand '(fnn 3 (eq %2 1)))
; => #'(LAMBDA (#:IGNORE_1_846 %2 #:IGNORE_3_847)
         (DECLARE (IGNORE #:IGNORE_1_846 #:IGNORE_3_847))
         (EQ %2 1))

(funcall (fnn 3 (eq %2 1)) 3 1 2)
; => T

enable-fn-syntax

enable-fn-syntax

By calling this function, you can use special syntax #%(...) instead of fn macro. Any forms of fn macro can be used. If an integer is suppied after #%, fnn macro will be used with the integer instead of fn.

Examples

(enable-fn-syntax)
(funcall #%(* % %) 3)
; => 9

(funcall #%3(eq %2 1) 3 1 2)
; => T

License

Copyright (C) 2011 Tomohiro Matsuyama <tomo@cx4a.org>. Licensed under the LLGPL License.

Something went wrong with that request. Please try again.