digitalmars.D - Scriptometer
- bearophile (5/5) Nov 03 2010 This is a comparison, how much good various languages are for scripting ...
- Kagamin (2/6) Nov 03 2010 I remember llvm's configure script...
- Kagamin (2/3) Nov 03 2010 Oh, no, not llvm's, but mingw's.
- =?iso-8859-2?B?VG9tZWsgU293afFza2k=?= (11/17) Nov 03 2010 g =
- bearophile (6/11) Nov 03 2010 Adding a struct like the Python fileinput to std.stdio of Phobos?
- =?iso-8859-2?B?VG9tZWsgU293afFza2k=?= (79/81) Nov 04 2010 Good idea. I must say it was fun writing "scripts" in D. They could use ...
- bearophile (30/45) Nov 04 2010 void main() {}
- =?iso-8859-2?B?VG9tZWsgU293afFza2k=?= (8/17) Nov 04 2010 =
- retard (10/27) Nov 04 2010 FWIW, the other code on the site didn't seem that unreadable. Cheating i...
- bearophile (4/12) Nov 04 2010 Are those shortcuts currently present in the D standard library? No, the...
- retard (8/25) Nov 04 2010 Such a layer is more or less doable in just about any sane language, in
- spir (9/10) Nov 05 2010 ious, they aren't for a D newbie. I may even suggest to put them in the ...
- spir (9/11) Nov 05 2010 =20
- Lutger (7/24) Nov 03 2010 Here is a quick attempt:
- bearophile (5/13) Nov 03 2010 It's cute. Compared to the Python version it doesn't work lazily (by lin...
- Jesse Phillips (3/20) Nov 03 2010 Disagree completely. The task was to remove comment lines, not properly ...
This is a comparison, how much good various languages are for scripting purposes: http://rigaux.org/language-study/scripting-language/ This test may be good both to see if there is something essential missing in Phobos2 and to see how D2 is fit for those purposes (the list contains some Bye, bearophile
Nov 03 2010
bearophile Wrote:This is a comparison, how much good various languages are for scripting purposes: http://rigaux.org/language-study/scripting-language/ This test may be good both to see if there is something essential missing in Phobos2 and to see how D2 is fit for those purposes (the list contains someI remember llvm's configure script...
Nov 03 2010
Kagamin Wrote:I remember llvm's configure script...Oh, no, not llvm's, but mingw's.
Nov 03 2010
Dnia 03-11-2010 o 21:27:00 bearophile <bearophileHUGS lycos.com> = napisa=B3(a):This is a comparison, how much good various languages are for scriptin=g =purposes: http://rigaux.org/language-study/scripting-language/ This test may be good both to see if there is something essential =missing in Phobos2 and to see how D2 is fit for those purposes (the li=st =Nice page. I submitted some "scripts" so D will be featured on it. (modifying the file, i.e. in place): http://rigaux.org/language-study/scripting-language/#sed_in_place Any idea how to pull it off nicely? -- = Tomek
Nov 03 2010
Tomek S.:Nice page. I submitted some "scripts" so D will be featured on it.You may show them here too.(modifying the file, i.e. in place): http://rigaux.org/language-study/scripting-language/#sed_in_place Any idea how to pull it off nicely?Adding a struct like the Python fileinput to std.stdio of Phobos? http://docs.python.org/library/fileinput.html Bye, bearophile
Nov 03 2010
bearophile napisa=B3(a):Good idea. I must say it was fun writing "scripts" in D. They could use = = community sandblasting before publishing. Remember, the aim is to write = = the smallest program possible, so optimize character count (contiguous = whitespaces count as 1). smallest - the smallest running program doing nothing: void main(){} hello world - print a simple string on stdout: import std.stdio; void main(){writeln("Hello World");} argv - access command line parameters (no segmentation fault accepted, n= or = silent exception, so some languages must explicitly check the presence o= f = the argument): import std.stdio; void main(string[] a){if(a.length>1)writeln(a[1]);} env - access environment variable: import std.stdio,std.process; void main(){writeln(getenv("HOME"));} test file exists - return exit code error (non zero) if a file does not = = exist: import std.file; int main(){return !exists("/etc/mtab");} test file readable - return exit code error (non zero) if a file is not = = readable: import std.stdio; void main(){File("/etc/mtab");} formatting - print integers in a simple formatted string: import std.stdio; void main(){int a=3D1,b=3D2;writefln("%s + %s =3D %s",a,b,a+b);} system - call an external program and check the return value: import std.stdio,std.process; void main(){if(system("false")) stderr.writeln("false failed"); = writeln("done");} n = place): import std.file,std.regex; "g"), ""));} compile what must be - find and compile .c files into .o when the .o is = = old or absent: import std.stdio,std.file,std.process; void main(){ foreach(c;listdir("","*.c")){ auto o=3Dc[0..$-1]~'o'; if(lastModified(o,0)<lastModified(c)) { writefln("compiling %s to %s",c,o); system("gcc -c -o '"~c~"' '"~o~"'"); } } } grep - grep with -F -i -h handling, usage, grep'ing many files: import std.stdio,std.array,std.regex; int main(string[] a){ auto o=3D["-h":0,"-F":0,"-i":0]; while(!(a=3Da[1..$]).empty) { if(auto b=3Da[0] in o) *b=3D1; else break; } if(!a.length||o["-h"]){ writeln("usage: grep [-F] [-i] regexp [files...]"); return 1; } auto e=3Do["-F"]?a[0].replace(regex(r"\W","g"),r"\$&"):a[0]; foreach(f;a[1..$]) foreach(l;File(f).byLine()) if(!l.match(regex(e,o["-i"]?"i":"")).empty) writeln(f,':',l); return 0; } -- = TomekNice page. I submitted some "scripts" so D will be featured on it.You may show them here too.
Nov 04 2010
Tomek S.:Remember, the aim is to write the smallest program possible, so optimize character count (contiguous whitespaces count as 1).But I suggest to not overdo it. Minimizing char count doesn't justify writing space-free programs. So I suggest to add spaces and newlines where they belong to increase readability a little.void main(){}void main() {}import std.stdio; void main(){writeln("Hello World");}import std.stdio; void main() { writeln("Hello World"); }import std.stdio; void main(string[] a){if(a.length>1)writeln(a[1]);}import std.stdio; void main(string[] args) { if (args.length > 1) writeln(args[1]); } And similar formatting/spacing for all the successive examples.formatting - print integers in a simple formatted string: import std.stdio; void main(){int a=1,b=2;writefln("%s + %s = %s",a,b,a+b);}writeln usage is shorter (see the Python version): import std.stdio; void main() { int a=1, b=2; writeln(a, " + ", b, " = ", a+b); }system - call an external program and check the return value: import std.stdio,std.process; void main(){if(system("false")) stderr.writeln("false failed"); writeln("done");}The other programs (Python too) use echo, not normal printing, so I suggest (untested): import std.stdio, std.process; void main() { if (system("false")) stderr.writeln("false failed"); system("echo done"); } Thank you for your work. Even if such little programs look simple and obvious, they aren't for a D newbie. I may even suggest to put them in the D examples or in the D wiki, etc (in Rosettacode site too I have written a ton of D implementations of many different kinds of programs, usually a little longer). In my opinion the D home page has to show a nice link to Ideone and codepad because they allow to compile and run D code on the web. Bye, bearophile
Nov 04 2010
Dnia 04-11-2010 o 22:13:12 bearophile <bearophileHUGS lycos.com> = napisa=B3(a):But I suggest to not overdo it. Minimizing char count doesn't justify ==writing space-free programs. So I suggest to add spaces and newlines =where they belong to increase readability a little.I admit I even wanted to use write, not writeln, to save 2 chars. Hell, = = this is WAR; goal justifies means. :-) -- = Tomekimport std.stdio; void main(){writeln("Hello World");}import std.stdio; void main() { writeln("Hello World"); }
Nov 04 2010
Thu, 04 Nov 2010 23:09:47 +0100, Tomek Sowiński wrote:Dnia 04-11-2010 o 22:13:12 bearophile <bearophileHUGS lycos.com> napisał(a):FWIW, the other code on the site didn't seem that unreadable. Cheating is not fair. I should also mention that you can change all of these languages quite a bit with a special library crafted for this purpose. If you want to use D for bash style scripting, it's very possible to provide a clean set of shortcut methods and use method "chaining" (e.g. directory.findAllMatching ("foo").filter("bar").copy("floppy drive") ) Since a trivial library would change the results that much, I find this scriptometer quite pointless..But I suggest to not overdo it. Minimizing char count doesn't justify writing space-free programs. So I suggest to add spaces and newlines where they belong to increase readability a little.I admit I even wanted to use write, not writeln, to save 2 chars. Hell, this is WAR; goal justifies means. :-)import std.stdio; void main(){writeln("Hello World");}import std.stdio; void main() { writeln("Hello World"); }
Nov 04 2010
retard:I should also mention that you can change all of these languages quite a bit with a special library crafted for this purpose. If you want to use D for bash style scripting, it's very possible to provide a clean set of shortcut methods and use method "chaining" (e.g. directory.findAllMatching ("foo").filter("bar").copy("floppy drive") ) Since a trivial library would change the results that much, I find this scriptometer quite pointless..Are those shortcuts currently present in the D standard library? No, they aren't. So it's not a pointless comparison. The purpose of that comparison is to show how much good a language+library is for those scripting purposes. Python is good because it has batteries included. Perl is "good" because it has CPAN. Both languages are usable for those scripting purposes. Bye, bearophile
Nov 04 2010
Thu, 04 Nov 2010 21:32:14 -0400, bearophile wrote:retard:Such a layer is more or less doable in just about any sane language, in very short time. This "meter" shouldn't be the guideline for the standard library if we are discussing a general purpose language such as D. Remember Tangobos - this one is much simpler. This one library can improve the score on that test much more than any specific language feature. Unlike the great language shootout, it's unlikely that many have the motivation to spend the second time studying this.I should also mention that you can change all of these languages quite a bit with a special library crafted for this purpose. If you want to use D for bash style scripting, it's very possible to provide a clean set of shortcut methods and use method "chaining" (e.g. directory.findAllMatching ("foo").filter("bar").copy("floppy drive") ) Since a trivial library would change the results that much, I find this scriptometer quite pointless..Are those shortcuts currently present in the D standard library? No, they aren't. So it's not a pointless comparison. The purpose of that comparison is to show how much good a language+library is for those scripting purposes. Python is good because it has batteries included. Perl is "good" because it has CPAN. Both languages are usable for those scripting purposes.
Nov 04 2010
On Thu, 04 Nov 2010 17:13:12 -0400 bearophile <bearophileHUGS lycos.com> wrote:Thank you for your work. Even if such little programs look simple and obv=ious, they aren't for a D newbie. I may even suggest to put them in the D e= xamples or in the D wiki, etc=20 +++ Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.com
Nov 05 2010
On Thu, 04 Nov 2010 21:52:04 +0100 Tomek Sowi=C5=84ski <just ask.me> wrote:Good idea. I must say it was fun writing "scripts" in D. They could use ==20community sandblasting before publishing.This list is a great source of D idioms for newcomers. Thank you very much = (I'll keep it for reference.) Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.com
Nov 05 2010
Tomek Sowiński wrote:Dnia 03-11-2010 o 21:27:00 bearophile <bearophileHUGS lycos.com> napisał(a):Here is a quick attempt: import std.file, std.regex; void main(string[] args) { }This is a comparison, how much good various languages are for scripting purposes: http://rigaux.org/language-study/scripting-language/ This test may be good both to see if there is something essential missing in Phobos2 and to see how D2 is fit for those purposes (the listNice page. I submitted some "scripts" so D will be featured on it. (modifying the file, i.e. in place): http://rigaux.org/language-study/scripting-language/#sed_in_place Any idea how to pull it off nicely?
Nov 03 2010
Lutger:Here is a quick attempt: import std.file, std.regex; void main(string[] args) { }It's cute. Compared to the Python version it doesn't work lazily (by lines). I have tried on Windows that D program and the Python program on a text file that has Unix newlines. The Python program has produced an output with Windows newlines, while the D program has produced an output with Unix newlines. I think Python is more correct here. Bye, bearophile
Nov 03 2010
bearophile Wrote:Lutger:Disagree completely. The task was to remove comment lines, not properly format line endings for the OS running. I don't think laziness has any benefit here.Here is a quick attempt: import std.file, std.regex; void main(string[] args) { }It's cute. Compared to the Python version it doesn't work lazily (by lines). I have tried on Windows that D program and the Python program on a text file that has Unix newlines. The Python program has produced an output with Windows newlines, while the D program has produced an output with Unix newlines. I think Python is more correct here. Bye, bearophile
Nov 03 2010