Reader Function Literal Shorthand
1 Usage Overview
#lang curly-fn | package: curly-fn |
The curly-fn language is a meta-language that extends a language’s readtable to support function literals as reader syntax. This is inspired by Clojure’s shorthand function literals as well as Rackjure’s implementation of them in Racket.
The syntax for shorthand function literals is to simply prepend a # before {}, and the contents will be read as a function literal. Arguments are denoted using identifiers prefixed with %.
% ‹digit›+ is a positional argument.
% on its own is an alias for %1.
%& is a rest argument.
%: ‹id› is a keyword argument.
As a special case, if the shorthand syntax is used, but no arguments prefixed with % are included in the body, then the syntax becomes a shorthand for curry.
2 Caveats
The shorthand is expanded to lambda by inspecting the datums within the function body. This inspection step occurs before subexpressions are expanded. This means that identifiers are inspected as-is at read time, before any macros have a chance to manipulate the syntax. This is probably a good thing, since it reduces the possibility of identifiers being lost or introduced via syntax transformation, but it does mean it isn’t possible to write a macro that expands to % or other identifiers and have those identifiers detected by the curly shorthand.
3 Using the Curly Function Reader
(require curly-fn) | package: curly-fn |
procedure
(make-curly-fn-readtable [#:readtable readtable]) → readtable?
readtable : readtable? = (current-readtable)