# Style question: alternatives to threading?

**URL:** <https://racket.discourse.group/t/style-question-alternatives-to-threading/3929>\
**Category:** Questions & Answers\
**Created:** [September 3, 2025, 2:52pm UTC](https://racket.discourse.group/t/style-question-alternatives-to-threading/3929 "2025-09-03T14:52:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamesgeddes](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jamesgeddes/32/974_2.png) [@jamesgeddes](https://racket.discourse.group/u/jamesgeddes)\
**Post date:** [September 3, 2025, 2:52pm UTC](https://racket.discourse.group/t/style-question-alternatives-to-threading/3929/1 "2025-09-03T14:52:25Z")

</div>

Sometimes I have an expression like `(f (g (h x)))`, except that the `f`, `g`, and `h` represent operations that are a little too short to bother giving names to (or even introducing lambdas) but a little too long to mash together. In a procedural language, you'd maybe write a sequence of operations, something like ...

```scheme
(let* ([x (F ... x ...)]
       [x (G ... x ...)]
       [x (H ... x ...)])
   x) 

```

(where `F ... x ...`, say, is supposed to mean "an expression involving `x`").

Is there some convention on this in Scheme? _Would_ you write the above, or is that rather infra dig.? Would you write it but change subsequent bindings to `y`, `z`, ...? Would you just go ahead and define named functions on the grounds that that's cheap in Scheme? Or does everyone just use threading, and write a lambda where necessary?

---

<div class="post-metadata">

**Author:** ![Laurent.O](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/laurent.o/32/18_2.png) [@Laurent.O](https://racket.discourse.group/u/Laurent.O)\
**Post date:** [September 3, 2025, 4:25pm UTC](https://racket.discourse.group/t/style-question-alternatives-to-threading/3929/2 "2025-09-03T16:25:05Z")

</div>

I'd write the above, but wrapped in a simple macro like [this one](https://racket.discourse.group/t/share-your-favourite-macros-that-youve-written/2017/3).

---

<div class="post-metadata">

**Author:** ![jamesgeddes](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jamesgeddes/32/974_2.png) [@jamesgeddes](https://racket.discourse.group/u/jamesgeddes)\
**Post date:** [September 4, 2025, 7:15am UTC](https://racket.discourse.group/t/style-question-alternatives-to-threading/3929/3 "2025-09-04T07:15:20Z")

</div>

That is very readable.

---

<div class="post-metadata">

**Author:** ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)\
**Post date:** [September 5, 2025, 4:00pm UTC](https://racket.discourse.group/t/style-question-alternatives-to-threading/3929/4 "2025-09-05T16:00:36Z")

</div>

Are you finding that you need to frequently write lambdas when using the threading macro? I'm curious why that would be the case --- could you share an example?

Note that you can use `_` to indicate placement of the argument within the expressions:

```scheme
(~> "middle" (string-append "beginning-" _ "-end"))

```

Personally, I would favor the threading style here, and I would [use Qi](https://docs.racket-lang.org/qi/Introduction_and_Usage.html#%28part._.Relationship_to_the_.Threading_.Macro%29).

---

<div class="post-metadata">

**Author:** ![damien\_mattei](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/damien_mattei/32/2706_2.png) [@damien\_mattei](https://racket.discourse.group/u/damien_mattei)\
**Post date:** [September 6, 2025, 7:54am UTC](https://racket.discourse.group/t/style-question-alternatives-to-threading/3929/5 "2025-09-06T07:54:31Z")

</div>

And if you use Qi with SRFI-105 Curly Infix you can write more easy to understand flows in infix :

```scheme
{("middle") ~> (string-append "beginning-" _ "-end")}

```

note that it seems that in @countvajhula example seems `"middle"` require to be between parenthesis ( ) because for me it does not works (even with `#lang racket` ) but i'm not absolutely sure of the syntax, see a full test below indeed (screenshot) :

 ![2025-09-06-094656_1920x1080_scrot](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/1/192df907637f9f30544f04cb320f6927a935505a.png)
