9.0
top
← prev up next →

Auto Rename TransformersπŸ”— i

eutro

A package for programmatic require and provide filters and renamings.

Example:
(module fancy-libracket
(struct fancy(xyz)#:transparent))
'fancy-lib
#:transform(transform/replace "fancy""not-so-fancy")))
> (not-so-fancy123)

(fancy 1 2 3)

> struct:not-so-fancy

#<struct-type:fancy>

syntax

( auto-rename-in require-spec...+#:transformtransform...)

syntax

( auto-rename-out provide-spec...+#:transformtransform...)

syntax

( auto-rename-in/out spec...+#:transformtransform...)

transform : filter/c
Require and provide transformers which apply the given transforms to all the imports and exports from the specs.

syntax

( transform-in require-spec...+#:transformtransforms...)

syntax

( transform-out provide-spec...+#:transformtransforms...)

syntax

( transform-in/out spec...+#:transformtransforms...)

Aliases for auto-rename-in , auto-rename-out and auto-rename-in/out .

1TransformersπŸ”— i

These bindings are provided by both auto-rename and auto-rename/filters. auto-rename additionally provides these bindings with tx/ replacing transformer/.

procedure

( transform/filter accept?)filter/c

accept?:(-> string? any/c )
Include only imports/exports for which accept? produces a true value.

syntax

( transform/when xaccept?-expr)

Equivalent to (transform/filter (λ (x)accept?-expr)).

procedure

( transform/remove reject?)filter/c

reject?:(-> string? any/c )
Exclude any imports/exports for which reject? produces a true value.

syntax

( transform/unless xreject?-expr)

Equivalent to (transform/remove (λ (x)reject?-expr)).

procedure

( transform/map renamer)filter/c

renamer:(-> string? string? )
Change the name of any imports/exports to the result of applying renamer to the original name.

syntax

( transform/for xname-expr)

Equivalent to (transform/map (λ (x)name-expr)).

procedure

( transform/append-map renamer)filter/c

Change the name of any imports/exports to the results of applying renamer to the original name. That is, the binding is imported/exported under every name that renamer returns, or no names at all if the returned sequence is empty.

syntax

( transform/for* xnames-expr)

Equivalent to (transform/append-map (λ (x)names-expr)).

procedure

( transform/matches pattern)filter/c

pattern:(or/c string? regexp? )
Include only imports/exports whose name matches pattern. Equivalent to (transform/when name(regexp-match? patternname)).

procedure

( transform/replace patternreplacement)filter/c

pattern:(or/c string? regexp? )
replacement:(or/c string? (string? string? ... . -> .string? ))
Replace all occurrences of pattern in import/export names with replacement, as if by regexp-replace* .

Equivalent to (transform/for name(regexp-replace* patternnamereplacement)).

2Miscellaneous DefinitionsπŸ”— i

procedure

( reducing-function/c input/caccumulator/c)contract?

input/c:contract?
accumulator/c:contract?
=
(input/caccumulator/c. -> .accumulator/c)
(accumulator/c. -> .accumulator/c))
A filter is a composable function which transforms streams of imports/exports. auto-rename uses filters to modify the sequence of imports/exports that auto-rename-in/out produce. Typically one would use the transform/xyz functions available in auto-rename/filters to construct these, rather than writing them by hand.

A reducing function is a type of procedure which accumulates inputs into an accumulator. auto-rename uses reducing functions to transform a sequence of imports/exports into the list of imports/exports produced by auto-rename-in/out . Typically, one does not see reducing functions unless they are writing a filter by hand.

Specifically (reducing-function/c in/cacc/c) is a contract for a procedure rf suitable for the expression (rf(foldl rfaccins)), where acc and ins conform to acc/c and (listof in/c) respectively, and a filter is a function which maps an import/export reducing function to a new import/export reducing function, which may rename, remove, duplicate, or otherwise modify the stream of imports/exports that the original reducing function receives, but may not observe or modify the accumulator.

Some illustrative, but not terribly useful, examples:
;A transformer which drops all imports/exports.
(define (transform/nonerf)
[(im/exacc)acc]
[(acc)acc]))
;A transformer which drops imports randomly.
(define (transform/drop-randomlyrf)
[(im/exacc)
(if (zero? (random 2))
acc
(rfim/exacc))]
[(acc)acc]))

A import or an export.

procedure

( im/export-name im/ex)string?

im/ex:im/export/c
Get the name of an import/export.

procedure

( im/export-map-name im/exproc)im/export/c

im/ex:im/export/c
proc:(-> string? string? )
Return a copy of im/ex with its name transformed by proc.

procedure

( transform/compose transform...)filter/c

transform:filter/c
Compose the given transforms. The effects of the transformations are performed left to right.

3Internationalisation SupportπŸ”— i

Bindings detailed in this section are experimental, and may not be up to the same quality as those exported by auto-rename. I make no backwards-compatibility guarantees.

3.1British and American EnglishπŸ”— i

package: auto-rename

This module provides require/provide transformers for importing and exporting bindings with British English spelling.

Examples:
> (require auto-rename/language/british-english
(for-british racket))

1

> (rationalise 1/41/10)

1/3

(car (expt 101024)))

car: contract violation

expected: pair?

given: 10...

> (string-normalise-spaces "foo barbaz \r\n\t")

"foo bar baz"

syntax

( for-british spec...+)

A require and provide transformer which renames identifiers using American English spellings to use British English spellings instead.

syntax

( for-american spec...+)

A require and provide transformer which renames identifiers using British English spellings to use American English spellings instead.

3.2Other languagesπŸ”— i

package: auto-rename

This module provides require/provide transformers for importing and exporting bindings in languages like French, German and Hungarian. Due to the automated and word-based nature of these translations they may not be very good, but they are predictable. Sometimes.

Examples:
> (require auto-rename/language/polyglot)
> (require (en-français racketracket/generator))

'(3 2 1)

#"abcd"

> (exiger (auf-deutsch racket))

#t

> (lassen-werte ([(rohr-einrohr-aus)(machen-rohr )])
(schreiben-saite (saite-oben "efgh\nijkl")rohr-aus)
(hafen->linien rohr-ein)

'("EFGH" "IJKL")

> (erfordern (magyarul racketracket/generator))
> (meghatároz funkció
[()(hozam 1)(hozam 2)(hozam 3)]
[(xy)(hányados/maradék xy)]))
> (funkció1007)

14

2

> (definieren |l'ensemble|(veränderlich-satz ))

Be Aus Be Aus Be Aus Be Aus

> |l'ensemble|

(mutable-set 1 12 4)

syntax

( en-français spec...+)

syntax

( auf-deutsch spec...+)

syntax

( magyarul spec...+)

Require and provide transformers which renames identifiers to be in the corresponding language.

This works by splitting each identifier into tokens of (English) alphabet characters, and applying pre-defined translations (if any) to each token individually.

top
← prev up next →

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