Re: [racket-users] What's the best way to do these syntax transforms?

2019-11-08 Thread Philip McGrath
On Fri, Nov 8, 2019 at 5:06 PM Christopher Lemmer Webber <
cweb...@dustycloud.org> wrote:

> Huh... somehow I had thought that I had heard that Racket has mutable
> strings by default.  It cropped up on my TODO list because of that.  I
> wonder what gave me that impression?
>

Racket strings are annoyingly mutable, enough so that there are many
reasonable definitions of "default" for which the statement "Racket has
mutable strings by default" would be true. For example:
> (immutable? (string-append ""))
#f
String literals are an exception to the general rule, though there is some
precedent for that exception: IIRC mutating a string literal in C is
undefined behavior.

This is a bit of a pet peeve of mine:
https://github.com/racket/rhombus-brainstorming/issues/22

-Philip

-- 
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/CAH3z3gYy5akbv6SgR82RcF7Xhu0pJ-T21maT%2BphsSHk_8ghymw%40mail.gmail.com.


Re: [racket-users] What's the best way to do these syntax transforms?

2019-11-08 Thread Philip McGrath
On Fri, Nov 8, 2019 at 2:58 PM Matthew Flatt  wrote:

> More precisely, the reader (via `read-syntax`) creates immutable
> strings.
>
> If a macro constructs a mutable string and converts it to a syntax
> object, the string is not converted to an immutable string. Maybe it
> should be.
>

I see now that this is true, but it isn't what I'd expected. The docs

for `datum->syntax` say that:

> For any kind of value other than a pair, vector, box, immutable hash
> table, immutable prefab structure, or syntax object, conversion means
> wrapping the value with lexical information, source-location information,
> and properties after the value is interned via datum-intern-literal.
>
and `datum-intern-literal` says

that "mutable strings and byte strings are interned as immutable strings
and byte strings," which I just confirmed is true.

Based on this, I'd previously thought that using `datum->syntax` on a
mutable string would convert the string with `datum-intern-literal`, which
would make the wrapped string immutable—but I see now that the wrapped
string is, in fact, still mutable.

-Philip

-- 
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/CAH3z3gb%2Bztz62%2BykWpZNbNQ1gPy70LVWB_%3DMpkLxKApScJiPEQ%40mail.gmail.com.


Re: [racket-users] What's the best way to do these syntax transforms?

2019-11-08 Thread Christopher Lemmer Webber
Jay McCarthy writes:

> On Fri, Nov 8, 2019 at 9:51 AM Christopher Lemmer Webber <
> cweb...@dustycloud.org> wrote:
>
>> I have a need to do two things in a #lang:
>>
>>  - Most importantly, make all strings that appear in the source code
>>immutable
>>
>
> Make #%datum turn literal strings `s` into `(string->immutable-string s)`

Philip has seemed to suggest that maybe this isn't necessary (?)
but it's useful to understand how #%datum helps here

>>  - Second and not as urgent, I'd like to add a "dot" notation, so that
>>(foo.bar 1 2 3) expands into (foo 'bar 1 2 3)
>>
>
> Turn on `read-cdot` and then make the `#%dot` macro put a quote on the RHS
> and have #%app notice a #%dot and unwrap it
>
> Jay

Okay thanks, I'll give that a try!

>> It seems to me that both of these needs are similar.  I can imagine how
>> to do both by thinking of the syntax tree like a list structure and
>> rewrite via recursive descent.  I guess I would re-append the src
>> locations to the new structure.  This seems doable.
>>
>> But is it the best way?  I'm guessing maybe there's a more racket'y way
>> but I'm unsure.
>>

-- 
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/87a796hvip.fsf%40dustycloud.org.


Re: [racket-users] What's the best way to do these syntax transforms?

2019-11-08 Thread Christopher Lemmer Webber
Philip McGrath writes:

> On Fri, Nov 8, 2019 at 9:56 AM Jay McCarthy  wrote:
>
>> On Fri, Nov 8, 2019 at 9:51 AM Christopher Lemmer Webber <
>> cweb...@dustycloud.org> wrote:
>>
>>> I have a need to do two things in a #lang:
>>>
>>>  - Most importantly, make all strings that appear in the source code
>>>immutable
>>>
>>
>> Make #%datum turn literal strings `s` into `(string->immutable-string s)`
>>
>
>  But the default `#%datum` (which expands to `quote`) already does this:
>> (immutable? "foo")
> #t
> Or, for another way of thinking about it, strings that go into syntax
> objects are interned. The upshot is that literals are immutable by default:
> a language that wanted mutable literals would have to make special effort
> via `#%datum`.
>
> -Philip

Huh... somehow I had thought that I had heard that Racket has mutable
strings by default.  It cropped up on my TODO list because of that.  I
wonder what gave me that impression?

-- 
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/87bltmhvks.fsf%40dustycloud.org.


Re: [racket-users] What's the best way to do these syntax transforms?

2019-11-08 Thread Matthew Flatt
At Fri, 8 Nov 2019 11:28:46 -0500, Philip McGrath wrote:
> On Fri, Nov 8, 2019 at 9:56 AM Jay McCarthy  wrote:
> 
> > On Fri, Nov 8, 2019 at 9:51 AM Christopher Lemmer Webber <
> > cweb...@dustycloud.org> wrote:
> >
> >> I have a need to do two things in a #lang:
> >>
> >>  - Most importantly, make all strings that appear in the source code
> >>immutable
> >>
> >
> > Make #%datum turn literal strings `s` into `(string->immutable-string s)`
> >
> 
>  But the default `#%datum` (which expands to `quote`) already does this:
> > (immutable? "foo")
> #t
> Or, for another way of thinking about it, strings that go into syntax
> objects are interned.

More precisely, the reader (via `read-syntax`) creates immutable
strings.

If a macro constructs a mutable string and converts it to a syntax
object, the string is not converted to an immutable string. Maybe it
should be.

-- 
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/5dc5c900.1c69fb81.b7375.6166SMTPIN_ADDED_MISSING%40gmr-mx.google.com.


Re: [racket-users] What's the best way to do these syntax transforms?

2019-11-08 Thread Philip McGrath
On Fri, Nov 8, 2019 at 9:56 AM Jay McCarthy  wrote:

> On Fri, Nov 8, 2019 at 9:51 AM Christopher Lemmer Webber <
> cweb...@dustycloud.org> wrote:
>
>> I have a need to do two things in a #lang:
>>
>>  - Most importantly, make all strings that appear in the source code
>>immutable
>>
>
> Make #%datum turn literal strings `s` into `(string->immutable-string s)`
>

 But the default `#%datum` (which expands to `quote`) already does this:
> (immutable? "foo")
#t
Or, for another way of thinking about it, strings that go into syntax
objects are interned. The upshot is that literals are immutable by default:
a language that wanted mutable literals would have to make special effort
via `#%datum`.

-Philip

-- 
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/CAH3z3gaxTm1hfEW2v8FjRFQ3noSMH7H_o%2BfY7oxXNpS5pqGvuA%40mail.gmail.com.


Re: [racket-users] What's the best way to do these syntax transforms?

2019-11-08 Thread Jay McCarthy
On Fri, Nov 8, 2019 at 9:51 AM Christopher Lemmer Webber <
cweb...@dustycloud.org> wrote:

> I have a need to do two things in a #lang:
>
>  - Most importantly, make all strings that appear in the source code
>immutable
>

Make #%datum turn literal strings `s` into `(string->immutable-string s)`


>  - Second and not as urgent, I'd like to add a "dot" notation, so that
>(foo.bar 1 2 3) expands into (foo 'bar 1 2 3)
>

Turn on `read-cdot` and then make the `#%dot` macro put a quote on the RHS
and have #%app notice a #%dot and unwrap it

Jay


> It seems to me that both of these needs are similar.  I can imagine how
> to do both by thinking of the syntax tree like a list structure and
> rewrite via recursive descent.  I guess I would re-append the src
> locations to the new structure.  This seems doable.
>
> But is it the best way?  I'm guessing maybe there's a more racket'y way
> but I'm unsure.
>


--
Jay McCarthy
Associate Professor @ CS @ UMass Lowell
http://jeapostrophe.github.io
Vincit qui se vincit.

-- 
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/CAJYbDanKjP3D6eyJ8cKbmLNAh48S6nJKno4hmEYwp1tHsjnRMw%40mail.gmail.com.


[racket-users] What's the best way to do these syntax transforms?

2019-11-08 Thread Christopher Lemmer Webber
I have a need to do two things in a #lang:

 - Most importantly, make all strings that appear in the source code
   immutable
 - Second and not as urgent, I'd like to add a "dot" notation, so that
   (foo.bar 1 2 3) expands into (foo 'bar 1 2 3)

It seems to me that both of these needs are similar.  I can imagine how
to do both by thinking of the syntax tree like a list structure and
rewrite via recursive descent.  I guess I would re-append the src
locations to the new structure.  This seems doable.

But is it the best way?  I'm guessing maybe there's a more racket'y way
but I'm unsure.

-- 
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/87imnuifp4.fsf%40dustycloud.org.