sorawee
2021-7-19 08:13:12

Do I read this correctly?

https://github.com/racket/readline/blob/master/readline-lib/readline/rktrl.rkt#L199

(cond [(and (not use-cs-other-thread?) (eq? 'chez-scheme (system-type 'vm))) where use-cs-other-thread? is defined as:

(eq? 'chez-scheme (system-type 'vm)) Wouldn’t this make the first branch always a dead code?

@mflatt


hazel
2021-7-19 11:44:05

it’s a predicate for detecting if cond is messed up (/s)


blerner
2021-7-19 12:14:42

For planning purposes, @asumu, will the PPA builds for this be out soon?


mflatt
2021-7-19 12:31:03

Yes, it’s dead code with the current definition of use-cs-other-thread?. The intent (and use while developing) was to be able to turn that code on and off. Since the use-cs-other-thread? mode has worked out, it would make sense to clean up the dead code.


massung
2021-7-19 16:00:31

Assuming no modification between calls to a hash table, are hash-keys and hash-values guaranteed to return the same order (even though the order is unspecified)? E.g. the 3rd key in the returned key list would be guaranteed to match with the 3rd value returned in the values list?


massung
2021-7-19 16:01:06

Or should I be certain by doing hash->list and mapping to get keys/values?


samth
2021-7-19 16:12:46

Or use in-hash


massung
2021-7-19 19:29:17

Is there a particular reason why a string is not a valid JSON key?


samth
2021-7-19 19:30:34

Allowing strings would make JSON not always round-trip


samth
2021-7-19 19:30:46

There might be other reasons but that’s a significant one


sorawee
2021-7-19 19:31:48

There’s also a discussion at https://github.com/racket/racket/pull/1878


sorawee
2021-7-19 19:32:58

oh wait, I misunderstood. Meant to write https://github.com/racket/racket/pull/1877, but there’s no discussion there


samth
2021-7-19 19:33:03

I mostly think that something like that PR would be very valuable, but it’s somewhat of a change from how JSON works in Racket


massung
2021-7-19 19:33:26

that doesn’t really make much sense. All strings can be turned into symbols, so it’s pretty much moot. For example:

(write-json #hasheq((\|foo bar\| . 10))) ;=> {"foo bar":10}


samth
2021-7-19 19:34:16

Right now, if you have a value and you write it to JSON and the read it back, you get an equal? value.


samth
2021-7-19 19:34:33

Allowing strings would make that not true.


samth
2021-7-19 19:35:01

Maybe the property isn’t worth it, but that’s a reason why it hasn’t been done.


massung
2021-7-19 19:35:58

Strings can be equal? just fine. How would that make it not true? Do you mean that you might write a string key and get back a symbol key?


samth
2021-7-19 19:36:10

Right


sorawee
2021-7-19 19:36:24

By the way, relatedly, the author of the PRs I mentioned above has some dissatisfaction with Racket. I don’t know if you have already seen it: https://lobste.rs/s/6rnyn9/why_i_no_longer_contribute_racket#c_fqqb9n


samth
2021-7-19 19:36:25

You would always get back a symbol key


samth
2021-7-19 19:36:48

Yes, I saw that he was dissattisfied with the response to those PRs.


massung
2021-7-19 19:37:08

The equal? requirement I find… uncompelling.


massung
2021-7-19 19:37:27

But, it isn’t my code, and I know people who are uncompelled w/ many of my reasons in my code.


massung
2021-7-19 19:39:31

Keeping the equal? requirement, but forcing all keys to strings would probably be more inclusive, but it’d likely break a lot of existing code that uses eq? for key comparisons.


sorawee
2021-7-19 19:40:35

It would actually just break existing code.

(hash 'a 1) would not be a valid jsexpr? anymore


massung
2021-7-19 19:40:48

true there, too


samth
2021-7-19 19:41:18

I think more broadly there are two ways to think about JSON integration into Racket. One is to say “here’s a nice way to write JSON in Racket, by defining some Racket data that maps to and from JSON”. That’s basically what the json library does. Another is to say “I want to serialize my specific kind of data, and potentially deserialize it from JSON into my data structures, and I don’t need to worry about confusing it with other JSON use”. That’s a very valid thing to do, and it’s not served as well by the json library.


claiborn
2021-7-19 19:41:20

I don’t have strong opinions on the value of equal? , but the inability to use strings as keys seems to surprise every new developer trying to do something in Racket (including me), so I do suspect we could call more prominent attention to it in the docs.


massung
2021-7-19 19:42:18

It could even be parameterized when writing JSON to allow string keys


massung
2021-7-19 19:42:44

(parameterize ([json-i-understand-string-keys #t]) ...)


sorawee
2021-7-19 19:43:51

should read-json also interact with json-i-understand-string-keys?


massung
2021-7-19 19:44:17

Nah, IMO it’s less important. But that’s w/ only 2 min of thought put into it


massung
2021-7-19 19:45:28

Another option would be to “subclass” hasheq and just make a json-hash object that “did the right thing” when adding non-symbol keys (like implicitly convert strings -> symbols or error out)


massung
2021-7-19 19:54:37

yeah, i’m constantly hitting frustrations w/ writing json. e.g. having to use a list for an array, even though in-application usage of a vector is far more efficient for my use-case. This means having to copy a very large vector to a list just to write it out as JSON.


massung
2021-7-19 19:54:40

Very frustrating


samdphillips
2021-7-19 20:52:33

I have a not ready for pkg server json library that allows a little more control over json parsing. https://github.com/samdphillips/racket-stream-json


samdphillips
2021-7-19 20:52:43

Also undocumented.


shu--hung
2021-7-19 23:00:40

Is anyone (or ryanc) able to edit the answer? The expression (free-identifier=? #'x2 #'x2) should be (free-identifier=? #'x1 #'x2). Stackoverflow rejected my edit suggestion and wanted me to change at least 6 characters. https://stackoverflow.com/a/6852466/2013713


sorawee
2021-7-19 23:01:53

Done!


sorawee
2021-7-19 23:04:26

Relatedly, I think it would be nice to explain somewhere how free-identifier=? and bound-identifier=? are useful and in what situation which variant you should use.


shu--hung
2021-7-19 23:13:57

Thanks! Embarrassingly, I don’t really understand what they are doing and usually just make try a few examples to see if things work out


sorawee
2021-7-19 23:16:14

Well, me too I guess…


samth
2021-7-20 00:47:56

free-id is “do these refer to the same binding” bound-id is would one shadow the other


samth
2021-7-20 00:48:28

The only situation you should use the latter, basically, is to check for uniqueness in a binding form


samth
2021-7-20 00:48:44

(there are other uses but I’ve never needed them)


shu--hung
2021-7-20 01:19:06

free-id is relatively understandable. But for the shadowing interpretation of bound-id, what is the context that makes this well-formed (kind of)?


samth
2021-7-20 01:19:39

What do you mean by well-formed?


shu--hung
2021-7-20 01:21:37

Should I read it as: if bound-id is called in a transformer, and if both identifiers are used in binding positions in different let-forms in the output of the transformer, and that one let-form is nested in the body of the other let-form, then the binding introduced by one id will definitely be shadowed by the binding introduced by the other one


shu--hung
2021-7-20 01:22:03

Otherwise I’m not sure how to read “shadowing”


samth
2021-7-20 01:22:49

Yes, that’s the idea


shu--hung
2021-7-20 01:23:00

okay I see


samth
2021-7-20 01:23:33

I think the caveat in the paper you quoted says that “definitely” might not be right


samth
2021-7-20 01:23:45

But that’s the idea


shu--hung
2021-7-20 01:25:00

Hmm, I thought the paper says: if bound-id is true then shadowing will definitely happen. otherwise nothing is promised


samth
2021-7-20 01:25:25

A simpler statement is that if a and b are bound-id=? then (lambda (a) b) is the identity


samth
2021-7-20 01:26:17

It says that there are some cases where bound-id produces false but shadowing still happens


samth
2021-7-20 01:26:49

It’s not defined to be a conservative approximation, it’s defined to be “has the same scope sets”


shu--hung
2021-7-20 01:32:08

Thanks!! I have another question. Is bound-id symmetric because it is defined to be testing whether the two ids have the same scope set?


samth
2021-7-20 01:34:04

Yes


samth
2021-7-20 01:54:25

shu--hung
2021-7-20 01:59:44

I see the symmetric description in the doc (which does not refer to scope sets) and also in Chez’s user guide. I guess the “binding” intuition appeared before scope sets, but it’s surprising that symmetricity looks like a requirement https://scheme.com/tspl4/syntax.html#./syntax:s37


samth
2021-7-20 02:00:52

they’re equivalence relations; they’re supposed to be symmetric


shu--hung
2021-7-20 02:03:54

Hmm, is being a equivalence relation a spec or a implementation fact? Because I don’t see why “a binds b” (as in (lambda (a) b) )has to be an equivalence relation


samth
2021-7-20 02:06:48

That doesn’t have to be an equivalence relation, but functions named =? are supposed to be


shu--hung
2021-7-20 02:15:23

ah okay, indeed