Thread overview
praise: optional comma at the end of argument list is a life saver for generated code
Sep 13, 2020
mw
Sep 13, 2020
Ali Çehreli
Sep 14, 2020
DlangUser38
September 13, 2020
I'm referring to this:

https://github.com/mingwugmail/talibd/blob/master/source/talibd.d#L109

 int lookback = TA_MACD_Lookback(optInFastPeriod,optInSlowPeriod,optInSignalPeriod,);


D compiler accept (but ignore) the last comma "," is a life saver for generated code.

Otherwise, one have to find new ways to remove it which is a nuisance.


(The generating C macro in this case, are defined as:

#define SPLIT_THEN_TAKE_VAR(X)     SPLIT(TAKE_VAR,   X),

  int lookback = TA_FUNC##_Lookback(FOR_EACH(SPLIT_THEN_TAKE_VAR, FUNC_INS)); __NL__\

https://github.com/mingwugmail/talibd/blob/master/source/talibd.h#L121
https://github.com/mingwugmail/talibd/blob/master/source/talibd.h#L60
)


September 13, 2020
Yes, accepting that trailing comma is very useful in many contexts.

Related, I use std.format's %( and %) specifiers, which automatically remove the extra delimiters at the end:

import std.stdio;

void main() {
  writefln!"%(%s, %)"([1, 2, 3]);
}

Prints

1, 2, 3

When we want, we can use %| to mean "keep the delimiters up to this place":

  writefln!"%(%s,%| %)"([1, 2, 3]);

Now the comma is printed as well but not the following space:

1, 2, 3,

I wish it had an additional feature where we could say "use this delimiter before the last one" so we could inject e.g. and "and":

1, 2, and 3

As far as I know, it doesn't exist.

Ali

September 14, 2020
On Sunday, 13 September 2020 at 19:28:05 UTC, Ali Çehreli wrote:
> I wish it had an additional feature where we could say "use this delimiter before the last one" so we could inject e.g. and "and":
>
> 1, 2, and 3
>
> As far as I know, it doesn't exist.
And it would still not be sufficient, as e.g. German would need to remove also the comma before the and: "1, 2, 3 und 4"
September 14, 2020
On Sunday, 13 September 2020 at 18:57:14 UTC, mw wrote:
> I'm referring to this:
>
> https://github.com/mingwugmail/talibd/blob/master/source/talibd.d#L109
>
>  int lookback = TA_MACD_Lookback(optInFastPeriod,optInSlowPeriod,optInSignalPeriod,);
>
>
> D compiler accept (but ignore) the last comma "," is a life saver for generated code.
>
> Otherwise, one have to find new ways to remove it which is a nuisance.
>
>
> (The generating C macro in this case, are defined as:
>
> #define SPLIT_THEN_TAKE_VAR(X)     SPLIT(TAKE_VAR,   X),
>
>   int lookback = TA_FUNC##_Lookback(FOR_EACH(SPLIT_THEN_TAKE_VAR, FUNC_INS)); __NL__\
>
> https://github.com/mingwugmail/talibd/blob/master/source/talibd.h#L121
> https://github.com/mingwugmail/talibd/blob/master/source/talibd.h#L60
> )

yeah it's okish. Also good for git diff, for example when you add a member to an enum then you only have one line modified instead of two.

---
enum Foo
{
   f1
}

enum Foo
{
-   f1
+   f1,
+   f2
}
---

now in D you can just have

---
enum Foo
{
   f1,
}

enum Foo
{
    f1,
+   f2,
}
---