jerome.martin.dev
2019-6-12 07:31:37

That’s perfect, thank you :slightly_smiling_face:


steveh2009
2019-6-12 14:02:49

Are Cygwin DLLs and DLLs produced by Microsoft Visual Studio the same thing as far as Racket’s FFI goes for integrating C libraries?


mflatt
2019-6-12 14:39:41

Probably. It’s the same object format. I forget whether Cygwin DLLs pull in any dependencies or behavior that is inherently incompatible with Racket, but I don’t think it does.


stefan.kruger
2019-6-12 15:34:44

@stefan.kruger has joined the channel


stefan.kruger
2019-6-12 15:53:17

I’d like to reduce a hash to a list with fewer items than what the hash contains - for a list I’d look to use filter-map or foldl. I naively tried (filter-map (lambda (k v) ...) (in-hash ht)) but filter-map no good on a sequence. Then I tried (for/list ([(k v) (in-hash ht)] ... with a #:when clause, which kind of works, except I’d need to do a bunch of (let... in the #:when… I had hoped I could do: (for/list ([(k v) (in-hash ht)]) (let ([new-v (...)]) (when (or (not (...)) (< new-v (...))) (values k)))) but didn’t expect the voids.



greg
2019-6-12 15:59:01

@stefan.kruger You can use for*/list and then use in-value to get let-like bindings in the clauses.


greg
2019-6-12 16:03:23

For example: (define ht (hash 'a 1 'b 4 'c 7 'd 9)) (for*/list ([(k v) (in-hash ht)] [new-v (in-value (* v 100))] #:when (< new-v 500)) k) ;; '(a b)


stefan.kruger
2019-6-12 16:05:00

Wow, that looks just what I was reaching for. Thanks for your help!


greg
2019-6-12 16:06:36

You’re welcome. in-value is a good name in the sense that it describes what it does, but, it doesn’t really afford why you’d want to use it, so, it’s probably not ideally discoverable. Anyway this is a pretty common idiom in Racket and you’ll see examples in the docs or in various repos.


notjack
2019-6-12 16:10:37

You can send place channels across place channels right? Have each request include a fresh single-use channel and have the hasher place send its response to the channel in the request


popa.bogdanp
2019-6-12 16:33:07

@notjack I’ve thought about that as well, but since FFI operations block the entire OS thread (in this case, the one backing the place — meaning the place can’t really process incoming messages concurrently), I don’t think that’ll make a huge difference compared to locking around the resource with call-with-semaphore as I am right now. If/when I need to improve the speed of login operations, I think creating a pool of hasher places will be the way to go.


notjack
2019-6-12 16:38:44

Oh I meant just as a way to ensure messages can’t get crossed


stefan.kruger
2019-6-12 16:52:26

Works :slightly_smiling_face: — I’d never have discovered that on my own.


samdphillips
2019-6-12 17:43:58

I forget about in-value a lot, which is probably why a lot of my code is cluttered with for/fold


sorawee
2019-6-12 18:05:19

Is there an in-value like solution for match as well? The best I can come up with is:

(match (list 5 6 7)
  [(list a (and b (app (lambda (x) (* 2 x)) d)) c)
   #:when (>= d 10)
   (list a b c d)])

But this looks kinda awful


alexknauth
2019-6-12 18:09:22

have you looked at the as pattern from unstable/match?



alexknauth
2019-6-12 18:14:51

@sorawee I would like to be able to write (require unstable/match) (match (list 5 6 7) [(list a (and b (as ([d (* 2 b)]))) c) #:when (>= d 10) (list a b c d)]) instead of that app + lambda thing, but match’s pattern language limits its binding

A more syntax-parse-like match form would be able to handle this perfectly though


sorawee
2019-6-12 18:15:56

Yeah, I think as can only see stuff outside of match (same as ==), but not variables bound in match, which is what I want


sorawee
2019-6-12 18:17:38

as will also get tedious when the pattern is bigger (e.g., the bound variable is in several branches of or)


sorawee
2019-6-12 18:18:01

Ideally I want something like:

(match (list 5 6 7)
  [(list a b c)
   #:with d (* 2 b)
   #:when (>= d 10)
   (list a b c d)])

alexknauth
2019-6-12 18:20:51

I believe @lexi.lambda at some point was working on a pattern-combinator language that would support syntax-parse-like features, including delimited cuts. And I’ve written some macros that would be able to compile a match pattern to use such a pattern-combinator language in a way that would allow exactly that (come to think of it, it would also allow the (and b (as ([d (* 2 b)]))) pattern above)

Although IIRC there were performance issues


lexi.lambda
2019-6-12 18:21:35

I never got to implementing head patterns.


sorawee
2019-6-12 18:21:41

I’m really looking forward to that :slightly_smiling_face:


lexi.lambda
2019-6-12 18:25:26

I have an idea for a way to implement (ellipsis) head pattern-like things in a datatype-agnostic way using a monadic DSL, but I haven’t gotten around to trying to implement it.


alexknauth
2019-6-12 18:27:48

Actually, I have a partially-working version of match patterns that would allow Sorawee’s example here https://github.com/AlexKnauth/match-pattern-synonym (require match-pattern-synonym) (match (list 5 6 7) [(list a (~refine b (~with d (* 2 b))) c) #:when (>= d 10) (list a b c d)]) The main goal of this project was to allow recursive pattern-synonyms, in the same way syntax-parse allows recursive syntax-classes, but I also got the ~refine pattern to work like and works in syntax-parse, along with a ~with pattern


lexi.lambda
2019-6-12 18:29:32

What is “that” in this context? If it’s monadic head patterns, the main thing I wanted to do differently is to make those patterns first-class values, the same way my existing implementation makes single-term patterns first-class values.


lexi.lambda
2019-6-12 18:30:22

But then I’d probably want a domain-specific optimizer language to make common cases fast, like GHC’s rewrite rules… can someone go do a PhD on that, please? :)


alexknauth
2019-6-12 18:34:45

“that” is the match-pattern-synonym repository


lexi.lambda
2019-6-12 18:35:44

I thought that was “here.” (But it probably doesn’t matter very much; don’t mind me.)


alexknauth
2019-6-12 18:38:54

Oh. “version of that here” + “that” somewhere else would imply something I did not mean


alexknauth
2019-6-12 18:56:01

Monadic head patterns sound interesting…


alexknauth
2019-6-12 19:16:25

I don’t have head patterns for my version of match patterns either


sorawee
2019-6-13 03:49:37

3 more commits!


jesse
2019-6-13 06:02:32

is anyone else going to ICFP in Berlin this August?