Auto Rename Transformers
(requireauto-rename) | package:auto-rename |
A package for programmatic require and provide filters and renamings.
(module fancy-lib racket (provide (all-defined-out)) (struct fancy (x y z) #:transparent))
> (require (transform-in 'fancy-lib #:transform (transform/replace "fancy" "not-so-fancy"))) > (not-so-fancy 1 2 3) (fancy 1 2 3)
> struct:not-so-fancy #<struct-type:fancy>
syntax
(auto-rename-in require-spec ...+ #:transform transform ...)
syntax
(auto-rename-out provide-spec ...+ #:transform transform ...)
syntax
(auto-rename-in/out spec ...+ #:transform transform ...)
transform : filter/c
syntax
(transform-in require-spec ...+ #:transform transforms ...)
syntax
(transform-out provide-spec ...+ #:transform transforms ...)
syntax
(transform-in/out spec ...+ #:transform transforms ...)
1 Transformers
(requireauto-rename/filters) | package:auto-rename |
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)
syntax
(transform/when x accept?-expr)
procedure
(transform/remove reject?) → filter/c
reject? : (-> string? any/c)
syntax
(transform/unless x reject?-expr)
procedure
(transform/map renamer) → filter/c
renamer : (-> string? string?)
syntax
(transform/for x name-expr)
procedure
(transform/append-map renamer) → filter/c
renamer : (-> string? (sequence/c string?))
syntax
(transform/for* x names-expr)
procedure
(transform/matches pattern) → filter/c
pattern : (or/c string? regexp?)
procedure
(transform/replace pattern replacement) → filter/c
pattern : (or/c string? regexp?) replacement : (or/c string? (string? string? ... . -> . string?))
Equivalent to (transform/forname(regexp-replace*patternnamereplacement)).
2 Miscellaneous Definitions
value
=
(-> (reducing-function/c im/export/c A) (reducing-function/c im/export/c A))
procedure
(reducing-function/c input/c accumulator/c) → contract?
input/c : contract? accumulator/c : contract?
=
(case-> (input/c accumulator/c . -> . accumulator/c) (accumulator/c . -> . accumulator/c))
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/cin/cacc/c) is a contract for a procedure rf suitable for the expression (rf(foldlrfaccins)), where acc and ins conform to acc/c and (listofin/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.
; A transformer which drops all imports/exports. (define (transform/none rf) (case-lambda [(im/ex acc) acc] [(acc) acc]))
; A transformer which drops imports randomly. (define (transform/drop-randomly rf) (case-lambda [(im/ex acc) (if (zero? (random 2)) acc (rf im/ex acc))] [(acc) acc]))
value
im/export/c : contract? = (or/c import? export?)
procedure
(im/export-name im/ex) → string?
im/ex : im/export/c
procedure
(im/export-map-name im/ex proc) → im/export/c
im/ex : im/export/c proc : (-> string? string?)
procedure
(transform/compose transform ...) → filter/c
transform : filter/c
3 Internationalisation Support
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.1 British and American English
(requireauto-rename/language/british-english) | |
package:auto-rename |
This module provides require/provide transformers for importing and exporting bindings with British English spelling.
> (require auto-rename/language/british-english (for-british racket)) > (normalise-arity 1) 1
> (rationalise 1/4 1/10) 1/3
> (parameterise ([error-print-width 5]) (car (expt 10 1024))) car: contract violation
expected: pair?
given: 10...
> (string-normalise-spaces " foo bar baz \r\n\t") "foo bar baz"
syntax
(for-british spec ...+)
syntax
(for-american spec ...+)
3.2 Other languages
(requireauto-rename/language/polyglot) | |
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.
> (require auto-rename/language/polyglot) > (require (en-français racket racket/generator)) > (se-dresser inconvénients nul (liste 1 2 3)) '(3 2 1)
> (|jeter-un-coup-d'œil-octets| 4 0 (ouvrir-saisir-chaîne "abcd")) #"abcd"
> (exiger (auf-deutsch racket)) > (sogar? (länge (nachteile 0 (nachteile 1 null)))) #t
> (lassen-werte ([(rohr-ein rohr-aus) (machen-rohr)]) (schreiben-saite (saite-oben "efgh\nijkl") rohr-aus) (schließen-ausgabe-hafen rohr-aus) (beginnen0 (hafen->linien rohr-ein) (schließen-eingang-hafen rohr-ein))) '("EFGH" "IJKL")
> (erfordern (magyarul racket racket/generator))
> (meghatároz funkció (ügy-lambda [() (hozam 1) (hozam 2) (hozam 3)] [(x y) (hányados/maradék x y)])) > (funkció 100 7)
14
2
> (definieren |l'ensemble| (veränderlich-satz))
> (für ([w (dans-générateur (dynamique-vent (λ () (kijelző "Be ")) funkció (λ () (anzeige "Aus "))))] [x (in-reichweite 5)] [y (-ben-természetes 3)] [z (dans-faire-du-vélo (dans-valeur 2))]) (satz-hinzufügen! |l'ensemble| (dans-le-monde-ior (arithmetik-schicht w x) (rationalisieren (/ y) (/ z))))) 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 ...+)
This works by splitting each identifier into tokens of (English) alphabet characters, and applying pre-defined translations (if any) to each token individually.