Stream: ideas

Topic: underscore as lambda sugar?


view this post on Zulip jan kili (Mar 02 2025 at 16:18):

Richard Feldman said:

an easy fix would be changing accessor syntax to be _.b

Should field access be unique or should we generalize this to "a single underscore in an expression is sugar for unique_name with an expression prefix of |unique_name|"?

foo(_.bar)

foo(_.bar())

foo(_.bar.baz)

foo(_.bar + 1)

foo(bar + _ * 2)

view this post on Zulip Richard Feldman (Mar 02 2025 at 16:40):

I don't want to scope creep into that

view this post on Zulip Richard Feldman (Mar 02 2025 at 16:43):

Scala does this and it would be a very big change to how Roc code looks - the last two examples there being the tip of the iceberg

view this post on Zulip Richard Feldman (Mar 02 2025 at 17:33):

this is the sort of feature that needs to start with a specific pain point, like "______ feels painful to read, and something like _ would make it a lot nicer to read" and then we can weigh that upside against the downsides :big_smile:

view this post on Zulip Richard Feldman (Mar 02 2025 at 17:34):

because I don't think consistency is enough of a reason to do this

view this post on Zulip Brendan Hansknecht (Mar 02 2025 at 18:35):

Yeah, this feature has definitely been ask for and pushed back against for anonymous lambdas before.


Last updated: Jun 16 2026 at 16:19 UTC