Re: T... args!

2022-04-29 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 30 April 2022 at 02:22:22 UTC, Tejas wrote: On Friday, 29 April 2022 at 16:10:52 UTC, Salih Dincer wrote: On Friday, 29 April 2022 at 12:57:15 UTC, Steven Schveighoffer wrote: [...] I see, think it can be done with mixin: ```d template prn(alias args) { string prn() {

Re: T... args!

2022-04-29 Thread Tejas via Digitalmars-d-learn
On Friday, 29 April 2022 at 16:10:52 UTC, Salih Dincer wrote: On Friday, 29 April 2022 at 12:57:15 UTC, Steven Schveighoffer wrote: [...] I see, think it can be done with mixin: ```d template prn(alias args) { string prn() { string result = "write("; foreach(s; args.split("|"))

Re: T... args!

2022-04-29 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 29 April 2022 at 12:57:15 UTC, Steven Schveighoffer wrote: There is no string interpolation in D. You can use a function such as `std.conv.text` to produce a string given interleaving strings and items. Or you can use `std.format.format` to make it happen. I see, think it can be

Re: T... args!

2022-04-29 Thread Dennis via Digitalmars-d-learn
On Friday, 29 April 2022 at 15:13:08 UTC, Tejas wrote: It's not a keyword yet it's recognised specially by the compiler... What? It's not really recognized by the compiler, there's a little bit of magic to print `string` in outputted D code (e.g. error messages) instead of

Re: T... args!

2022-04-29 Thread Tejas via Digitalmars-d-learn
On Friday, 29 April 2022 at 12:57:15 UTC, Steven Schveighoffer wrote: On 4/28/22 10:48 PM, Salih Dincer wrote: [...] There is no string interpolation in D. You can use a function such as `std.conv.text` to produce a string given interleaving strings and items. Or you can use

Re: T... args!

2022-04-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/28/22 10:48 PM, Salih Dincer wrote: On Thursday, 9 December 2021 at 14:34:58 UTC, Steven Schveighoffer wrote: You may want to post what you want to achieve with your code, instead of examples of what you tried, and it may allow us to make things clearer. You are likely using the wrong

Re: T... args!

2022-04-28 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 9 December 2021 at 14:34:58 UTC, Steven Schveighoffer wrote: You may want to post what you want to achieve with your code, instead of examples of what you tried, and it may allow us to make things clearer. You are likely using the wrong construct to achieve your goals. -Steve

Re: T... args!

2021-12-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/8/21 7:36 PM, Salih Dincer wrote: On Wednesday, 8 December 2021 at 23:47:07 UTC, Adam Ruppe wrote: On Wednesday, 8 December 2021 at 23:43:48 UTC, Salih Dincer wrote: I think you meant to say void foo(string[] args...) {} Not exactly... ```d alias str = immutable(char)[]; void

Re: T... args!

2021-12-09 Thread Petar via Digitalmars-d-learn
On Thursday, 9 December 2021 at 00:36:29 UTC, Salih Dincer wrote: On Wednesday, 8 December 2021 at 23:47:07 UTC, Adam Ruppe wrote: On Wednesday, 8 December 2021 at 23:43:48 UTC, Salih Dincer wrote: I think you meant to say void foo(string[] args...) {} Not exactly... ```d alias str =

Re: T... args!

2021-12-08 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 23:47:07 UTC, Adam Ruppe wrote: On Wednesday, 8 December 2021 at 23:43:48 UTC, Salih Dincer wrote: I think you meant to say void foo(string[] args...) {} Not exactly... ```d alias str = immutable(char)[]; void foo(str...)(str args) { foreach(ref a; args)

Re: T... args!

2021-12-08 Thread Adam Ruppe via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 23:43:48 UTC, Salih Dincer wrote: Is this not a contradiction? : and 3.1415 aren't string: ```d void foo(string...)(string args) { `string...` there is a user-defined identifier representing a mix of types. string isn't special, yo can declare your own

T... args!

2021-12-08 Thread Salih Dincer via Digitalmars-d-learn
Hi all, Is this not a contradiction? : and 3.1415 aren't string: ```d void foo(string...)(string args) { foreach(ref str; args) { str.writeln('\t', typeof(str).stringof); } } foo("Pi", "number", ':', 3.1415); /* Pi string number string : char 3,1415 double