Function Composition Syntax
1 API Reference
2 Integration with fancy-app
compose-app/  fancy-app

Function Composition Syntax

Jack Firth <[email protected]>

This library provides an alternative #%app syntax that interprets double dots as (unary) function composition. The syntax is lightweight and extensible through syntax parameters, allowing alternative base forms of #%app to be substituted. Included with this package is integration with the fancy-app module, to make composition of anonymous functions as painless as possible.

Source code for this library is avaible at

1 API Reference

 (require compose-app) package: compose-app


(compose-app func-expr dotted-func-expr ...)

func-expr = single-expr
  | many-expr ...
dotted-func-expr = .. func-expr
Expands into a function composition of each func-expr, with function application for the expanded composition defined in terms of compose-app-base-app. If a func-expr is a single-expr, the expression is used directly, but in the many-expr case the expression used for that function is (compose-app-group many-expr ...). The compose-app module additionally provides compose-app as #%app. If no uses of .. are found, an expansion to a normal function application (still in terms of compose-app) is used.

> ((add1 .. string->number .. first) '("15" "2" "96"))


> (define ((mapped f) vs) (map f vs))
> ((rest .. (mapped string->symbol) .. string-split) "foo bar baz")

'(bar baz)

> ((rest .. mapped string->symbol .. string-split) "foo bar baz")

'(bar baz)

The composition produced by compose-app is a single-argument function defined in terms of compose-app-base-lambda, which defaults to lambda from racket/base.



A syntactic element used by compose-app. Usage anywhere else is a syntax error.

A syntax parameter that defines how compose-app treats multiple expressions in the same function segment. Defaults to compose-app-base-app.

A syntax parameter that defines what function application syntax compose-app expands to. Defaults to #%app from racket/base. Changing this allows compose-app to be used with other libraries providing modified versions of #%app.

A syntax parameter that defines what anonymous function syntax compose-app expands to. Defaults to lambda from racket/base. This parameter should always be a macro that accepts expressions like lambda does, but it will only ever be used to produce single-argument functions. Changing this allows compose-app with other definitions of anonymous function semantics.

2 Integration with fancy-app

 (require compose-app/fancy-app) package: compose-app

Like compose-app, but with compose-app-base-app set to #%app from fancy-app.

> ((map string->number _ .. rest .. string-split) "1 10 100")

'(10 100)