Function Composition Syntax (original) (raw)

8.15

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 https://github.com/jackfirth/compose-app

1 API Reference🔗ℹ

(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 ofcompose-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-appmodule 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.

The composition produced by compose-app is a single-argument function defined in terms of compose-app-base-lambda, which defaults tolambda 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 tocompose-app-base-app.

A syntax parameter that defines what function application syntaxcompose-app expands to. Defaults to #%app fromracket/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 syntaxcompose-app expands to. Defaults to lambda fromracket/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🔗ℹ

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