# Redex- rendering multiple where clauses on separate lines

**URL:** <https://racket.discourse.group/t/redex-rendering-multiple-where-clauses-on-separate-lines/2630>\
**Category:** Questions & Answers\
**Created:** [December 31, 2023, 5:51pm UTC](https://racket.discourse.group/t/redex-rendering-multiple-where-clauses-on-separate-lines/2630 "2023-12-31T17:51:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![oflatt](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/oflatt/32/1014_2.png) [@oflatt](https://racket.discourse.group/u/oflatt)\
**Post date:** [December 31, 2023, 5:51pm UTC](https://racket.discourse.group/t/redex-rendering-multiple-where-clauses-on-separate-lines/2630/1 "2023-12-31T17:51:36Z")

</div>

I'm writing a [semantics for egglog](https://github.com/oflatt/egglog/blob/oflatt-ideal-semantics/semantics/semantics.scrbl) and struggling to get good output from `render-reduction-relation`.

I often use many `where` clauses to bind intermediate values, and these are all rendered in-line:

 ![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/4/4fdbfaff6e718b759fb76aadb8a5f5c2afe28d8b.png)

Is there a way to get these conditions rendered on separate lines? Seems like not based on [this redex source code](https://github.com/racket/redex/blob/c38859cac93b3c6f8b6ad19c9030cabaf7a36809/redex-pict-lib/redex/private/pict.rkt#L432).

Most of my problems I can fix with manual control using `with-compound-rewriter`, but I think not this one. @robby, maybe you have advice for me. It may be that I need to add a hook to redex.

---

<div class="post-metadata">

**Author:** ![robby](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/robby/32/7_2.png) [@robby](https://racket.discourse.group/u/robby)\
**Post date:** [December 31, 2023, 7:19pm UTC](https://racket.discourse.group/t/redex-rendering-multiple-where-clauses-on-separate-lines/2630/2 "2023-12-31T19:19:40Z")

</div>

It looks like `metafunction-fill-acceptable-width` affects the rendering when `rule-pict-style` is in `'compact-vertical` mode. Here's an example. Looks like the docs need updating!

```scheme
#lang racket
(require redex)
(define-language L
  (e ::= (e e) x)
  (x ::= variable-not-otherwise-mentioned))

(define-metafunction L
  long-name-for-the-identity-function : any -> any
  [(long-name-for-the-identity-function any) any])

(define r
  (reduction-relation
   L
   (--> e e_4
        (where e_1 (long-name-for-the-identity-function e))
        (where e_2 (long-name-for-the-identity-function e_1))
        (where e_3 (long-name-for-the-identity-function e_2))
        (where e_4 (long-name-for-the-identity-function e_3)))))

(parameterize ([rule-pict-style 'compact-vertical]
               [metafunction-fill-acceptable-width 10])
  (reduction-relation->pict r))

```

---

<div class="post-metadata">

**Author:** ![oflatt](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/oflatt/32/1014_2.png) [@oflatt](https://racket.discourse.group/u/oflatt)\
**Post date:** [December 31, 2023, 10:55pm UTC](https://racket.discourse.group/t/redex-rendering-multiple-where-clauses-on-separate-lines/2630/3 "2023-12-31T22:55:18Z")

</div>

That looks a lot better, thanks!  
Should I ask more redex questions here or make new posts for each? Maybe new posts in the Questions & Answers category?

---

<div class="post-metadata">

**Author:** ![oflatt](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/oflatt/32/1014_2.png) [@oflatt](https://racket.discourse.group/u/oflatt)\
**Post date:** [December 31, 2023, 10:57pm UTC](https://racket.discourse.group/t/redex-rendering-multiple-where-clauses-on-separate-lines/2630/4 "2023-12-31T22:57:27Z")

</div>

The docs for `metafunction-fill-acceptable-width` are pretty good actually, I just didn't see that one

Maybe should be renamed to `where-clause-acceptable-width`?

---

<div class="post-metadata">

**Author:** ![robby](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/robby/32/7_2.png) [@robby](https://racket.discourse.group/u/robby)\
**Post date:** [January 1, 2024, 8:03pm UTC](https://racket.discourse.group/t/redex-rendering-multiple-where-clauses-on-separate-lines/2630/5 "2024-01-01T20:03:01Z")

</div>

> [@oflatt](#):
>
> That looks a lot better, thanks!  
> Should I ask more redex questions here or make new posts for each? Maybe new posts in the Questions & Answers category?

I'm happy with anything!

> [@oflatt](#):
>
> The docs for `metafunction-fill-acceptable-width` are pretty good actually, I just didn't see that one
> 
> Maybe should be renamed to `where-clause-acceptable-width`?

I guess renaming things like that will break existing code. Probably it is best to add more cross references or maybe add some nice starting examples so that folks can more easily find existing things. I'm happy to take ideas, especially based on where you looked but didn't find something or what kind of new examples would have helped you.

---

<div class="post-metadata">

**Author:** ![oflatt](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/oflatt/32/1014_2.png) [@oflatt](https://racket.discourse.group/u/oflatt)\
**Post date:** [January 1, 2024, 8:40pm UTC](https://racket.discourse.group/t/redex-rendering-multiple-where-clauses-on-separate-lines/2630/6 "2024-01-01T20:40:55Z")

</div>

Cross-references are a good idea. I followed the first tutorial and found it very helpful. Extending that with more formatting examples would be great!

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [January 1, 2024, 8:57pm UTC](https://racket.discourse.group/t/redex-rendering-multiple-where-clauses-on-separate-lines/2630/7 "2024-01-01T20:57:39Z")

</div>

For some of my projects, I have created files with names such as `should be racket`. They contain simple compositions of Racket functions and renames that I consider better sign-posts for eventual readers. Consider starting a `should-be-redex.rkt` file where `where-clause-acceptable-width` is a renaming of `metafunction-fill-acceptable-width`. You may find that the former is the only name you use — in which case we should probably add this secondary name to `redex` — or you may find that you use it only once and then a local file is good enough.
