> On May 16, 2018, at 6:37 AM, Jens Axel Søgaard <jensa...@soegaard.net> wrote:
> 
> Alternative 1: Use filtered-in to require renamed versions.
> 
> ( <>filtered-in 
> <http://docs.racket-lang.org/reference/require.html?q=regexp-in#%28form._%28%28lib._racket%2Frequire..rkt%29._filtered-in%29%29>
>  proc-expr require-spec)
> Applies an arbitrary transformation on the import names (as strings) of 
> require-spec. The proc-expr must evaluate at expansion time to a 
> single-argument procedure, which is applied on each of the names from 
> require-spec. For each name, the procedure must return either a string for 
> the import’s new name or #f to exclude the import.
> 
> 
> For example,
> (require 
> <http://docs.racket-lang.org/reference/require.html?q=regexp-in#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29>
>  (filtered-in 
> <http://docs.racket-lang.org/reference/require.html?q=regexp-in#%28form._%28%28lib._racket%2Frequire..rkt%29._filtered-in%29%29>
>           (lambda 
> <http://docs.racket-lang.org/reference/lambda.html?q=regexp-in#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._lambda%29%29>
>  (name)
>             (and 
> <http://docs.racket-lang.org/reference/if.html?q=regexp-in#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._and%29%29>
>  (regexp-match? 
> <http://docs.racket-lang.org/reference/regexp.html?q=regexp-in#%28def._%28%28quote._~23~25kernel%29._regexp-match~3f%29%29>
>  #rx"^[a-z-]+$" name)
>                  (regexp-replace 
> <http://docs.racket-lang.org/reference/regexp.html?q=regexp-in#%28def._%28%28quote._~23~25kernel%29._regexp-replace%29%29>
>  #rx"-" (string-titlecase 
> <http://docs.racket-lang.org/reference/strings.html?q=regexp-in#%28def._%28%28quote._~23~25kernel%29._string-titlecase%29%29>
>  name) "")))
>           racket/base))
> imports only bindings from racket/base 
> <http://docs.racket-lang.org/reference/index.html?q=regexp-in> that match the 
> pattern #rx"^[a-z-]+$", and it converts the names to “camel case.”

> Alternative 1 is best.
> 
> /Jens Axel


Here is a `transform-right-arrow-in` definition that transforms -> into →:

#lang racket
(require racket/require
         racket/require-syntax
         (for-syntax syntax/parse))

(begin-for-syntax
  ;; String -> String
  (define (transform-right-arrow name)
    (regexp-replace* #rx"->" name "→")))

(define-require-syntax transform-right-arrow-in
  (syntax-parser
    [(transform-right-arrow-in require-spec)
     #'(filtered-in transform-right-arrow require-spec)]))

;; Using it:

(require (transform-right-arrow-in racket/base))

(symbol→string 'blubber)
(string→number "987")
(real→double-flonum 377)
(list→vector (list 144 233 377 610 987 1597))



-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to