Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
January 26, 2017 Bug in documentation or misunderstanding it? | ||||
---|---|---|---|---|
| ||||
I read docs and can't understand what's wrong. Or I am do not understand it, or there is come mistake. Let's look at function https://dlang.org/phobos/std_stdio.html#.File.byLine auto byLine(Terminator = char, Char = char)(KeepTerminator keepTerminator = No.keepTerminator, Terminator terminator = '\x0a') what does mean first groups of scope: (Terminator = char, Char = char) ? The second one as I understand it's options symbol `=` mean that there is some default values, so if I will call function I can do not set them, so predefined values will be used. Am I right? And If I do not want predefined I can pass my own like: `byLine(No.keepTerminator, 'SomeLetter')` for example: `file.byLine(No.keepTerminator, 'a')` But when I compile simple example I am getting compilation error: `undefined identifier 'No'` Where I am wrong? |
January 26, 2017 Re: Bug in documentation or misunderstanding it? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | On Thursday, 26 January 2017 at 17:38:59 UTC, Suliman wrote:
> I read docs and can't understand what's wrong. Or I am do not understand it, or there is come mistake.
>
> [...]
You have to import typecons.
|
January 26, 2017 Re: Bug in documentation or misunderstanding it? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | On Thu, Jan 26, 2017 at 05:38:59PM +0000, Suliman via Digitalmars-d-learn wrote: > I read docs and can't understand what's wrong. Or I am do not understand it, or there is come mistake. > > Let's look at function https://dlang.org/phobos/std_stdio.html#.File.byLine > > auto byLine(Terminator = char, Char = char)(KeepTerminator keepTerminator = > No.keepTerminator, Terminator terminator = '\x0a') > > what does mean first groups of scope: (Terminator = char, Char = char) ? Those are compile-time parameters. You specify them in a compile-time argument list using the !(...) construct, for example: auto lines = File("myfile.txt") .byLine!(dchar, char)(Yes.keepTerminator, '\u263a'); T -- If lightning were to ever strike an orchestra, it'd always hit the conductor first. |
January 26, 2017 Re: Bug in documentation or misunderstanding it? | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On Thursday, 26 January 2017 at 17:52:24 UTC, H. S. Teoh wrote:
> On Thu, Jan 26, 2017 at 05:38:59PM +0000, Suliman via Digitalmars-d-learn wrote:
>> I read docs and can't understand what's wrong. Or I am do not understand it, or there is come mistake.
>>
>> Let's look at function https://dlang.org/phobos/std_stdio.html#.File.byLine
>>
>> auto byLine(Terminator = char, Char = char)(KeepTerminator keepTerminator =
>> No.keepTerminator, Terminator terminator = '\x0a')
>>
>> what does mean first groups of scope: (Terminator = char, Char = char) ?
>
> Those are compile-time parameters. You specify them in a compile-time argument list using the !(...) construct, for example:
>
> auto lines = File("myfile.txt")
> .byLine!(dchar, char)(Yes.keepTerminator, '\u263a');
>
>
> T
So I am right about others items about for example that `=` is optional?
|
January 26, 2017 Re: Bug in documentation or misunderstanding it? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | On Thursday, 26 January 2017 at 18:42:29 UTC, Suliman wrote: > On Thursday, 26 January 2017 at 17:52:24 UTC, H. S. Teoh wrote: >> On Thu, Jan 26, 2017 at 05:38:59PM +0000, Suliman via Digitalmars-d-learn wrote: >>> I read docs and can't understand what's wrong. Or I am do not understand it, or there is come mistake. >>> >>> Let's look at function https://dlang.org/phobos/std_stdio.html#.File.byLine >>> >>> auto byLine(Terminator = char, Char = char)(KeepTerminator keepTerminator = >>> No.keepTerminator, Terminator terminator = '\x0a') >>> >>> what does mean first groups of scope: (Terminator = char, Char = char) ? >> >> Those are compile-time parameters. You specify them in a compile-time argument list using the !(...) construct, for example: >> >> auto lines = File("myfile.txt") >> .byLine!(dchar, char)(Yes.keepTerminator, '\u263a'); >> >> >> T > > So I am right about others items about for example that `=` is optional? Why this code is work: `file.byLine(KeepTerminator.no, 'm')` |
January 27, 2017 Re: Bug in documentation or misunderstanding it? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | On Thu, Jan 26, 2017 at 06:47:21PM +0000, Suliman via Digitalmars-d-learn wrote: > On Thursday, 26 January 2017 at 18:42:29 UTC, Suliman wrote: > > On Thursday, 26 January 2017 at 17:52:24 UTC, H. S. Teoh wrote: > > > On Thu, Jan 26, 2017 at 05:38:59PM +0000, Suliman via Digitalmars-d-learn wrote: > > > > I read docs and can't understand what's wrong. Or I am do not understand it, or there is come mistake. > > > > > > > > Let's look at function https://dlang.org/phobos/std_stdio.html#.File.byLine > > > > > > > > auto byLine(Terminator = char, Char = char)(KeepTerminator > > > > keepTerminator = No.keepTerminator, Terminator terminator = > > > > '\x0a') > > > > > > > > what does mean first groups of scope: (Terminator = char, Char = > > > > char) ? > > > > > > Those are compile-time parameters. You specify them in a compile-time argument list using the !(...) construct, for example: > > > > > > auto lines = File("myfile.txt") > > > .byLine!(dchar, char)(Yes.keepTerminator, '\u263a'); > > > > > > > > > T > > > > So I am right about others items about for example that `=` is optional? > > Why this code is work: `file.byLine(KeepTerminator.no, 'm')` Yes, the `=` means the parameter has a default value. This applies to both compile-time parameters and runtime parameters. So: file.byLine(KeepTerminator.no); is the same as: file.byLine!(char, char)(No.keepTerminator, '\x0a'); T -- There are 10 kinds of people in the world: those who can count in binary, and those who can't. |
Copyright © 1999-2021 by the D Language Foundation