Re: [racket-users] Best way to handle different versions of Racket?

2020-03-30 Thread Ben Greenman
On 3/30/20, Siddhartha Kasivajhula  wrote:
> Hi there,
> Is there a standard/recommended way to handle multiple versions of Racket
> in library code?

If you're planning to ship the library as a package, you can also:

1. make 2 versions of the library (maybe as two branches in the same git repo)
2. add a version exception on pkgs.racket-lang.org

https://docs.racket-lang.org/pkg/getting-started.html#(part._.Version_.Exceptions)

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAFUu9R5D3o2XJXvscJPjDd5ieGJt2-Qwsq4A4eeFL6VUX3tB4Q%40mail.gmail.com.


Re: [racket-users] Best way to handle different versions of Racket?

2020-03-30 Thread Siddhartha Kasivajhula
Ah right, that makes sense :)


On Mon, Mar 30, 2020 at 12:29 PM Sorawee Porncharoenwase <
sorawee.pw...@gmail.com> 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 <
> skasi...@gmail.com> 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 <
>> sorawee.pw...@gmail.com> 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 <
>>> sorawee.pw...@gmail.com> 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 <
 skasi...@gmail.com> 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   (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 racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/CACQBWFkRahhtoXKUbpcJ%2BHpYwq5FBU85Ze_NGkEntXX3kTD01g%40mail.gmail.com
> 
> .
>


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


Re: [racket-users] Best way to handle different versions of Racket?

2020-03-30 Thread Sorawee Porncharoenwase
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 
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 <
> sorawee.pw...@gmail.com> 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 <
>> sorawee.pw...@gmail.com> 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 <
>>> skasi...@gmail.com> 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>>>   (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 racket-users+unsubscr...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/racket-users/CACQBWFkRahhtoXKUbpcJ%2BHpYwq5FBU85Ze_NGkEntXX3kTD01g%40mail.gmail.com
 
 .

>>>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CADcueguF6iJkHaYSEBprZjwVxNOxRU3RWV6TuGPPAzHniO6M9g%40mail.gmail.com.


Re: [racket-users] Best way to handle different versions of Racket?

2020-03-30 Thread Siddhartha Kasivajhula
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 <
sorawee.pw...@gmail.com> 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 <
> sorawee.pw...@gmail.com> 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 <
>> skasi...@gmail.com> 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>>   (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 racket-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/racket-users/CACQBWFkRahhtoXKUbpcJ%2BHpYwq5FBU85Ze_NGkEntXX3kTD01g%40mail.gmail.com
>>> 
>>> .
>>>
>>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CACQBWFmoT_6rF4Z7poR%3DNVJ5GF2JTec3YCNqdduDi6pMfD%3D5nA%40mail.gmail.com.


Re: [racket-users] Best way to handle different versions of Racket?

2020-03-30 Thread Sorawee Porncharoenwase
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 <
sorawee.pw...@gmail.com> 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 <
> skasi...@gmail.com> 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>   (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 racket-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/racket-users/CACQBWFkRahhtoXKUbpcJ%2BHpYwq5FBU85Ze_NGkEntXX3kTD01g%40mail.gmail.com
>> 
>> .
>>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CADcuegsPsYRE7JZa6vrAoV2fHKPLM9O9-8ghhTiR5TexyHeRSA%40mail.gmail.com.


Re: [racket-users] Best way to handle different versions of Racket?

2020-03-30 Thread Sorawee Porncharoenwase
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 
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   (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 racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/CACQBWFkRahhtoXKUbpcJ%2BHpYwq5FBU85Ze_NGkEntXX3kTD01g%40mail.gmail.com
> 
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CADcuegu%2BKY5UNeOXY1WrmVDb1N715ncP49ASOY1SdZPCznKxsw%40mail.gmail.com.


[racket-users] Best way to handle different versions of Racket?

2020-03-30 Thread Siddhartha Kasivajhula
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 (versionimmutable-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 racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CACQBWFkRahhtoXKUbpcJ%2BHpYwq5FBU85Ze_NGkEntXX3kTD01g%40mail.gmail.com.