echo: "-n", the next installment

John Colvin john.loughran.colvin at gmail.com
Sat Jul 27 06:07:34 PDT 2013


On Saturday, 27 July 2013 at 12:59:06 UTC, monarch_dodra wrote:
> On Saturday, 27 July 2013 at 12:19:44 UTC, John Colvin wrote:
>> On Saturday, 27 July 2013 at 01:09:03 UTC, Jesse Phillips 
>> wrote:
>>> On Friday, 26 July 2013 at 00:38:46 UTC, John Colvin wrote:
>>>> After a few weeks of not getting around to it, here's my 
>>>> second post:
>>>>
>>>> http://foreach-hour-life.blogspot.co.uk/2013/07/the-first-corner-n-for-echo.html
>>>
>>> BTW, std.getopt is a good way to parse arguments. Not sure if 
>>> it is relevant to what you want to teach, but should 
>>> generally be preferred over handwritten.
>>
>> I'm pretty sure it wouldn't work ideally for echo as the 
>> behaviour depends on the order of the arguments.
>
> getopt knows how to handle ordering, it's really just a matter 
> of echo's argument parsing rules being different from classic 
> getopt.
>
> For example, echo does not handle "--" argument (end of options 
> mark), which means it is literally impossible for echo's first 
> "string argument" to be "-n".
>
> So for example, while "echo -- -n" would print "-- -n", a 
> getopt echo would print "-n".
>
> Arguably, this is better behavior, but if the goal is exact 
> replication, then it's wrong :/

Also, this wouldn't work

$ echo -E fdsa -n
fdsa -n
$

as getopt would parse the -n as an option.

Exact replication is the name of the game here, as often in the 
real world one has to write to a spec that is subtly different to 
what library writers had in mind.


More information about the Digitalmars-d-announce mailing list