Thread overview | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 07, 2013 A very basic blog about D | ||||
---|---|---|---|---|
| ||||
I had some free time so I decided I should start a simple blog about D, implementing some unix utilities. I've (unsurprisingly) started with echo. http://foreach-hour-life.blogspot.co.uk/ It's nothing ground-breaking, but every little helps :) |
July 07, 2013 Re: A very basic blog about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On 7/7/13 8:00 AM, John Colvin wrote: > I had some free time so I decided I should start a simple blog about D, > implementing some unix utilities. I've (unsurprisingly) started with echo. > > http://foreach-hour-life.blogspot.co.uk/ > > It's nothing ground-breaking, but every little helps :) Nice idea! Comments: - The imperative version writes an extra space at the end (the joiner version does not have that problem). - The echo utility has an odd way to process the cmdline: if exactly the first argument is a -n, then do not writeln at the end. - It's quite likely the joiner-based version will be slower because it writes one character at a time. (Would be great to test and discuss performance as well.) Here's a conformant implementation for reference: http://www.scs.stanford.edu/histar/src/pkg/echo/echo.c Andrei |
July 07, 2013 Re: A very basic blog about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 7/7/13 8:55 AM, Andrei Alexandrescu wrote: > Here's a conformant implementation for reference: > http://www.scs.stanford.edu/histar/src/pkg/echo/echo.c Hmm, that's actually not so good, it doesn't ensure that I/O was successful. Anyhow, here's a possibility: import std.stdout; void main(string[] args) { const appendNewline = args.length > 1 && args[1] == "-n"; foreach (i, arg; args[appendNewline + 1 .. $]) { if (i) write(' '); write(arg); } if (nl) writeln(); } But then I figured echo must do escape character processing, see e.g. http://www.raspberryginger.com/jbailey/minix/html/echo_8c-source.html. With that the blog entry would become quite interesting. Andrei |
July 07, 2013 Re: A very basic blog about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Sunday, 7 July 2013 at 15:55:31 UTC, Andrei Alexandrescu wrote: > On 7/7/13 8:00 AM, John Colvin wrote: >> I had some free time so I decided I should start a simple blog about D, >> implementing some unix utilities. I've (unsurprisingly) started with echo. >> >> http://foreach-hour-life.blogspot.co.uk/ >> >> It's nothing ground-breaking, but every little helps :) > > Nice idea! Comments: > > - The imperative version writes an extra space at the end (the joiner version does not have that problem). Woops, missed that. > - The echo utility has an odd way to process the cmdline: if exactly the first argument is a -n, then do not writeln at the end. As mentioned in the blog, i'll be covering the various flags later. > - It's quite likely the joiner-based version will be slower because it writes one character at a time. (Would be great to test and discuss performance as well.) I plan on continuing both versions through successive posts, so when they're complete I'll do a head-to-head between them, including performance. |
July 07, 2013 Re: A very basic blog about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Sunday, 7 July 2013 at 16:06:43 UTC, Andrei Alexandrescu wrote: > On 7/7/13 8:55 AM, Andrei Alexandrescu wrote: >> Here's a conformant implementation for reference: >> http://www.scs.stanford.edu/histar/src/pkg/echo/echo.c > > Hmm, that's actually not so good, it doesn't ensure that I/O was successful. Anyhow, here's a possibility: > > import std.stdout; > void main(string[] args) > { > const appendNewline = args.length > 1 && args[1] == "-n"; > foreach (i, arg; args[appendNewline + 1 .. $]) > { > if (i) write(' '); > write(arg); > } > if (nl) writeln(); > } Right structure, wrong logic? Shouldn't it be: import std.stdio; void main(string[] args) { const noNewline = args.length > 1 && args[1] == "-n"; foreach (i, arg; args[noNewline + 1 .. $]) { if (i) write(' '); write(arg); } if (!noNewline) writeln(); } or am I being dumb? > But then I figured echo must do escape character processing, see e.g. http://www.raspberryginger.com/jbailey/minix/html/echo_8c-source.html. With that the blog entry would become quite interesting. > > > Andrei Yeah, I reckon it will get quite interesting as I get in to the details. It's easy to see these basic utilities as trivial but they most certainly aren't, if you want to get them 100% right for all the options. |
July 07, 2013 Re: A very basic blog about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On 7/7/13 10:08 AM, John Colvin wrote: > On Sunday, 7 July 2013 at 16:06:43 UTC, Andrei Alexandrescu wrote: >> On 7/7/13 8:55 AM, Andrei Alexandrescu wrote: >>> Here's a conformant implementation for reference: >>> http://www.scs.stanford.edu/histar/src/pkg/echo/echo.c >> >> Hmm, that's actually not so good, it doesn't ensure that I/O was >> successful. Anyhow, here's a possibility: >> >> import std.stdout; >> void main(string[] args) >> { >> const appendNewline = args.length > 1 && args[1] == "-n"; >> foreach (i, arg; args[appendNewline + 1 .. $]) >> { >> if (i) write(' '); >> write(arg); >> } >> if (nl) writeln(); >> } > > Right structure, wrong logic? Shouldn't it be: > > import std.stdio; > void main(string[] args) > { > const noNewline = args.length > 1 && args[1] == "-n"; > foreach (i, arg; args[noNewline + 1 .. $]) > { > if (i) write(' '); > write(arg); > } > if (!noNewline) writeln(); > } > > or am I being dumb? No, I am :o). > Yeah, I reckon it will get quite interesting as I get in to the details. > It's easy to see these basic utilities as trivial but they most > certainly aren't, if you want to get them 100% right for all the options. Cool! Andrei |
July 07, 2013 Re: A very basic blog about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu, el 7 de July a las 09:06 me escribiste: > On 7/7/13 8:55 AM, Andrei Alexandrescu wrote: > >Here's a conformant implementation for reference: http://www.scs.stanford.edu/histar/src/pkg/echo/echo.c > > Hmm, that's actually not so good, it doesn't ensure that I/O was successful. Anyhow, here's a possibility: > > import std.stdout; > void main(string[] args) > { > const appendNewline = args.length > 1 && args[1] == "-n"; > foreach (i, arg; args[appendNewline + 1 .. $]) > { > if (i) write(' '); > write(arg); > } > if (nl) writeln(); > } > > But then I figured echo must do escape character processing, see > e.g. http://www.raspberryginger.com/jbailey/minix/html/echo_8c-source.html. > With that the blog entry would become quite interesting. If you want the specification, here it is :) http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html -- Leandro Lucarella (AKA luca) http://llucax.com.ar/ ---------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------- All fathers are intimidating. They're intimidating because they are fathers. Once a man has children, for the rest of his life, his attitude is, "To hell with the world, I can make my own people. I'll eat whatever I want. I'll wear whatever I want, and I'll create whoever I want." -- Jerry Seinfeld |
July 07, 2013 Re: A very basic blog about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Leandro Lucarella | On Sunday, 7 July 2013 at 20:08:19 UTC, Leandro Lucarella wrote: > Andrei Alexandrescu, el 7 de July a las 09:06 me escribiste: >> On 7/7/13 8:55 AM, Andrei Alexandrescu wrote: >> >Here's a conformant implementation for reference: >> >http://www.scs.stanford.edu/histar/src/pkg/echo/echo.c >> >> Hmm, that's actually not so good, it doesn't ensure that I/O was >> successful. Anyhow, here's a possibility: >> >> import std.stdout; >> void main(string[] args) >> { >> const appendNewline = args.length > 1 && args[1] == "-n"; >> foreach (i, arg; args[appendNewline + 1 .. $]) >> { >> if (i) write(' '); >> write(arg); >> } >> if (nl) writeln(); >> } >> >> But then I figured echo must do escape character processing, see >> e.g. http://www.raspberryginger.com/jbailey/minix/html/echo_8c-source.html. >> With that the blog entry would become quite interesting. > > If you want the specification, here it is :) > http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html I prefer this one :p http://www.gnu.org/fun/jokes/echo-msg.html From the opengroup spec: "If the first operand is -n, or if any of the operands contain a <backslash> character, the results are implementation-defined." Ah...specifications... I'm gonna stick with normal linux implementation, as described here: http://linux.die.net/man/1/echo However, on my machine, "echo --version" claims it's part of the GNU coreutils, but when you look at the coreutils docs: http://www.gnu.org/software/coreutils/manual/html_node/echo-invocation.html#echo-invocation You get the sentence "the normally-special argument ‘--’ has no special meaning and is treated like any other string.", which should preclude the identifying message being printed in the first place! |
July 08, 2013 Re: A very basic blog about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | John Colvin, el 7 de July a las 22:39 me escribiste: > On Sunday, 7 July 2013 at 20:08:19 UTC, Leandro Lucarella wrote: > >Andrei Alexandrescu, el 7 de July a las 09:06 me escribiste: > >>On 7/7/13 8:55 AM, Andrei Alexandrescu wrote: > >>>Here's a conformant implementation for reference: http://www.scs.stanford.edu/histar/src/pkg/echo/echo.c > >> > >>Hmm, that's actually not so good, it doesn't ensure that I/O was successful. Anyhow, here's a possibility: > >> > >>import std.stdout; > >>void main(string[] args) > >>{ > >> const appendNewline = args.length > 1 && args[1] == "-n"; > >> foreach (i, arg; args[appendNewline + 1 .. $]) > >> { > >> if (i) write(' '); > >> write(arg); > >> } > >> if (nl) writeln(); > >>} > >> > >>But then I figured echo must do escape character processing, see > >>e.g. http://www.raspberryginger.com/jbailey/minix/html/echo_8c-source.html. > >>With that the blog entry would become quite interesting. > > > >If you want the specification, here it is :) http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html > > I prefer this one :p http://www.gnu.org/fun/jokes/echo-msg.html > > From the opengroup spec: > "If the first operand is -n, or if any of the operands contain a > <backslash> character, the results are implementation-defined." > > Ah...specifications... > > > I'm gonna stick with normal linux implementation, as described here: http://linux.die.net/man/1/echo That's not Linux, that's GNU coreutils :) -- Leandro Lucarella (AKA luca) http://llucax.com.ar/ ---------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------- A buscar no lo voy a ir -- Rata (Pichi Traful, febrero de 2011) |
July 08, 2013 Re: A very basic blog about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Leandro Lucarella | On Monday, 8 July 2013 at 09:08:18 UTC, Leandro Lucarella wrote:
> John Colvin, el 7 de July a las 22:39 me escribiste:
>> On Sunday, 7 July 2013 at 20:08:19 UTC, Leandro Lucarella wrote:
>> >Andrei Alexandrescu, el 7 de July a las 09:06 me escribiste:
>> >>On 7/7/13 8:55 AM, Andrei Alexandrescu wrote:
>> >>>Here's a conformant implementation for reference:
>> >>>http://www.scs.stanford.edu/histar/src/pkg/echo/echo.c
>> >>
>> >>Hmm, that's actually not so good, it doesn't ensure that I/O was
>> >>successful. Anyhow, here's a possibility:
>> >>
>> >>import std.stdout;
>> >>void main(string[] args)
>> >>{
>> >> const appendNewline = args.length > 1 && args[1] == "-n";
>> >> foreach (i, arg; args[appendNewline + 1 .. $])
>> >> {
>> >> if (i) write(' ');
>> >> write(arg);
>> >> }
>> >> if (nl) writeln();
>> >>}
>> >>
>> >>But then I figured echo must do escape character processing, see
>> >>e.g. http://www.raspberryginger.com/jbailey/minix/html/echo_8c-source.html.
>> >>With that the blog entry would become quite interesting.
>> >
>> >If you want the specification, here it is :)
>> >http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html
>>
>> I prefer this one :p http://www.gnu.org/fun/jokes/echo-msg.html
>>
>> From the opengroup spec:
>> "If the first operand is -n, or if any of the operands contain a
>> <backslash> character, the results are implementation-defined."
>>
>> Ah...specifications...
>>
>>
>> I'm gonna stick with normal linux implementation, as described here:
>> http://linux.die.net/man/1/echo
>
> That's not Linux, that's GNU coreutils :)
Sue me :p Strangely, it's in direct contradiction with the GNU coreutils documentation, as hosted on the GNU site.
|
Copyright © 1999-2021 by the D Language Foundation