the D scripting language -- command line

sop phobos at std.s
Thu Nov 11 04:45:05 PST 2010


ruben niemann Wrote:

> spir Wrote:
> 
> > [started separate thread]
> > 
> > On Thu, 11 Nov 2010 00:58:31 +0100
> > Tomek Sowiński <just at ask.me> wrote:
> > 
> > > Andrei Alexandrescu napisał:
> > > 
> > > >> 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.
> > > > 
> > > > Not getting the example. How would anonymous options work?
> > > 
> > > // Let's match assignments.
> > > auto args = ["program.exe", ".*=.*;", "file1.d", "file2.d", "file3.d"];
> > > bool h, i; string expr; string[] files;
> > > getopt(args, "h",&h, "i",&i, &expr, &files);
> > > assert(!h);
> > > assert(!i);
> > > assert(expr == ".*=.*;");
> > > assert(files == ["file1.d", "file2.d", "file3.d"]);
> > > assert(args == ["program.exe"]);
> > > 
> > > Staying conservative, anonymous options would only be allowed at the end of the 
> > > option list, because their order matters (unlike named options). Perhaps this can 
> > > be relaxed with time.
> > 
> > I thought once at a default interface between the command-line and a program's startup routine, main(). The idea would be for main to have parameters automagically fed from whatever the user provides. With a command-line syntax inspired by named func call. It lets the program itself be called more or less like a func, via program-level parameter definition:
> > 
> >  // program "findword"
> >  int main (string filename, string word, bool verbose=false) {...}
> > 
> >  // use it
> >  $ findword filename=foo.txt word=foo verbose=true
> > 
> > Parameters having default value can indeed be omitted by the user. Optionally, the first arg (often corresponding to the "object" on which a command applies, like the receiver in OO, and thus usually "obvious") can be automatically mapped to the first param of main:
> > 
> >  $ findword foo.txt word=foo
> > 
> > This is, indeed, a language-specific feature. On the other hand, it brings to the user consistent program-call format -- rather than each program defining its own. Maybe after sometime the same syntax trick and syntax would adopted by other languages.
> > I find this very coool on the programmer side as well. It must indeed by implemented in the language('s runtime) itself. To have such a feature without breaking any code, a possibility may be to use a different name than "main", eg "script".
> > (I guess such a feature would make some difference in judging a language's adequacy to scripting.)
> > 
> > What do you think?
> 
> That's a nifty feature.
> 
> I took a look at the scriptometer page. It looks like if more real scripting languages are coming there (one or two more), D will be out from the top-20. The script library and shortcuts are badly needed. D isn't (yet) even the best static compiled language in the test. At least two Java/JVM languages beat D and it doesn't yet even have the super tight Groovy. It's also still missing Clojure, Io, Factor, and those other "tight" languages.
> 
> Looking bad without a dedicated library. The library might be good to contain features 'sed', 'grep', and fill the namespace with name globals. std.s sounds like a good name.
 Indeed. The many feces of d doesnt include sop " script oriented prog...


More information about the Digitalmars-d mailing list