Skip to content

Commit ff36f0b

Browse files
Function signature fix for repeating arguments (#760)
* fix(signature): Enable the use of repeating parameters in lambda functions 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. * test(signature): Add tests for variadic lambda functions "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)}}`
1 parent 6092352 commit ff36f0b

File tree

7 files changed

+44
-2
lines changed

7 files changed

+44
-2
lines changed

case035.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"expr": "λ($arg1, $arg2)<n+n:o>{{\"$arg1\": $arg1, \"$arg2\": $arg2}}(1, 2, 3)",
3+
"dataset": null,
4+
"bindings": {},
5+
"result": {
6+
"$arg1": 1,
7+
"$arg2": 2
8+
}
9+
}

case036.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "λ($arg1, $arg2, $arg3)<n+s:a<n>>{[$arg1, $arg2, $arg3]}(1, 2, \"a\")",
3+
"dataset": null,
4+
"bindings": {},
5+
"result": [1, 2, "a"]
6+
}

case037.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "λ($arg1, $arg2, $arg3)<n+s-:a<n>>{[$arg1, $arg2, $arg3]}(1, 2, \"a\")",
3+
"data": "b",
4+
"bindings": {},
5+
"result": [1, 2, "a"]
6+
}

case038.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "λ($arg1, $arg2, $arg3)<n+s-:a<n>>{[$arg1, $arg2, $arg3]}(1, 2)",
3+
"data": "b",
4+
"bindings": {},
5+
"result": [1, 2, "b"]
6+
}

case039.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"expr": "λ($arg1, $arg2)<a<n>+:o>{{'$arg1': $arg1, '$arg2': $arg2}}([1, 2], [3, 4], [5, 6])",
3+
"data": "b",
4+
"bindings": {},
5+
"result": {
6+
"$arg1": [1, 2],
7+
"$arg2": [3, 4]
8+
}
9+
}

case040.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "λ($arg1, $arg2)<s?n+:a<n>>{[$arg1, $arg2]}(1, 2, 3)",
3+
"dataset": null,
4+
"bindings": {},
5+
"result": [1, 2]
6+
}

src/signature.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,15 @@ const signature = (() => {
252252
argIndex++;
253253
}
254254
} else {
255-
// may have matched multiple args (if the regex ends with a '+'
255+
// may have matched multiple args (if the regex ends with a '+')
256256
// split into single tokens
257257
match.split('').forEach(function (single) {
258+
arg = args[argIndex];
258259
if (param.type === 'a') {
259260
if (single === 'm') {
260261
// missing (undefined)
261262
arg = undefined;
262263
} else {
263-
arg = args[argIndex];
264264
var arrayOK = true;
265265
// is there type information on the contents of the array?
266266
if (typeof param.subtype !== 'undefined') {

0 commit comments

Comments
 (0)