
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.

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

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

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

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

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

are the lists sorted?

lol +1

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

arguments should be reversed in the first one

I meant to swap the arguments

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

OK, I have what I need, thanks all!

@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)))

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

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

@massung sgn

tyvm

@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.

@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:

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

will racket 7.6 release with chezscheme :0?

@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.

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

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/

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?

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.

@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.

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).

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.

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

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.

@greg that’s brilliant