Variables referring to other variables within Module

The following doesn't work:

Lol[x_, y_] = Module[ {w=x+1, z = w + 1}, z]


because z refers to w. Is there a way to make it so that variable definitions within Module can refer to other variable definitions?

This is similar to let constructs in other languages.

• Try this: Lol[x_, y_] := Module[{w, z}, w = x + 1; z = w + 1] – MelaGo May 23 '19 at 22:21
• Strongly related if not a dupe: How to avoid nested With – Leonid Shifrin May 23 '19 at 23:27

I think you meant to use Lol[x_, y_]. At any rate, you can use With to do this, although the syntax coloring is bad:

Lol[x_, y_] := With[
{w = x + 1},
{z = w + 1},
z
]


Then:

Lol[2, 3]


4

The syntax coloring should be fixed with the next version of Mathematica.

• If With is the answer then it is a duplicate, if OP showed only a minimal example and Module is a key here, then it is not the answer. I know you know but readers may not know why Module was replaced with With without a word of explanation. – Kuba May 24 '19 at 9:12
• @Kuba The original post refers to the "let constructs" found elsewhere. That pretty much implies a With-like approach should be used, i.e. Module should not be a key requirement. – Daniel Lichtblau May 24 '19 at 15:22
• @DanielLichtblau thanks the comment. Seems like my initial comment is still valid though. – Kuba May 27 '19 at 13:56