
@hendrik has joined the channel

Trying this out.

Oh, hey Hendrik, welcome!

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

Hi @hendrik :wave:

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

Well, actually, cond
can kinda do that

@christos.perivolaropo
You can use the =>
clause in cond
.

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

Yep, what @soegaard2 said


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

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


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
.

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

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

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

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

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

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

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

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

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

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.

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

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

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

That @laurent.orseau suggests

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.

Thanks for the pointer

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

@sachinsrivastava2019 has joined the channel

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.

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

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.