Ah right, that makes sense :)

On Mon, Mar 30, 2020 at 12:29 PM Sorawee Porncharoenwase <
[email protected]> wrote:

> 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))
>
>
>
> On Mon, Mar 30, 2020 at 12:17 PM Siddhartha Kasivajhula <
> [email protected]> wrote:
>
>> That looks great, thanks! Re: shadowing, I don't plan to re-provide
>> string-append-immutable -- only use it internally within the module, so
>> shadowing should be OK, right?
>> Re: reason to use it - performance. I'm applying the string-append
>> operation in a pairwise way over input sequences, and re-converting to
>> immutable at each step appears to have a measurable cost.
>>
>>
>> On Mon, Mar 30, 2020 at 12:11 PM Sorawee Porncharoenwase <
>> [email protected]> wrote:
>>
>>> 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.
>>>
>>> On Mon, Mar 30, 2020 at 12:00 PM Sorawee Porncharoenwase <
>>> [email protected]> wrote:
>>>
>>>> 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]))
>>>>
>>>>
>>>>
>>>> On Mon, Mar 30, 2020 at 11:49 AM Siddhartha Kasivajhula <
>>>> [email protected]> wrote:
>>>>
>>>>> Hi there,
>>>>> Is there a standard/recommended way to handle multiple versions of
>>>>> Racket in library code?
>>>>>
>>>>> For instance, this handy utility was added in a recent version of
>>>>> Racket:
>>>>>
>>>>>
>>>>> https://docs.racket-lang.org/reference/strings.html?q=strings#%28def._%28%28quote._~23~25kernel%29._string-append-immutable%29%29
>>>>>
>>>>> I'd like to use it in my library code but that would probably mean
>>>>> that users with an older version of Racket wouldn't be able to use the
>>>>> library, is that right? I'm tempted to add something like:
>>>>>
>>>>> (require version/utils)
>>>>> (define string-append
>>>>>   (if (version<? (version) "7.5.0.14")
>>>>>       (compose string->immutable-string string-append)
>>>>>       string-append-immutable))
>>>>>
>>>>> ... at the top of the module. Is this advisable? Or is there a better,
>>>>> maybe more raco-friendly way?
>>>>>
>>>>> Thanks,
>>>>> -Sid
>>>>>
>>>>>
>>>>> --
>>>>> 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 [email protected].
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/racket-users/CACQBWFkRahhtoXKUbpcJ%2BHpYwq5FBU85Ze_NGkEntXX3kTD01g%40mail.gmail.com
>>>>> <https://groups.google.com/d/msgid/racket-users/CACQBWFkRahhtoXKUbpcJ%2BHpYwq5FBU85Ze_NGkEntXX3kTD01g%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CACQBWFmBpVWY%2B9bUo9uPk38n9f4tJvJg9HRKbv8LCkZ3gM%3D1qQ%40mail.gmail.com.

Reply via email to