gknauth
2020-2-5 17:50:34

Suppose I have two lists (list 1 2 3 4 5) and (list 3 4 5 7 8). What I need is something that will tell me, when comparing the two lists (or sets, really), that the second list took away (list 1 2) , kept (list 3 4 5) and added (list 7 8) . I’ve been looking at racket/set and I’m trying to figure out if it has enough for me to do that as is, i.e., the ingredients are there and I just have to put them together right, or whether I need to create some new code. FWIW, this is weather-related, alerts followed by alerts followed by more alerts, …, with the set of locations changing often.


soegaard2
2020-2-5 17:54:38

(list 1 2) = (set-substract (list 3 4 5 7 8 ) (list 1 2 3 4 5))


soegaard2
2020-2-5 17:55:11

(list 3 4 5) = (set-intersect ...)


soegaard2
2020-2-5 17:56:37

(list 7 8 ) = (set-subtract (list 3 4 5 7 8 ) (list 1 2 3 4 5)


sorawee
2020-2-5 17:57:37

Ah, it’s actually a set. OK, my bad.


soegaard2
2020-2-5 17:58:48

If the lists are sorted, I think, you could write something more efficient though.


massung
2020-2-5 17:58:56

are the lists sorted?


massung
2020-2-5 17:59:01

lol +1


gknauth
2020-2-5 17:59:44

Thanks @soegaard2 and @sorawee! @soegaard2, is the first computation above correct? It is the same as the third.


jaz
2020-2-5 18:00:05

arguments should be reversed in the first one


soegaard2
2020-2-5 18:00:08

I meant to swap the arguments


gknauth
2020-2-5 18:00:31

Thanks @jaz & @soegaard2. @massung yes the lists are sorted.


gknauth
2020-2-5 18:00:44

OK, I have what I need, thanks all!


massung
2020-2-5 18:26:48

@gknauth does this meet needs easier? (define (sub/sect xs ys) (letrec ([agg (λ (xs ys final dropped intersected) (cond [(null? xs) (values (append final ys) dropped intersected)] [(null? ys) (values final (append dropped xs) intersected)] [else (let ([x (car xs)] [y (car ys)]) (cond [(= x y) (agg (cdr xs) (cdr ys) (cons y final) dropped (cons x intersected))] [(< x y) (agg (cdr xs) ys final (cons x dropped) intersected)] [else (agg xs (cdr ys) (cons y final) dropped intersected)]))]))]) (agg xs ys null null null)))


massung
2020-2-5 18:27:03

> (sub/sect '(1 2 3 4 5) '(3 4 5 7 8)) '(5 4 3 7 8) '(2 1) '(5 4 3)


massung
2020-2-5 19:23:19

sorry, not seeing it obviously anywhere… does racket have a sign or signum function readily available?


soegaard2
2020-2-5 19:24:41

@massung sgn


massung
2020-2-5 19:24:49

tyvm


gknauth
2020-2-5 19:39:44

@massung Thanks. sub/sect didn’t do quite what I needed, but I appreciate the effort! (Its first value returned was same as the second set passed in, it did give me the set of items dropped, and it did not give the items added.) But all’s cool, given the help I received earlier from everyone, mostly based on what @soegaard2 provided, I was able to cook up something, so I have what I need.


massung
2020-2-5 19:46:24

@gknauth ah, np. i thought you wanted the intersection instead of added. it’d be easy to modify to give added instead, but if you’re good then good. :slightly_smiling_face:


gknauth
2020-2-5 19:47:00

@massung I’m good, but thank you! Thank you everyone!


jestarray
2020-2-5 21:18:18

will racket 7.6 release with chezscheme :0?


sorawee
2020-2-5 21:31:28

@jestarray According to the drafted Racket 7.6 release announcement (https://groups.google.com/forum/#!topic/racket-dev/xYjE9JCe9u0):

> Racket CS is ready for production use. We will work to further improve Racket CS before making it the default implementation, but it now consistently passes all of our integration tests and generally performs well. (Compiled code remains significantly larger compared to the default implementation.) So just like Racket 7.5, the release will have both variants, with the default being 3m.


massung
2020-2-5 21:39:17

> generally performs well Is this on Windows, too? Last time I tried Racket CS (7.4) is ran considerably worse on Windows


greg
2020-2-5 22:13:44

This is still very WIP, and the web page was quickly thrown together from some screen caps and org-mode. But what I’ve been working on for the last 3 or 4 weeks: https://www.racket-mode.com/racket-check-syntax-preview/


greg
2020-2-5 23:47:54

racket-check-syntax-mode is awfully verbose, especially when a prefix to other names. I’m open to better suggestions. racket-check-mode? Would racket-plus-mode or racket-ide-mode be too pretentious and/or inaccurate?


ruyvalle
2020-2-6 00:09:05

Is there a recommended way of writing to a unix socket? I’m currently doing something like (displayln data output-socket).

Also does shutting down a custodian take a long time?

(let loop () (define t (thread (thunk (for ([i (in-range 5000)]) (displayln i) (displayln data output-socket))))) (sleep 2) (kill-thread t) (loop)) and (let loop ([cust (make-custodian)]) (parameterize ([current-custodian cust]) (thread (thunk (for ([i (in-range 5000)]) (displayln i) (displayln data output-socket)))) (sleep 2)) (loop (make-custodian))) appear to behave quite differently.

In the latter case, the output to stdout from several threads appears to get mixed, whereas in the former case there is no such mixing.

By the way, data is a string with approximately 2500 characters.


greg
2020-2-6 00:31:02

@ruyvalle Using displayln seems fine. Keep in mind that some kinds of ports are buffered, e.g. TCP ports, so you might want to use flush-output before waiting to receive a response, if you have some sort of two-way protocol.


greg
2020-2-6 00:32:22

As for custodians, I don’t think they’re inherently much slower than having some sort of “cleanup” function you write yourself, that does the same sort of things (e.g. closing ports, releasing other resources).


greg
2020-2-6 00:33:09

I don’t think there’s any value to making a custodian, if you never call custodian-shutdown-all on it. I realize your snippet above is just for-example, but wanted to mention this.


greg
2020-2-6 00:34:29

I think https://docs.racket-lang.org/more/index.html has some good discussion and examples if you haven’t already seen that.


ruyvalle
2020-2-6 00:37:23

Thanks @greg! I’ve started going through that link, but haven’t gone through the whole thing. What you said makes a lot of sense. I’ll try using flush-output as you suggested.


samth
2020-2-6 03:01:24

@greg that’s brilliant