hendrik
2022-2-25 10:42:55

@hendrik has joined the channel


hendrik
2022-2-25 10:46:37

Trying this out.


laurent.orseau
2022-2-25 10:49:12

Oh, hey Hendrik, welcome!


christos.perivolaropo
2022-2-25 12:24:28

is there a similar macro to CLs when-let that works like (when-let ([x ...]) (display x)) is guaranteed not to display #f


spdegabrielle
2022-2-25 12:24:52

Hi @hendrik :wave:


sorawee
2022-2-25 12:26:46

Not from the standard library, but you can create your own, or use ones from packages


sorawee
2022-2-25 12:27:27

Well, actually, cond can kinda do that


soegaard2
2022-2-25 12:27:36

@christos.perivolaropo

You can use the => clause in cond.


sorawee
2022-2-25 12:27:45

(cond [... => (lambda (x) ...)])


sorawee
2022-2-25 12:27:55

Yep, what @soegaard2 said


soegaard2
2022-2-25 12:28:28

sorawee
2022-2-25 12:29:22

pretty clunky though. Unless I have the proc-expr already defined somewhere, I probably would write the expanded form myself, or use match


soegaard2
2022-2-25 12:30:17

Agree. There were a srfi that had a “nicer” version - but the name escapes me.


soegaard2
2022-2-25 12:31:36

laurent.orseau
2022-2-25 13:05:17

I’ve given this some more thought, and this might have been a corner case of for/fold only. For example, the behaviour of #:when is more apparent with for: (for/list (#:when (> i 2) [i 10]) i) i: undefined; cannot reference an identifier before its definition Disabling breaks before the first for clause seems like a half-ass patch in retrospect.

I’m now inclined to either not changed anything or add a small example to for/fold.


laurent.orseau
2022-2-25 13:15:15

@christos.perivolaropo If you desperately want when-let, it’s straightforward to write: #lang racket (require syntax/parse/define) (define-syntax-parse-rule (when-let ([x:id v:expr]) body ...) (let ([x v]) (when x body ...))) (when-let ([a #f]) (displayln a)) (when-let ([a 3]) (displayln a))


laurent.orseau
2022-2-25 13:16:47

Not sure if when-let is supposed to handle multiple bindings.


greg
2022-2-25 14:53:40

In Emacs Lisp if-let and when-let do handle multiple bindings (and-ing them all for the condition).


greg
2022-2-25 14:55:12

Also there’s a shorthand, for a single binding you can use just one set of parens, e.g. (when-let (x rhs) body...).


greg
2022-2-25 14:55:30

Also I think there are if-let* and when-let*.


greg
2022-2-25 14:55:58

So this could be a whole little library if someone wanted to do that.


greg
2022-2-25 14:57:13

Having said all that I’m usually OK just using match (in Racket) or pcase (in Elisp), although it’s a little verbose.


massung
2022-2-25 15:23:03

Along the same lines, I always miss let-returning and similar constructs.


laurent.orseau
2022-2-25 15:29:22

What’s let-returning? Sounds similar to (let/ec return (let (...) ...))


massung
2022-2-25 15:32:59

Wondering if someone has a solution to this FFI problem:

I’m using a 3rd party FFI library that has a “kind of” bug in it, but it’s something I can’t fix myself. Simply put there is some global state that’s 0 upon initialization (correct) but changes over the course of using the library. At some point I’m done with my work and want to start over. However, the library doesn’t have a way of resetting that global state itself (open issue).

I currently have no way of resetting this state myself without quitting Racket and restarting it, which reloads the library. And I don’t see any FFI functions in Racket to unload (or reload) a library. Obviously this is great 99% of the time and this is just an annoying predicament that I happen to be in because the library in question was never intended to be used from a REPL.


massung
2022-2-25 15:33:23

Like so:

(let-returning ([x (+ 1 2)]) (println x)) Would be the same as:

(let ([x (+ 1 2)]) (begin0 x (println x)))


laurent.orseau
2022-2-25 15:39:14

ah that’s different then, thanks. (also very easy to implement anyway)


christos.perivolaropo
2022-2-25 15:55:01

Thanks everyone! Very helpful comments, I think I will write the macro


christos.perivolaropo
2022-2-25 15:55:17

That @laurent.orseau suggests


ryanc
2022-2-25 15:56:17

The #:custodian argument to ffi-lib is where Racket’s support for unloading dynamic libraries lives. If you give it a custodian, it registers the library to be unloaded when the custodian is shut down. See the warnings in the docs.


massung
2022-2-25 16:01:04

Thanks for the pointer


soegaard2
2022-2-25 17:13:07

@massung I would love having the option of using your synthesizer with Sketching.


sachinsrivastava2019
2022-2-25 17:59:23

@sachinsrivastava2019 has joined the channel


wjb
2022-2-25 21:22:08

Is there an easy way to enable that nifty search box on my own scribble htmls site? There isn’t a lot of documentation on it, except for a rather mysterious search-box? field in the html renderer.


bsilverstrim
2022-2-25 22:36:20

Has something happened that the Racket Newsletter hasn’t been updating?


alexharsanyi
2022-2-25 23:20:15

Could someone who is familiar with racket/draw and/or cairo libraries, have a look at https://github.com/racket/plot/issues/109, the last comment has a simple program which renders incorrectly vertical text. The problem seems to be limited to Windows for a specific font family and sizes. Thanks, Alex.