Your code would not work because prior 7.5.0.14, there’s no string-append-immutable
, so the use of string-append-immutable
in the else branch will result in an unbound id error.
Instead, use https://docs.racket-lang.org/version-case/index.html which will run the “if” at compile-time, making the "unbound id" go away at compile-time.
Another problem is that when you define string-append
(or even string-append-immutable
), it will shadow Racket’s string-append
(or string-append-immutable
). You might want to do something like this instead:
(define @string-append-immutable ... now you can use string-append-immutable here ...)
(provide (rename-out [@string-append-immutable string-append-immutable]))
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CACQBWFkRahhtoXKUbpcJ%2BHpYwq5FBU85Ze_NGkEntXX3kTD01g%40mail.gmail.com.
Is there any reason to use Racket’s string-append-immutable
though? It might be simpler to just:
(define string-append-immutable
(compose string->immutable-string string-append))
(provide string-append-immutable)
since you need to define it anyway for the versions prior 7.5.0.14.
The problem with shadowing is more than that. Suppose you somehow want to shadow add1 by making it add 2 instead.
(define add1 (compose add1 add1))
However, this will not work, resulting in the following error:
add1: undefined;
cannot reference an identifier before its definition
because blue add1
refers to red add1
, not Racket’s add1
.
So you really need to either rename Racket’s add1
to something else, or define your add1
with another name. The first approach would be something like:
(require (only-in racket [add1 @add1]))
(define add1 (compose @add1 @add1))
and the second approach would be something like:
(define @add1 (compose add1 add1))
Is there a standard/recommended way to handle multiple versions of Racket in library code?
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/1abd44b5-cec8-4c1a-a7d1-e2096f5a839d%40googlegroups.com.