ƒ is reader syntax that expands to an anonymous fn expression.
Syntax
ƒ⟨param-char⟩*.⟨expr⟩
;; ⟨param-char⟩ := ⟨alphabetic-char⟩ | _
Semantics
- The characters between
ƒ(U+0192, Latin Small Letter F with Hook) and.specify the positional parameters of the generatedfn:- Each alphabetic character (
cl:alpha-char-p) becomes a single-character parameter variable interned in the current package (respecting the current readtable case). - Duplicate alphabetic parameter characters (after readtable case conversion) signal a reader error.
- Each
_character becomes a wildcard parameter_and may appear multiple times. - When no characters appear between
ƒand.(ƒ.⟨expr⟩), the result is a nullary function(fn () ⟨expr⟩).
- Each alphabetic character (
- The body of the function is the single expression
⟨expr⟩immediately following., which may itself be anotherƒform:ƒx.xexpands to(fn (x) x).ƒ.xexpands to(fn () x).ƒxy.(+ x y)expands to(fn (x y) (+ x y)).ƒx.ƒy.(+ x y)expands to(fn (x) (fn (y) (+ x y))).ƒ_x_.xexpands to(fn (_ x _) x).
ƒdoes not support multi-character parameter names, constructor destructuring patterns, or&keyparameters; usefnfor those.
Examples
;; Unary short lambda
(coalton (map ƒx.(+ x 2) (the (List Integer) [1 2 3])))
; => (3 4 5)
;; Binary short lambda in a fold
(coalton (fold ƒab.(+ (* a 10) b) 0 (the (List Integer) [1 2 3 4])))
; => 1234
;; Ignoring arguments with `_`
(coalton (fold ƒn_.(+ n 1) 0 (the (List String) ["a" "b" "c"])))
; => 3
Other notes
ƒis available whenever thecoalton:coaltonreadtable is active, including inside.ctfiles and inside(coalton ...)/(coalton-toplevel ...)forms.- In the
mineeditor,ƒcan be entered by typingCtrl+\ fn. In Emacs, it can be entered withC-x 8 RET 0192 RET.