Thread overview | ||||||
---|---|---|---|---|---|---|
|
September 13, 2020 praise: optional comma at the end of argument list is a life saver for generated code | ||||
---|---|---|---|---|
| ||||
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 Re: praise: optional comma at the end of argument list is a life saver for generated code | ||||
---|---|---|---|---|
| ||||
Posted in reply to mw | 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 Re: praise: optional comma at the end of argument list is a life saver for generated code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | 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 Re: praise: optional comma at the end of argument list is a life saver for generated code | ||||
---|---|---|---|---|
| ||||
Posted in reply to mw | 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,
}
---
|
Copyright © 1999-2021 by the D Language Foundation