popa.bogdanp
2021-5-14 07:11:45

Here are some things that I don’t think are highlighted enough. If Racket were to lose its macro system tomorrow, I’d continue using it because of these things:

• Racket’s concurrency primitives are far better than anything you can get out of CL (which is nothing out of the box and then either bordeaux-threads or one of the libs that wrap libuv). • Ports are a nice abstraction and the fact that “gray streams” aren’t a standard part of CL rubs me the wrong way (even though most (all?) implementations support them). • Proper tail calls. • An integrated documentation ecosystem via scribblings. This is massive and pretty much no other language even comes close to it IME. Rust, Python, Go and even CL have documentation systems, but library docs are segmented from each other. There’s probably more, but that’s all I can think of pre :coffee:️.


sschwarzer
2021-5-14 10:47:49

I have defined a struct of the form (struct foo (x y)) and want to compare instances of it in tests.

This struct doesn’t need to be accessed outside the module, so the struct doesn’t need to be transparent. On the other hand, I have unit tests in the module that define and use the struct, but since the struct is opaque, I can’t compare instances of the struct with equal? in the tests. I also found struct->vector and struct->list, but I was able to confirm the documentation :wink: that they skip or fail with opaque fields.

Now I can think of several ways to compare the struct values: • Make the struct transparent and compare instances with equal? • Define a module-local function (foo->list foo-instance) for the tests and compare the result(s) with equal? • Define a module-local function (foo=? foo-instance1 foo-instance2) for the tests and use this instead of equal?. (Being able to use equal? would be nice though to make use of check-equal? and test-equal?.) I think I’d go with the foo->list approach, but I wonder if there’s a better approach, maybe something simpler I missed?


sschwarzer
2021-5-14 10:56:45

A downside of the foo->list approach is that the function would need to be updated if I change the definition of foo (say, adding a field). It’s not a problem in my case, but in general this would be a disadvantage / potential source of unintentionally passing tests.



kyp0717
2021-5-14 11:03:13

Hello. What is the difference between hash vs hasheq data structure?


kellysmith12.21
2021-5-14 11:05:22

A normal hash table uses equal? to compare keys, while a hasheq table uses eq? to compare keys. In almost every case, you’ll want to use a normal hash (and you’ll almost always want to use equal? to see if two things are equal).


sschwarzer
2021-5-14 11:07:06

Implementing gen:equal+hash seems a lot of code though for this purpose. That said, I see it could be useful to recursively compare data that contains opaque struct instances.


kyp0717
2021-5-14 11:08:58

Thank you for your respond. In which situation would you use hasheq ?


kellysmith12.21
2021-5-14 11:20:45

I can’t think of a situation where I would use hasheq… I suppose an example would be if I wanted to traverse cyclic data and check if I ended up back at the start, but there’s probably a better way to do that.


samth
2021-5-14 16:45:51

dan.ml.901
2021-5-14 18:34:33

How would I get that debugging option in Dr Racket outside of Dr Racket? I’m trying to get that in the Racket Language server in VS Code.


dan.ml.901
2021-5-14 18:36:44

Ah nvm I see the docs explain it


samth
2021-5-14 18:37:00

I don’t know how to do that in the language server. At the command line, you use errortrace as described here: https://docs.racket-lang.org/errortrace/quick-instructions.html?q=errortrce


kellysmith12.21
2021-5-15 01:35:52

One more example: if the keys to the hash table are all symbols (but not strings), then it would make sense to use hasheq.