The D Scripting Language
Tomek Sowiński
just at ask.me
Wed Nov 10 13:45:20 PST 2010
Andrei Alexandrescu napisał:
>> I'm having trouble thinking of something that would go in this module
>> that wouldn't be a better fit somewhere else. What do you envision?
>
> I thought of it for a bit, but couldn't come up with anything :o). I
> think you're right!
Yeah, I think std.all would be just fine, or as Pelle proposed, a module publicly importing a first-aid kit for scripting.
> Someone proposed to add something like
> http://docs.python.org/library/fileinput.html to Phobos. I think it's a
> good idea. We have all mechanics in place (byLine/byChunk, chain). So it
> should be easy to define byLine to accept an array of filenames:
>
> import std.stdio;
> void main(string args[]) {
> getopt(args, ...);
Speaking of getopt, when writing the 'grep' snippet I missed anonymous options a lot:
bool h, i; string expr; string[] files;
getopt(args, "h",&h, "i",&i, &expr, &files);
They can be implemented with relatively little effort.
> foreach (line; File.byLine(args[1 .. $]) {
> ...
> }
> }
>
> I hypothetically made byLine a static method inside File to avoid
> confusing beginners (one might think on first read that byLine goes line
> by line through an array of strings).
The hipothetical version gave me exactly this impression. Moreover, the element type should be tuple(line, current file
name or a pointer to File). So maybe File.byFileLine(...)?
--
Tomek
More information about the Digitalmars-d
mailing list