Apply method with curly braces

前端 未结 2 1411
感动是毒
感动是毒 2021-01-15 03:05

Why this works:

  List(
   \"string\", \"string2\"
  )

But this doesn\'t?

  List{
   \"string\", \"string2\"
  }

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-15 03:48

    Canonical answer on braces and a supplement.

    The official glossary helpfully calls a block an encapsulation of side effects and a result value.

    A few opinions were recently expressed on the ML about braces and their non-pointy cousins.

    Perhaps it is unhelpful to think of parens and braces as somehow interchangeable in some contexts.

    It is easier to think in terms of exprs and blocks, and in this case, function args can be either comma-separated exprs or a block.

提交回复
热议问题