Skip to content

Conversation

@Turings98apprentice
Copy link

Before this change, a function signature containing a repeating symbol (eg. <n+>) would copy the first of those arguments into every matching parameter instead of copying each argument to each parameter respectively.

Example:

function($a1, $a2)<n+> {
    [$a1, $a2]
}(1, 2)

returns [1, 1] instead of [1, 2].

This fix modifies the behavior to match what's expected*:

function($n1, $n2, $n3, $s)<n+s> {
    {
        $s: [$n1, $n2, $n3]
    }
}(3, 7, 31, 'Mersenne primes')

now yields

{
    "Mersenne primes": [
        3,
        7,
        31
    ]
}

*One important note here is that this implementation doesn't actually support an arbitrary number of arguments, only as many as the number of parameters you're willing to add to your function. I tried to change as little as possible while still squashing the bug.


Relatedly, I would recommend a breaking change that would bind each repeating parameter to an array of its provided arguments. Then, you could write something like this:

function($nums, $str)<n+s> {
    {
        $str: $count($nums)
    }
}(1, 2, 3, 4, 5, 'Number of arguments')

which would yield

{
    "Number of arguments": 5
}

Signed-off-by: Brandon Peterson [email protected]

…tions

Before this change, a function signature containing a repeating symbol (eg. <n+>) would copy the first of those arguments into every matching parameter (eg. `function($a1, $a2)<n+>{[$a1, $a2]}(1, 2)` returns [1, 1] instead of [1, 2]) instead of copying each argument to each parameter respectively.
"Variadic" just means a function can take an arbitrary number of arguments (eg. <n+>).

One important note here is that this implementation doesn't actually support an arbitrary number of arguments, only as many as the number of parameters you're willing to add to your function. I tried to change as little as possible while still squashing the bug.

I would recommend a breaking change that would bind each repeating parameter to an array of its provided arguments. Then, you could write something like this: `function($nums, $str)<n+s>{{$str: $count($nums)}}`
@Turings98apprentice Turings98apprentice changed the title Function signature fix Function signature fix for repeating arguments Oct 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant