..
9.0
top
← prev up next →

Function Composition SyntaxπŸ”— i

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

1API ReferenceπŸ”— i

syntax

( compose-app func-exprdotted-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.

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

16

> (define ((mappedf)vs)(map fvs))
> ((rest.. (mappedstring->symbol ).. string-split)"foo bar baz")

'(bar baz)

> ((rest.. mappedstring->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.

syntax

..

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.

2Integration with fancy-appπŸ”— i

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

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

'(10 100)

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /