Replies: 9 comments 21 replies
-
As an aside, there should probably be a clearer printing of mutable strings than |
Beta Was this translation helpful? Give feedback.
-
My vote here is for option 2. It's backwards compatible while retaining the smallest legacy code and API surface possible. And I can add Resyntax rules to push people towards using immutable strings, so they don't have to remember to use the flags. |
Beta Was this translation helpful? Give feedback.
-
I'd go for option 1. Even for large strings, |
Beta Was this translation helpful? Give feedback.
-
I am also for option 1 generally, adding immutable-string variants of primitives to Racket as needed for performance. |
Beta Was this translation helpful? Give feedback.
-
Option 1 isn't safe if any of the mutable strings on the racket side get reused. Do we know for a fact that doesn't happen in any string APIs? I know that |
Beta Was this translation helpful? Give feedback.
-
Racket switched lists from mutable to immutable. I see no reason why we can't do the same for strings, considering that the list change presumably was larger and affected more programs. |
Beta Was this translation helpful? Give feedback.
-
“800” — that’s a small number. I expected more.
|
Beta Was this translation helpful? Give feedback.
-
I'd like that only Two ideas, I'm not sure about them:
|
Beta Was this translation helpful? Give feedback.
-
Inspired by the discussion on normalizing-annotations / impersonator-annotations vs flat-annotations, here's what it would currently look like in terms of impersonator contracts: (define (string->immutable-string-proj blame)
(λ (s neg-party)
(cond
[(string? s) (string->immutable-string s)]
[else
(raise-blame-error blame #:missing-party neg-party s
'(expected "string?" given: "~e")
s)])))
(define ->immutable-string/c
(make-contract
#:name '->immutable-string/c
#:first-order string?
#:late-neg-projection string->immutable-string-proj)) With the (define/contract regexp-match/immutable
(-> regexp?
string?
(or/c #f
(cons/c ->immutable-string/c (listof (or/c ->immutable-string/c #f)))))
regexp-match)
(define/contract regexp-match*/immutable
(->* [regexp?
string?]
[#:match-select (or/c (list? . -> . (or/c any/c list?)) #f)]
(listof (or/c ->immutable-string/c (listof (or/c #f ->immutable-string/c)))))
regexp-match*) |
Beta Was this translation helpful? Give feedback.
-
Rhombus now expects strings to be immutable rather pervasively. This is partly because
String
only matches Racket's immutable strings, even more so because aMap
with the default hashing compares mutable and immutable strings differently. Unfortunately that has significant conflicts with runtime features that produce strings, like regular expressions and IO. So, for example this doesn't work (using @samdphillipsrhombus/compat
library):No matter what you type in, it will never match the key. Similar problems arise with regular expression splitting of strings, and with other core Racket operations that produce strings.
I can think of a few approaches to take here (of course there could be some I haven't thought of):
unsafe-string->immutable-string!
can make this pretty fast, but it adds overhead to many Rhombus APIs.I don't have a strong sense of what's best here, or whether there's a better choice that I haven't thought of yet, but it seems important to start thinking about this.
Beta Was this translation helpful? Give feedback.
All reactions