
I just got one a couple hours ago.


I find myself writing this pattern very often (let ([ret (make-mutable-structure ...)]) ,@mutate-ret ret)
, is there an idiomatic way to do it?

What is “,@mutate-ret”?

It looks weird because it seems like you are not in a quasiquoting context, so it doesn’t make sense to unquote

do you meant to say
(let ([ret (make-mutable-structure ...)])
<expression that mutates ret> …
ret)
?

There’s an idiom if <expression> ...
doesn’t mention ret
: (begin0 <e1> <e2> <e3>)
is translated to:
(let ([ret <e1>])
<e2>
<e3>
ret)
except that, as mentioned above <e2>
and <e3>
doesn’t have a way to refer to ret
.

You are free to define your own macro however:
(define-syntax-rule (let0 x e es ...)
(let ([x e])
es ...
x))
(let0 ret (make-mutable-structure)
(set-field! ret 1))

If you want even more magic, you can make ret
to be a “magic keyword” similar to this
in Java. This can be done by either using syntax parameter or unhygienic macro.

So the usage might look like:
(let0 (make-mutable-structure)
(set-field! ret 1))

@pocmatos Thank you! :slightly_smiling_face:

So I think I’ve successfully enabled GitHub login for discourse. If anyone can give it a go I’d appreciate some testing

Clojure has a doto
form that is similar, something like (transliterated) (doto ([ret (make-…)])
(exps with ret))
Though now I can’t remember if doto returns ret or not. It was intended primarily for use with Java objects and methods, I think, but could be the basis for a useful macro.