Reader Function Literal Shorthand
1 Usage Overview
2 Caveats
3 Using the Curly Function Reader
make-curly-fn-readtable
8.12

Reader Function Literal Shorthand🔗ℹ

1 Usage Overview🔗ℹ

 #lang curly-fn package: curly-fn-lib

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 %.

>

 

(#{list 1 % 3} 2)

'(1 2 3)

>

 

(map #{- % 4} (range 9))

'(-4 -3 -2 -1 0 1 2 3 4)

>

 

(#{apply list %&} 'a 'b 'c)

'(a b c)

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.

>

 

(map #{+ 2} (range 10))

'(2 3 4 5 6 7 8 9 10 11)

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-lib

procedure

(make-curly-fn-readtable [#:readtable readtable])  readtable?

  readtable : readtable? = (current-readtable)
Creates a readtable that extends readtable to add support for reading literal function shorthand syntax.

It isn’t possible to add this to an arbitrary readtable and have it produce lambdas, since lambdas cannot be serialized to syntax objects. Instead, this readtable produces #%namespaced datums, which are expected to be bound to #%namespaced from namespaced-transformer.