Skip to content

Commit

Permalink
Proposal: Variadics (#2240)
Browse files Browse the repository at this point in the history
Proposes a set of core features for declaring and implementing generic
variadic
functions.

A "pack expansion" is a syntactic unit beginning with `...`, which is a
kind of
compile-time loop over sequences called "packs". Packs are initialized
and
referred to using "pack bindings", which are marked with the `each`
keyword at
the point of declaration and the point of use.

The syntax and behavior of a pack expansion depends on its context, and
in some
cases by a keyword following the `...`:

- In a tuple literal expression (such as a function call argument list),
`...`
iteratively evaluates its operand expression, and treats the values as
    successive elements of the tuple.
- `...and` and `...or` iteratively evaluate a boolean expression,
combining
the values using `and` and `or`, and ending the loop early if the
underlying
    operator short-circuits.
-   In a statement context, `...` iteratively executes a statement.
- In a tuple literal pattern (such as a function parameter list), `...`
iteratively matches the elements of the scrutinee tuple. In conjunction
with
    pack bindings, this enables functions to take an arbitrary number of
    arguments.

---------

Co-authored-by: josh11b <[email protected]>
Co-authored-by: Richard Smith <[email protected]>
Co-authored-by: josh11b <[email protected]>
Co-authored-by: Chandler Carruth <[email protected]>
Co-authored-by: Carbon Infra Bot <[email protected]>
  • Loading branch information
6 people authored Dec 11, 2024
1 parent 14724a5 commit 8e8d570
Show file tree
Hide file tree
Showing 3 changed files with 2,092 additions and 10 deletions.
Loading

0 comments on commit 8e8d570

Please sign in to comment.