quarkdown icon indicating copy to clipboard operation
quarkdown copied to clipboard

[BUG] Subtraction not working when using positional argument + named argument

Open imLymei opened this issue 1 year ago • 5 comments

Description

Subtraction function does not work while using argument + named argument. If this should be the case, the error message should be updated.

With named argument

.var {a} {15}
.var {b} {8}

- Addition: .a + .b = **.sum {.a} {.b}**
- Subtraction: .a - .b = **.subtract {.a} from:{.b}**

Image

Without named argument

.var {a} {15}
.var {b} {8}

- Addition: .a + .b = **.sum {.a} {.b}**
- Subtraction: .a - .b = **.subtract {.a} {.b}**

Image

imLymei avatar Jun 05 '25 20:06 imLymei

Hi @imLymei, thank you for reporting. That's possibly because .subtract's from parameter is the second one, positionally speaking. The issue can be generalized to an incorrect binding when mixing positional and named arguments.

As a side note, coincidentally enough, I already planned to remove the name from to avoid confusion, but I didn't really think of your approach.

iamgio avatar Jun 05 '25 20:06 iamgio

I believe you would also be interested in the function call chaining syntax: for instance .sum {.a} {.b} can be rewritten as .a::sum {.b}.

iamgio avatar Jun 05 '25 20:06 iamgio

Okay, after some thinking I realized your proposed syntax could be ambiguous. Consider the function signature f(a, b), then calling .f {0} a:{1} would be confusing for both the compiler and humans. I will just provide a clearer error message.

iamgio avatar Jun 05 '25 21:06 iamgio

Done!

New message when calling .subtract {1} from:{3}:

Cannot call function subtract(Number from, Number b) with arguments (1, 3): parameter 'from' is already bound, but was attempted to be bound again to 3

iamgio avatar Jun 05 '25 21:06 iamgio

I believe you would also be interested in the function call chaining syntax: for instance .sum {.a} {.b} can be rewritten as .a::sum {.b}.

THANKS! That's definitely better!

imLymei avatar Jun 05 '25 22:06 imLymei