digitalmars.D - The D Scripting Language
- =?iso-8859-2?B?VG9tZWsgU293afFza2k=?= (6/6) Nov 07 2010 This wraps up a thread from a few days ago. Pascal featured my D example...
- Walter Bright (2/8) Nov 07 2010 Thanks for doing this. I think D fares rather well in it.
- Jesse Phillips (2/11) Nov 07 2010 When I looked over his scoring from the original post, it seemed > 100 w...
- Andrei Alexandrescu (3/14) Nov 07 2010 Perhaps a module std.scripting could help quite a lot, too.
- Eric Poggel (3/22) Nov 07 2010 I'm having trouble thinking of something that would go in this module
- Andrei Alexandrescu (18/42) Nov 09 2010 I thought of it for a bit, but couldn't come up with anything :o). I
- bearophile (4/7) Nov 09 2010 Good. That someone was me (But I don't use Python fileinput often, so I ...
- =?ISO-8859-1?Q?Pelle_M=E5nsson?= (7/50) Nov 09 2010 module std.script;
- Gary Whatmore (2/62) Nov 09 2010 I think optimizing this particular test is important for the publicity o...
- Daniel Gibson (10/11) Nov 09 2010 D. Once the scripting community acknowledges D, we could redesign it. W...
- Alexander Malakhov (10/19) Nov 11 2010 Maybe it would be better to just make rdmd to surround source code with:
- Gary Whatmore (2/30) Nov 11 2010 No, it could do that in all cases. D supports nested declarations. This ...
-
Alexander Malakhov
(20/39)
Nov 12 2010
Gary Whatmore
=D0=C9=D3=C1=CC(=C1) =D7 =D3=D7=CF=A3=CD =D0=... - Adam D. Ruppe (25/26) Nov 12 2010 I wrote a little rund helper program, and a PHP style D interpreter
-
Alexander Malakhov
(10/48)
Nov 12 2010
Adam D. Ruppe
=D0=C9=D3=C1=CC(=C1) =D7 =D3=D... - retard (6/43) Nov 13 2010 I don't have any opinion of this, but the 1) point make me ask, why
- Leandro Lucarella (14/30) Nov 13 2010 Python allows that too, that's why I opened an enhancement request:
-
Alexander Malakhov
(12/27)
Nov 14 2010
Leandro Lucarella
=D0=C9=D3=C1=CC(=C1) =D7 =D3=D7=C... - =?UTF-8?B?UGVyIMOFbmdzdHLDtm0=?= (5/7) Nov 14 2010 Another thing that comes to mind about things not allowed in unittest
- Andrei Alexandrescu (4/25) Nov 11 2010 rdmd already does that with --eval and --loop.
-
Alexander Malakhov
(13/32)
Nov 12 2010
Andrei Alexandrescu
=D0=C9=D3=C1=CC(=C1)... - Andrei Alexandrescu (7/38) Nov 12 2010 It is:
-
Alexander Malakhov
(14/21)
Nov 12 2010
Andrei Alexandrescu
=D0=C9=D3=C1=CC(=C1)... - sybrandy (4/6) Nov 12 2010 You should be able to do this yourself quite easily by right-clicking on...
- div0 (9/17) Nov 12 2010 Yes you can do it yourself, but if you want it to work seamlessly, DMD
- Andrew Wiley (10/26) Nov 12 2010 That sounds good until you think of comparable situations. Python does t...
- sybrandy (17/26) Nov 12 2010 I fully understand and agree with your point. It's all about how much
- sybrandy (7/23) Nov 12 2010 True...I'm not a fan of having the OS do things beyond my control.
- Andrei Alexandrescu (3/11) Nov 12 2010 Would be nice if the installer took care of that though.
- spir (14/23) Nov 13 2010 hem
- sybrandy (5/21) Nov 13 2010 The nice thing is many installers will ask before they mess things up.
-
Alexander Malakhov
(36/53)
Nov 14 2010
spir
=D0=BF=D0=B8=D1=81=D0=B0=D0=BB(=D0=B0) =D0=B... - Andrew Wiley (7/29) Nov 13 2010 e
- spir (15/16) Nov 13 2010 Btw, I just had an idea about std imports -- not only for scripting, but...
- Nick Sabalausky (3/17) Nov 13 2010 I like the reasoning, but I think it might be confusing.
- Bruno Medeiros (7/28) Nov 26 2010 I think that if one wants to add to D tools additional semantics such as...
- Tomek =?UTF-8?B?U293acWEc2tp?= (10/31) Nov 10 2010 Speaking of getopt, when writing the 'grep' snippet I missed anonymous o...
- Stanislav Blinov (7/21) Nov 10 2010 I too got confused. But personally, I don't like byFileLine either.
- Andrei Alexandrescu (3/22) Nov 10 2010 Not getting the example. How would anonymous options work?
- Tomek =?UTF-8?B?U293acWEc2tp?= (15/24) Nov 10 2010 // Let's match assignments.
- Andrei Alexandrescu (6/28) Nov 10 2010 I still don't see added value over the existing situation. Currently
- Steven Schveighoffer (8/40) Nov 11 2010 1. uses same type check/conversion that is used for options
- Tomek =?UTF-8?B?U293acWEc2tp?= (10/21) Nov 11 2010 Yeah,
- Peter Alexander (2/21) Nov 09 2010 Make it std.s and we save 8 characters for each program :-)
- sybrandy (19/21) Nov 11 2010 Also, something I just thought of this morning is to create something
- Tomek =?UTF-8?B?U293acWEc2tp?= (4/9) Nov 11 2010 std.variant?
- BCS (2/9) Nov 07 2010 The link from D seems dead to me (missing ':' after http).
- Gary Whatmore (2/15) Nov 09 2010 If > 100 is good for scripting and < 100 bad, D belongs to the latter ca...
- =?UTF-8?B?UGVyIMOFbmdzdHLDtm0=?= (31/35) Nov 15 2010 I'm wondering whether the issue of D's or-expression, compared to that
- spir (26/60) Nov 15 2010 =20
- bearophile (4/5) Nov 15 2010 During the design stages of Python3 I've even asked to remove those dirt...
- =?UTF-8?B?UGVyIMOFbmdzdHLDtm0=?= (29/46) Nov 15 2010 Verbosity is not only about more code to type, it's also about more code...
- Simen kjaeraas (17/23) Nov 15 2010 You should probably use a function template[1] or at least an eponymous ...
- =?UTF-8?B?UGVyIMOFbmdzdHLDtm0=?= (7/27) Nov 15 2010 Great, using either of those makes this possible:
- Daniel Murphy (8/9) Nov 15 2010 I think allowing the second expression in the ternary operator to be omi...
- =?ISO-8859-1?Q?Per_=C5ngstr=F6m?= (9/14) Nov 16 2010 Personally I had '|||' in mind, but I'm OK with '?:'. I think it should
- spir (9/23) Nov 16 2010 itted
- gooba (2/29) Nov 16 2010 They now added Scala to scriptometer http://rigaux.org/language-study/sc...
- Alexey Khmara (25/54) Nov 16 2010 "Script mode" (actually - simple wrapper) would be better:
- Adam Ruppe (3/8) Nov 16 2010 My rund.d program does this.
- Alexey Khmara (16/24) Nov 16 2010 I really think that it would be good to ship something like this with
- Leandro Lucarella (9/21) Nov 16 2010 Yes, the "elvis operator" ?:
- Leandro Lucarella (32/32) Nov 19 2010 By the way, I found a bug that I think is quite serious if DMD wants to
- Bruno Medeiros (4/8) Nov 26 2010 Hum, nice, I think this is a very interesting benchmark/metric.
This wraps up a thread from a few days ago. Pascal featured my D examples on his Scriptometer site. http://rigaux.org/language-study/scripting-language/ D comes 17th out of 28, so it's so-so for scripting. -- Tomek
Nov 07 2010
Tomek Sowiski wrote:This wraps up a thread from a few days ago. Pascal featured my D examples on his Scriptometer site. http://rigaux.org/language-study/scripting-language/ D comes 17th out of 28, so it's so-so for scripting.Thanks for doing this. I think D fares rather well in it.
Nov 07 2010
Tomek Sowiski Wrote:This wraps up a thread from a few days ago. Pascal featured my D examples on his Scriptometer site. http://rigaux.org/language-study/scripting-language/ D comes 17th out of 28, so it's so-so for scripting. -- TomekWhen I looked over his scoring from the original post, it seemed > 100 was a great choice for a scripting language and everything below wasn't. D hit where I expected, just good enough to use for scripting.
Nov 07 2010
On 11/7/10 5:34 PM, Jesse Phillips wrote:Tomek Sowiski Wrote:Perhaps a module std.scripting could help quite a lot, too. AndreiThis wraps up a thread from a few days ago. Pascal featured my D examples on his Scriptometer site. http://rigaux.org/language-study/scripting-language/ D comes 17th out of 28, so it's so-so for scripting. -- TomekWhen I looked over his scoring from the original post, it seemed> 100 was a great choice for a scripting language and everything below wasn't. D hit where I expected, just good enough to use for scripting.
Nov 07 2010
On 11/7/2010 8:49 PM, Andrei Alexandrescu wrote:On 11/7/10 5:34 PM, Jesse Phillips wrote: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?Tomek Sowiski Wrote:Perhaps a module std.scripting could help quite a lot, too. AndreiThis wraps up a thread from a few days ago. Pascal featured my D examples on his Scriptometer site. http://rigaux.org/language-study/scripting-language/ D comes 17th out of 28, so it's so-so for scripting. -- TomekWhen I looked over his scoring from the original post, it seemed> 100 was a great choice for a scripting language and everything below wasn't. D hit where I expected, just good enough to use for scripting.
Nov 07 2010
On 11/7/10 9:12 PM, Eric Poggel wrote:On 11/7/2010 8:49 PM, Andrei Alexandrescu wrote:I thought of it for a bit, but couldn't come up with anything :o). I think you're right! 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, ...); 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). AndreiOn 11/7/10 5:34 PM, Jesse Phillips wrote: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?Tomek Sowiski Wrote:Perhaps a module std.scripting could help quite a lot, too. AndreiThis wraps up a thread from a few days ago. Pascal featured my D examples on his Scriptometer site. http://rigaux.org/language-study/scripting-language/ D comes 17th out of 28, so it's so-so for scripting. -- TomekWhen I looked over his scoring from the original post, it seemed> 100 was a great choice for a scripting language and everything below wasn't. D hit where I expected, just good enough to use for scripting.
Nov 09 2010
Andrei:Someone proposed to add something like http://docs.python.org/library/fileinput.html to Phobos. I think it's a good idea.Good. That someone was me (But I don't use Python fileinput often, so I have never written an enhancement request on this). Bye, bearophile
Nov 09 2010
On 11/09/2010 06:12 PM, Andrei Alexandrescu wrote:On 11/7/10 9:12 PM, Eric Poggel wrote:module std.script; public import std.stdio, std.file, std.process, std.algorithm, ... etc I use at least some of these for most of my programs/scripts. And std.all is probably a bit too heavy. std.script could basically fetch us enough stuff to be on par with importless python.On 11/7/2010 8:49 PM, Andrei Alexandrescu wrote:I thought of it for a bit, but couldn't come up with anything :o). I think you're right! 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, ...); 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). AndreiOn 11/7/10 5:34 PM, Jesse Phillips wrote: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?Tomek Sowiski Wrote:Perhaps a module std.scripting could help quite a lot, too. AndreiThis wraps up a thread from a few days ago. Pascal featured my D examples on his Scriptometer site. http://rigaux.org/language-study/scripting-language/ D comes 17th out of 28, so it's so-so for scripting. -- TomekWhen I looked over his scoring from the original post, it seemed> 100 was a great choice for a scripting language and everything below wasn't. D hit where I expected, just good enough to use for scripting.
Nov 09 2010
Pelle Mnsson Wrote:On 11/09/2010 06:12 PM, Andrei Alexandrescu wrote:I think optimizing this particular test is important for the publicity of D. Once the scripting community acknowledges D, we could redesign it. We should make all current test cases one liners, if possible. I'm dreaming of a Linux system (Ubuntu) which uses dmd instead of bash to compile all init scripts. The system would boot in just a few seconds.On 11/7/10 9:12 PM, Eric Poggel wrote:module std.script; public import std.stdio, std.file, std.process, std.algorithm, ... etc I use at least some of these for most of my programs/scripts. And std.all is probably a bit too heavy. std.script could basically fetch us enough stuff to be on par with importless python.On 11/7/2010 8:49 PM, Andrei Alexandrescu wrote:I thought of it for a bit, but couldn't come up with anything :o). I think you're right! 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, ...); 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). AndreiOn 11/7/10 5:34 PM, Jesse Phillips wrote: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?Tomek Sowiski Wrote:Perhaps a module std.scripting could help quite a lot, too. AndreiThis wraps up a thread from a few days ago. Pascal featured my D examples on his Scriptometer site. http://rigaux.org/language-study/scripting-language/ D comes 17th out of 28, so it's so-so for scripting. -- TomekWhen I looked over his scoring from the original post, it seemed> 100 was a great choice for a scripting language and everything below wasn't. D hit where I expected, just good enough to use for scripting.
Nov 09 2010
On Wed, Nov 10, 2010 at 2:04 AM, Gary Whatmore <no spam.sp> wrote:I think optimizing this particular test is important for the publicity of=D. Once the scripting community acknowledges D, we could redesign it. We s= hould make all current test cases one liners, if possible. I'm dreaming of = a Linux system (Ubuntu) which uses dmd instead of bash to compile all init = scripts. The system would boot in just a few seconds.No it wouldn't. Booting doesn't take so long because you wait for bash/dash to interpret the init scripts but because you wait for what the init-scripts do (mount/fsck filesystems, start daemons, ...). Sure, there's an overhead from bash (or dash, that at least debian uses now and has fewer overhead), but it's not that significant.
Nov 09 2010
Perhaps a module std.scripting could help quite a lot, too.module std.script; public import std.stdio, std.file, std.process, std.algorithm, ... etc I use at least some of these for most of my programs/scripts. And std.all is probably a bit too heavy. std.script could basically fetch us enough stuff to be on par with importless python.Maybe it would be better to just make rdmd to surround source code with: //----- rdmd generated text BEGIN public import std.stdio, ... void main( string[] args ){ //----- rdmd generated text END // programmer's code } in cases when rdmd detects there is no main() -- Alexander
Nov 11 2010
Alexander Malakhov Wrote:No, it could do that in all cases. D supports nested declarations. This is how the other languages do this. It would improve the score a lot. Did TDPL talk script programming? We can still change this radically without breaking D2 - thank god the specification is informal and incomplete.Perhaps a module std.scripting could help quite a lot, too.module std.script; public import std.stdio, std.file, std.process, std.algorithm, ... etc I use at least some of these for most of my programs/scripts. And std.all is probably a bit too heavy. std.script could basically fetch us enough stuff to be on par with importless python.Maybe it would be better to just make rdmd to surround source code with: //----- rdmd generated text BEGIN public import std.stdio, ... void main( string[] args ){ //----- rdmd generated text END // programmer's code } in cases when rdmd detects there is no main()
Nov 11 2010
Gary Whatmore <no spam.sp> =D0=C9=D3=C1=CC(=C1) =D7 =D3=D7=CF=A3=CD =D0=C9= =D3=D8=CD=C5 Thu, 11 Nov 2010 = 20:07:35 +0600:Alexander Malakhov Wrote:th:... Maybe it would be better to just make rdmd to surround source code wi=s =//----- rdmd generated text BEGIN public import std.stdio, ... void main( string[] args ){ //----- rdmd generated text END // programmer's code } in cases when rdmd detects there is no main()No, it could do that in all cases. D supports nested declarations. Thi=is how the other languages do this. It would improve the score a lot. ==Did TDPL talk script programming? We can still change this radically =without breaking D2 - thank god the specification is informal and =incomplete.Then you have 2 issues: void main(string[] args){ import std.stdio; // 1. will not compile void main(string[] args){ writeln("hello"); } main(args); // 2. this should be appended, hence anyway rdmd should = analyze // if there is main() } -- btw, why name is not simply "std.io" ? -- = Alexander
Nov 12 2010
Alexander Malakhov wrote:import std.stdio; // 1. will not compileI wrote a little rund helper program, and a PHP style D interpreter in another thread a couple days ago, that solves this by a simple string scan. http://arsdnet.net/dcode/rund.d http://arsdnet.net/dcode/dhp.d It scans the code byLine. If the line starts with "import", cut it out and move it to the top of the final file outputted, above main. This would break if you indented the import, or if it was in a string literal or something, but there's a simple solution to that: don't do it! Example of use: $ rund import std.math; writeln(pow(4, 3)); <EOF> 64 ====== $ dhp <?d import std.math; ?> Four to the third power is <?= pow(4, 3) ?>! <EOF> Four to the third power is 64! ======= You can see the rule at work in the second example. <?d import std.math; ?> wouldn't have been moved, so I just put a newline on it.
Nov 12 2010
Adam D. Ruppe <destructionator gmail.com> =D0=C9=D3=C1=CC(=C1) =D7 =D3=D7= =CF=A3=CD =D0=C9=D3=D8=CD=C5 Fri, 12 = Nov 2010 23:13:13 +0600:Alexander Malakhov wrote:=import std.stdio; // 1. will not compileI wrote a little rund helper program, and a PHP style D interpreter in another thread a couple days ago, that solves this by a simple string scan. http://arsdnet.net/dcode/rund.d http://arsdnet.net/dcode/dhp.d It scans the code byLine. If the line starts with "import", cut it out=and move it to the top of the final file outputted, above main. This would break if you indented the import, or if it was in a string ==literal or something, but there's a simple solution to that: don't do it! Example of use: $ rund import std.math; writeln(pow(4, 3)); <EOF> 64 =3D=3D=3D=3D=3D=3D $ dhp <?d import std.math; ?> Four to the third power is <?=3D pow(4, 3) ?>! <EOF> Four to the third power is 64! =3D=3D=3D=3D=3D=3D=3D You can see the rule at work in the second example. <?d import std.mat=h; =?> wouldn't have been moved, so I just put a newline on it.Looks nice, especially dhp. But if 2nd problem isn't solved there is no point in fixing importsvoid main(string[] args){ import std.stdio; // 1. will not compile void main(string[] args){ writeln("hello"); } main(args); // 2. this should be appended, hence anyway rdmd should =-- = Alexanderanalyze // if there is main() }
Nov 12 2010
Fri, 12 Nov 2010 23:01:24 +0600, Alexander Malakhov wrote:Gary Whatmore <no spam.sp> писал(а) в своём письме Thu, 11 Nov 2010 20:07:35 +0600:shouldAlexander Malakhov Wrote:Then you have 2 issues: void main(string[] args){ import std.stdio; // 1. will not compile void main(string[] args){ writeln("hello"); } main(args); // 2. this should be appended, hence anyway rdmd... Maybe it would be better to just make rdmd to surround source code with: //----- rdmd generated text BEGIN public import std.stdio, ... void main( string[] args ){ //----- rdmd generated text END // programmer's code } in cases when rdmd detects there is no main()No, it could do that in all cases. D supports nested declarations. This is how the other languages do this. It would improve the score a lot. Did TDPL talk script programming? We can still change this radically without breaking D2 - thank god the specification is informal and incomplete.analyze // if there is main() }I don't have any opinion of this, but the 1) point make me ask, why imports can't be used inside methods just like in Scala. There's no technical reason other than "this adds bugs!" - at least no scientific research can prove this since Scala hasn't been in wide use that long.
Nov 13 2010
retard, el 13 de noviembre a las 08:24 me escribiste:Python allows that too, that's why I opened an enhancement request: http://d.puremagic.com/issues/show_bug.cgi?id=3506 As the bugzilla issue shows, this is particularly annoying when combined with unittest. -- Leandro Lucarella (AKA luca) http://llucax.com.ar/ ---------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------- Hoy estuvimos en el museo de antropología, pero yo voy a volver para estar por lo menos un día ahí adentro... es una locura, como Disney pero de indigenas -- Carla Lucarella (10/2008 contando de su viaje a México)void main(string[] args){ import std.stdio; // 1. will not compile void main(string[] args){ writeln("hello"); } main(args); // 2. this should be appended, hence anyway rdmdshouldanalyze // if there is main() }I don't have any opinion of this, but the 1) point make me ask, why imports can't be used inside methods just like in Scala. There's no technical reason other than "this adds bugs!" - at least no scientific research can prove this since Scala hasn't been in wide use that long.
Nov 13 2010
Leandro Lucarella <luca llucax.com.ar> =D0=C9=D3=C1=CC(=C1) =D7 =D3=D7=CF= =A3=CD =D0=C9=D3=D8=CD=C5 Sat, 13 Nov = 2010 21:13:42 +0600:retard, el 13 de noviembre a las 08:24 me escribiste:=void main(string[] args){ import std.stdio; // 1. will not compile> void main(string[]=Maybe it will somehow affect compile time or complicate module dependenc= y = analysis ?args){writeln("hello"); }<...> the 1) point make me ask, why imports can't be used inside methods just like in Scala. There's no technical reason other than "this adds bugs!"Python allows that too, that's why I opened an enhancement request: http://d.puremagic.com/issues/show_bug.cgi?id=3D3506 As the bugzilla issue shows, this is particularly annoying when combin=edwith unittest.Even if there are technical issues, special case for unit tests sounds = like a good improvement of usability -- = Alexander
Nov 14 2010
On 2010-11-14 13:40, Alexander Malakhov wrote:Even if there are technical issues, special case for unit tests sounds like a good improvement of usabilityAnother thing that comes to mind about things not allowed in unittest scope that could facilitate unit testing: defining templates. -- Per Å.
Nov 14 2010
On 11/11/10 5:50 AM, Alexander Malakhov wrote:rdmd already does that with --eval and --loop. http://www.digitalmars.com/d/2.0/rdmd.html AndreiPerhaps a module std.scripting could help quite a lot, too.module std.script; public import std.stdio, std.file, std.process, std.algorithm, ... etc I use at least some of these for most of my programs/scripts. And std.all is probably a bit too heavy. std.script could basically fetch us enough stuff to be on par with importless python.Maybe it would be better to just make rdmd to surround source code with: //----- rdmd generated text BEGIN public import std.stdio, ... void main( string[] args ){ //----- rdmd generated text END // programmer's code } in cases when rdmd detects there is no main()
Nov 11 2010
Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> =D0=C9=D3=C1=CC(=C1)= =D7 =D3=D7=CF=A3=CD = =D0=C9=D3=D8=CD=C5 Thu, 11 Nov 2010 21:12:33 +0600:On 11/11/10 5:50 AM, Alexander Malakhov wrote:th:Maybe it would be better to just make rdmd to surround source code wi=I was unable to pass file to --eval, is this possible ?//----- rdmd generated text BEGIN public import std.stdio, ... void main( string[] args ){ //----- rdmd generated text END // programmer's code } in cases when rdmd detects there is no main()rdmd already does that with --eval and --loop. http://www.digitalmars.com/d/2.0/rdmd.html Andreirdmd --eval=3Dscript.d(16): Error: undefined identifier script also while I'm here. This works: > rdmd = --eval=3Dwriteln("");writeln("");writeln(""); and this don't:rdmd --eval=3Dwriteln("hello")(16): Error: undefined identifier hello btw, does --eval make "import std.all" or some set of modules ? -- = Alexander
Nov 12 2010
On 11/12/10 9:21 AM, Alexander Malakhov wrote:Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> () ϣ Thu, 11 Nov 2010 21:12:33 +0600:It is: rdmd --eval $(cat filename) I know... it's cheating :o). But if you want to pass a file, why not just make the file a small program and compile it the classic way?On 11/11/10 5:50 AM, Alexander Malakhov wrote:I was unable to pass file to --eval, is this possible ?Maybe it would be better to just make rdmd to surround source code with: //----- rdmd generated text BEGIN public import std.stdio, ... void main( string[] args ){ //----- rdmd generated text END // programmer's code } in cases when rdmd detects there is no main()rdmd already does that with --eval and --loop. http://www.digitalmars.com/d/2.0/rdmd.html AndreiIt imports all modules. Andreirdmd --eval=script.d(16): Error: undefined identifier script also while I'm here. This works: > rdmd --eval=writeln("");writeln("");writeln(""); and this don't:rdmd --eval=writeln("hello")(16): Error: undefined identifier hello btw, does --eval make "import std.all" or some set of modules ?
Nov 12 2010
Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> =D0=C9=D3=C1=CC(=C1)= =D7 =D3=D7=CF=A3=CD = =D0=C9=D3=D8=CD=C5 Fri, 12 Nov 2010 23:44:18 +0600:On 11/12/10 9:21 AM, Alexander Malakhov wrote:I was unable to pass file to --eval, is this possible ?It is: rdmd --eval $(cat filename) I know... it's cheating :o). But if you want to pass a file, why not =just make the file a small program and compile it the classic way? AndreiFirst of all, I have virtually no exp with scripts, and maybe nobody should listen to my opinion :) I was thinking about 2 things: 1. In many examples from that site "import ... void main" was 50% of the= = code 2. Make Windows to open .d files with rdmd by default, so I could run th= em with simple double-click -- = Alexander
Nov 12 2010
2. Make Windows to open .d files with rdmd by default, so I could run them with simple double-clickYou should be able to do this yourself quite easily by right-clicking on the D file and associating it with rdmd. I'd give better instructions except I'm not on a Windows machine right now. Casey
Nov 12 2010
On 12/11/2010 19:42, sybrandy wrote:Yes you can do it yourself, but if you want it to work seamlessly, DMD would need an installer to set-up that registration. Can't say I'm in favour of it; windows has enough security holes as it is, without allowing a powerful compiler to kick off with an inadvertent click. -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk2. Make Windows to open .d files with rdmd by default, so I could run them with simple double-clickYou should be able to do this yourself quite easily by right-clicking on the D file and associating it with rdmd. I'd give better instructions except I'm not on a Windows machine right now. Casey
Nov 12 2010
2010/11/12 div0 <div0 sourceforge.net>On 12/11/2010 19:42, sybrandy wrote:That sounds good until you think of comparable situations. Python does this, Perl does this, heck, if allowing powerful things to start with an inadvertent click, why do we have batch files? Why do we have executables? Being able to run things by clicking on them is a feature, not a security hole. It only becomes a security hole when the user doesn't watch what they click. The tradeoff between convenience and protection there hasn't ever been considered because the protection definitely isn't worth the inconvenience of having to start everything from a command prompt. Andrew Wiley2. Make Windows to open .d files with rdmd by default, so I could runYes you can do it yourself, but if you want it to work seamlessly, DMD would need an installer to set-up that registration. Can't say I'm in favour of it; windows has enough security holes as it is, without allowing a powerful compiler to kick off with an inadvertent click.them with simple double-clickYou should be able to do this yourself quite easily by right-clicking on the D file and associating it with rdmd. I'd give better instructions except I'm not on a Windows machine right now. Casey
Nov 12 2010
That sounds good until you think of comparable situations. Python does this, Perl does this, heck, if allowing powerful things to start with an inadvertent click, why do we have batch files? Why do we have executables? Being able to run things by clicking on them is a feature, not a security hole. It only becomes a security hole when the user doesn't watch what they click. The tradeoff between convenience and protection there hasn't ever been considered because the protection definitely isn't worth the inconvenience of having to start everything from a command prompt. Andrew WileyI fully understand and agree with your point. It's all about how much power does a user really need so that they don't shoot themselves in the foot and does the user know what is on their system. The scenario that concerns me is the user double-clicking on some unknown file (E.g. one that ends with .d in this case) and it doing something unexpected. In other words, they may expect it to open in a viewer or editor vs. performing some operation to a set of files. However, this isn't the fault of the installer, though the installer can help by making the association optional. For example, if I'm sharing a computer with someone who's not technical, it may be better that I do not have that association in place as I'm comfortable with running files from the command line and I don't trust the other user to not double-click on a file that they shouldn't. Of course, I prefer to use double-click to open the file in Vim vs. executing it. Having the option to not set the association would keep me from executing files when I want to edit them. Casey
Nov 12 2010
On 11/12/2010 03:06 PM, div0 wrote:On 12/11/2010 19:42, sybrandy wrote:True...I'm not a fan of having the OS do things beyond my control. Hell, I complained to my current company's tech support one time because they installed new software and I didn't know about it. I told them that I thought it was a virus! Of course, I just may be a control freak when it comes to computers I use. CaseyYes you can do it yourself, but if you want it to work seamlessly, DMD would need an installer to set-up that registration. Can't say I'm in favour of it; windows has enough security holes as it is, without allowing a powerful compiler to kick off with an inadvertent click.2. Make Windows to open .d files with rdmd by default, so I could run them with simple double-clickYou should be able to do this yourself quite easily by right-clicking on the D file and associating it with rdmd. I'd give better instructions except I'm not on a Windows machine right now. Casey
Nov 12 2010
On 11/12/10 11:42 AM, sybrandy wrote:Would be nice if the installer took care of that though. Andrei2. Make Windows to open .d files with rdmd by default, so I could run them with simple double-clickYou should be able to do this yourself quite easily by right-clicking on the D file and associating it with rdmd. I'd give better instructions except I'm not on a Windows machine right now. Casey
Nov 12 2010
On Fri, 12 Nov 2010 14:42:38 -0500 sybrandy <sybrandy gmail.com> wrote:hem2. Make Windows to open .d files with rdmd by default, so I could run t==20with simple double-click=20 You should be able to do this yourself quite easily by right-clicking on=the D file and associating it with rdmd. I'd give better instructions=20 except I'm not on a Windows machine right now. -- CaseyYes. Maybe Alexander meant this for users rather than for developpers. The = association should then be set during install of the compiler, I guess (but= I actually have no idea how this is supposed to be done -- just know that = some apps installers do this: set their own file associations -- which by t= he way is pretty annoying when you don't want eg an image viewer to "hijack= " all image file formats). Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.com
Nov 13 2010
On 11/13/2010 05:15 AM, spir wrote:On Fri, 12 Nov 2010 14:42:38 -0500 sybrandy<sybrandy gmail.com> wrote:The nice thing is many installers will ask before they mess things up. In all honesty, I was just trying to help him out. I didn't realize my answer would open up so much discussion! CaseyYes. Maybe Alexander meant this for users rather than for developpers. The association should then be set during install of the compiler, I guess (but I actually have no idea how this is supposed to be done -- just know that some apps installers do this: set their own file associations -- which by the way is pretty annoying when you don't want eg an image viewer to "hijack" all image file formats). Denis -- -- -- -- -- -- -- vit esse estrany ☣ spir.wikidot.com2. Make Windows to open .d files with rdmd by default, so I could run them with simple double-clickYou should be able to do this yourself quite easily by right-clicking on the D file and associating it with rdmd. I'd give better instructions except I'm not on a Windows machine right now. -- Casey
Nov 13 2010
spir <denis.spir gmail.com> =D0=BF=D0=B8=D1=81=D0=B0=D0=BB(=D0=B0) =D0=B2= =D1=81=D0=B2=D0=BE=D1=91=D0=BC =D0=BF=D0=B8=D1=81=D1=8C=D0=BC=D0=B5 Sat= , 13 Nov 2010 = 16:15:39 +0600:On Fri, 12 Nov 2010 14:42:38 -0500 sybrandy <sybrandy gmail.com> wrote:un =2. Make Windows to open .d files with rdmd by default, so I could r==them with simple double-clickYes. Maybe Alexander meant this for users rather than for developpers.=The association should then be set during install of the compiler, I =guess (but I actually have no idea how this is supposed to be done -- ==just know that some apps installers do this: set their own file =associations -- which by the way is pretty annoying when you don't wan=t =eg an image viewer to "hijack" all image file formats). Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.comWith my point 2 I meant that I want to __have an option__ to run .d with= = rdmd, of course It would certainly be much simpler for users. I'm in-house programmer, a= nd = actually it's not even an option to make any user from financial = department to run anything from command line (most likely they will forg= et = how to do this in a couple weeks) My main idea was a little different, though: to be able to write short = scripts ("import"- and "main()"-less, like with rdmd --eval) AND to run = = them easily. Then, if I need smth like 30-liner for some files manipulation and if I'= m = proficient with D, I would go with D instead of .bat. I have never used scripting for anything except this stuff, so I can't = come up with better example.onYou should be able to do this yourself quite easily by right-clicking=sthe D file and associating it with rdmd. I'd give better instruction=Yeah, that's really easy (roughly translated from russian win7): 1. right click on .d file (shift + right-click on XP, IIRC) 2. "Open with..." 3. "Choose Program" 4. find rdmd.exe (default is C:\D\dmd2\windows\bin) 5. check "Use this program with all files of this type" box -- = Alexanderexcept I'm not on a Windows machine right now.
Nov 14 2010
On Sat, Nov 13, 2010 at 4:15 AM, spir <denis.spir gmail.com> wrote:On Fri, 12 Nov 2010 14:42:38 -0500 sybrandy <sybrandy gmail.com> wrote:nthem2. Make Windows to open .d files with rdmd by default, so I could runwith simple double-clickYou should be able to do this yourself quite easily by right-clicking o=ethe D file and associating it with rdmd. I'd give better instructions except I'm not on a Windows machine right now. -- CaseyYes. Maybe Alexander meant this for users rather than for developpers. Th=association should then be set during install of the compiler, I guess (b=utI actually have no idea how this is supposed to be done -- just know that some apps installers do this: set their own file associations -- which by the way is pretty annoying when you don't want eg an image viewer to "hijack" all image file formats). Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.comIf I remember correctly, the dinstaller is built using the Nullsoft Scriptable Install System (NSIS), and adding file associations to the installer is simple and documented.
Nov 13 2010
On Fri, 12 Nov 2010 23:21:55 +0600 "Alexander Malakhov" <anm programmer.net> wrote:btw, does --eval make "import std.all" or some set of modules ?Btw, I just had an idea about std imports -- not only for scripting, but fo= r general use of D as well: What if D automagically imported a std set of m= odules, _provided_ none of them is explicitely imported? Then, I guess, people could go on importing manually (eg to reduce size of = executable) without any change. This also applies to all existing apps, doe= sn't it? A border case would be an app that actually imports nothing -- but= is it at all possible to do anything? An interesting debate would be to define this std set ;-) Could it (easily)= be made configurable? Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.com
Nov 13 2010
"spir" <denis.spir gmail.com> wrote in message news:mailman.322.1289642939.21107.digitalmars-d puremagic.com...On Fri, 12 Nov 2010 23:21:55 +0600 "Alexander Malakhov" <anm programmer.net> wrote:I like the reasoning, but I think it might be confusing.btw, does --eval make "import std.all" or some set of modules ?Btw, I just had an idea about std imports -- not only for scripting, but for general use of D as well: What if D automagically imported a std set of modules, _provided_ none of them is explicitely imported? Then, I guess, people could go on importing manually (eg to reduce size of executable) without any change. This also applies to all existing apps, doesn't it? A border case would be an app that actually imports nothing -- but is it at all possible to do anything? An interesting debate would be to define this std set ;-) Could it (easily) be made configurable?
Nov 13 2010
On 11/11/2010 13:50, Alexander Malakhov wrote:I think that if one wants to add to D tools additional semantics such as that one (automatically add main, imports, etc., for scripting), it would be nice to define a new file extension like ".ds", ".dscript", whatever, for such files, just to make this clearer and more separate. -- Bruno Medeiros - Software EngineerPerhaps a module std.scripting could help quite a lot, too.module std.script; public import std.stdio, std.file, std.process, std.algorithm, ... etc I use at least some of these for most of my programs/scripts. And std.all is probably a bit too heavy. std.script could basically fetch us enough stuff to be on par with importless python.Maybe it would be better to just make rdmd to surround source code with: //----- rdmd generated text BEGIN public import std.stdio, ... void main( string[] args ){ //----- rdmd generated text END // programmer's code } in cases when rdmd detects there is no main()
Nov 26 2010
Andrei Alexandrescu napisał:Yeah, I think std.all would be just fine, or as Pelle proposed, a module publicly importing a first-aid kit for scripting.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!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
Nov 10 2010
Tomek Sowiński wrote:Andrei Alexandrescu napisał:I too got confused. But personally, I don't like byFileLine either. Maybe something like Files range: File.byLine(files(args[1..$]))) or files(args[1..$]).byLine ?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(...)?
Nov 10 2010
On 11/10/10 1:45 PM, Tomek Sowiński wrote:Andrei Alexandrescu napisał:Not getting the example. How would anonymous options work? AndreiYeah, I think std.all would be just fine, or as Pelle proposed, a module publicly importing a first-aid kit for scripting.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!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.
Nov 10 2010
Andrei Alexandrescu napisał:// 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. -- TomekSpeaking 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?
Nov 10 2010
On 11/10/10 3:58 PM, Tomek Sowiński wrote:Andrei Alexandrescu napisał:I still don't see added value over the existing situation. Currently getopt leaves whatever wasn't an option in args[1 .. $] (without shuffling order), so the code above would simply use args[1] for expr and args[2 .. $] for files. Andrei// 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.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?
Nov 10 2010
On Wed, 10 Nov 2010 19:12:26 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 11/10/10 3:58 PM, Tomek Sowiński wrote:1. uses same type check/conversion that is used for options 2. Less boilerplate code. For 2, without anonymous options, you either use args[1] everywhere, or you assign args[1] to a variable at the top. To just do it in one line is convenient, I kind of like the idea. -SteveAndrei Alexandrescu napisał:I still don't see added value over the existing situation. Currently getopt leaves whatever wasn't an option in args[1 .. $] (without shuffling order), so the code above would simply use args[1] for expr and args[2 .. $] for files.// 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.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?
Nov 11 2010
Steven Schveighoffer napisał:Yeah, auto args =["numcruncher.exe", "-avg", "-med", "5", "3", "4.5", ".8"]; bool avg, med; double[] numbers; getopt(args, "avg",&avg, "med",&med, &numbers);I still don't see added value over the existing situation. Currently getopt leaves whatever wasn't an option in args[1 .. $] (without shuffling order), so the code above would simply use args[1] for expr and args[2 .. $] for files.1. uses same type check/conversion that is used for options2. Less boilerplate code. For 2, without anonymous options, you either use args[1] everywhere, or you assign args[1] to a variable at the top. To just do it in one line is convenient, I kind of like the idea.Yes. Why should getopt do just half of the job when it can do most, and for cheap? Again, small implementation effort in the denominator boosts the ROI of this development to lucrative levels. -- Tomek
Nov 11 2010
On 8/11/10 1:49 AM, Andrei Alexandrescu wrote:On 11/7/10 5:34 PM, Jesse Phillips wrote:Make it std.s and we save 8 characters for each program :-)Tomek Sowiski Wrote:Perhaps a module std.scripting could help quite a lot, too. AndreiThis wraps up a thread from a few days ago. Pascal featured my D examples on his Scriptometer site. http://rigaux.org/language-study/scripting-language/ D comes 17th out of 28, so it's so-so for scripting. -- TomekWhen I looked over his scoring from the original post, it seemed> 100 was a great choice for a scripting language and everything below wasn't. D hit where I expected, just good enough to use for scripting.
Nov 09 2010
Perhaps a module std.scripting could help quite a lot, too. AndreiAlso, something I just thought of this morning is to create something similar to std.variant for variables where every variable is the same type. Perl, for example, may store the same value multiple times in the same "structure" (I don't know the right term) depending on if it was used as a number, a string, or both. This can make language easier to use for scripting so that the user doesn't have to worry about data types. For example (Using Foo as the name of the type for lack of a better name): Foo x = 27; x += 15; // X is now 42 Foo y = "X is " ~ x; // Here, x is now treated like a string. The way I figure it, and I could be wrong, this could be stored as a struct with the various op* operations defined to perform the correct operation when called. Also, errors should be reported if, for example, someone tries to add the value "bar" to 13. I think this would be a good first step to making D more scripting friendly, though less efficient in terms of memory and speed. And hopefully this would also work with all of the existing methods that we have, though there are probably a ton of issues related to that. Casey
Nov 11 2010
sybrandy napisał:Foo x = 27; x += 15; // X is now 42 Foo y = "X is " ~ x; // Here, x is now treated like a string.std.variant? -- Tomek
Nov 11 2010
Hello Tomek,This wraps up a thread from a few days ago. Pascal featured my D examples on his Scriptometer site. http://rigaux.org/language-study/scripting-language/ D comes 17th out of 28, so it's so-so for scripting.The link from D seems dead to me (missing ':' after http).
Nov 07 2010
Jesse Phillips Wrote:Tomek Sowiski Wrote:If > 100 is good for scripting and < 100 bad, D belongs to the latter category. It only scored 93.This wraps up a thread from a few days ago. Pascal featured my D examples on his Scriptometer site. http://rigaux.org/language-study/scripting-language/ D comes 17th out of 28, so it's so-so for scripting. -- TomekWhen I looked over his scoring from the original post, it seemed > 100 was a great choice for a scripting language and everything below wasn't. D hit where I expected, just good enough to use for scripting.
Nov 09 2010
On 2010-11-07 22:29, Tomek Sowiński wrote:This wraps up a thread from a few days ago. Pascal featured my D examples on his Scriptometer site. http://rigaux.org/language-study/scripting-language/ D comes 17th out of 28, so it's so-so for scripting.I'm wondering whether the issue of D's or-expression, compared to that of languages such as Perl and Ruby, has been discussed and dismissed. Personally, I was a bit disappointed to learn that D had such a traditional or-expression, seeing how much it is willing to improve over C/C++ in other areas. I think the following code summarizes the issue. I'm not a language lawyer, so maybe the rules could be described more succinctly, but I think you'll get my drift. I'm aware that with D being a typed and compiled language, there has to a be a restriction that both sub-expressions must be convertible to a common type, but I'm sure that can be worked out somehow. string func(string s) { /++ // A handy feature of many scripting languages, but not in D // (in D, the type of the or-expression is bool): // The type of the or-expression is the type of the first // sub-expression that evaluates to true. return s || "default"; +/ // The D equivalent, arguably more readable but also more verbose: return s ? s : "default"; } void main() { assert(func("a") == "a"); assert(func(null) == "default"); } -- Per Å.
Nov 15 2010
On Mon, 15 Nov 2010 13:15:50 +0100 Per =C3=85ngstr=C3=B6m <d-news autark.se> wrote:On 2010-11-07 22:29, Tomek Sowi=C5=84ski wrote:=20This wraps up a thread from a few days ago. Pascal featured my D examples on his Scriptometer site. http://rigaux.org/language-study/scripting-language/ D comes 17th out of 28, so it's so-so for scripting.I'm wondering whether the issue of D's or-expression, compared to that=20 of languages such as Perl and Ruby, has been discussed and dismissed. =20 Personally, I was a bit disappointed to learn that D had such a=20 traditional or-expression, seeing how much it is willing to improve over=C/C++ in other areas. =20 I think the following code summarizes the issue. I'm not a language=20 lawyer, so maybe the rules could be described more succinctly, but I=20 think you'll get my drift. I'm aware that with D being a typed and=20 compiled language, there has to a be a restriction that both=20 sub-expressions must be convertible to a common type, but I'm sure that=20 can be worked out somehow. =20 string func(string s) { /++ // A handy feature of many scripting languages, but not in D // (in D, the type of the or-expression is bool): // The type of the or-expression is the type of the first // sub-expression that evaluates to true. return s || "default"; +/ // The D equivalent, arguably more readable but also more verbose: return s ? s : "default"; }More verbose? Real programmers *want* to type 3 more characters when this makes code cle= arer! ;-) I read once that professional programmers produce about one dozen lines of = effective code per day. Let us say they actually write three times more, by= editing and/or recoding. How much time & effort is typing 36 lines of code= ? Maybe it's just me: I find nearly all complains about verbosity simply ri= diculous. Programmers spend 49% of their time thinking about the model, 49%= controlling their code, the rest typing. I *want* my language of choice to let me write clear code -- this is by far= the most important task of a language designer, and cost in terms of numbe= r of characters is hardly even a side-issue. All major problems around soft= ware come from the extreme difficulty of understanding. Also: that logical expressions do not return logical values (read: bools) i= s arguably semantic mismatch (that necessarily hurts newcomers). I even fin= d Lua's if x then doSomethingWith(x) borderline (here "x" is shortcut for "x !=3D nil"). Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.com
Nov 15 2010
spir:I *want* my language of choice to let me write clear code --During the design stages of Python3 I've even asked to remove those dirty boolean shortcuts of Python2 :-) Bye, bearophile
Nov 15 2010
On 2010-11-15 14:27, spir wrote:On Mon, 15 Nov 2010 13:15:50 +0100 Per Ångström<d-news autark.se> wrote:Verbosity is not only about more code to type, it's also about more code to read. My example was brief so of course that difference is negligible. Here's a somewhat more complex example which forces a trade-off between an extra temporary variable, evaluating the same expression twice or using a template: /++ Simulates type-returning or-expression +/ template or(T) { T _(T a, lazy T b) {T tmp = a; return tmp ? tmp : b;} } void m() { /+ least verbose, invalid D: string s = func("...") || "default"; +/ /+ valid D, but requires extra temp variable: string tmp = func("..."); string s = tmp ? tmp : "default"; +/ /+ valid D, no temp variable but two (hopefully idempotent) function calls: string s = func("...") ? func(".,.") : "default"; +/ // valid D, but arguably ugly: string s = or!string._(func("..."), "default"); } -- Per Å.string func(string s) { /++ // A handy feature of many scripting languages, but not in D // (in D, the type of the or-expression is bool): // The type of the or-expression is the type of the first // sub-expression that evaluates to true. return s || "default"; +/ // The D equivalent, arguably more readable but also more verbose: return s ? s : "default"; }More verbose? Real programmers *want* to type 3 more characters when this makes code clearer! ;-)
Nov 15 2010
Per =C3=85ngstr=C3=B6m <d-news autark.se> wrote:/++ Simulates type-returning or-expression +/ template or(T) { T _(T a, lazy T b) {T tmp =3D a; return tmp ? tmp : b;} }You should probably use a function template[1] or at least an eponymous = = template here: // function template: auto or( T )( T a, lazy T b ) { return a ? a : b; } // eponymous template: template or( T ) { auto or( T a, lazy T b ) { return a ? a : b; } } [1]: http://digitalmars.com/d/2.0/template.html#function-templates -- = Simen
Nov 15 2010
On 2010-11-15 18:40, Simen kjaeraas wrote:Per Ångström <d-news autark.se> wrote:Great, using either of those makes this possible: string s = or(func2("..."), "default"); Which is a lot less ugly. Cheers, -- Per Å./++ Simulates type-returning or-expression +/ template or(T) { T _(T a, lazy T b) {T tmp = a; return tmp ? tmp : b;} }You should probably use a function template[1] or at least an eponymous template here: // function template: auto or( T )( T a, lazy T b ) { return a ? a : b; } // eponymous template: template or( T ) { auto or( T a, lazy T b ) { return a ? a : b; } } [1]: http://digitalmars.com/d/2.0/template.html#function-templates
Nov 15 2010
"Per ngstrm" <d-news autark.se> wrote in message news:ibr8bs$22mu$1 digitalmars.com...return s || "default";I think allowing the second expression in the ternary operator to be omitted would be a better fit for D, and provide the same function. ie. auto x = a ? a : b; auto x = a ? : b; I think bearophile might have already proposed this?
Nov 15 2010
On 2010-11-16 01:10, Daniel Murphy wrote:I think allowing the second expression in the ternary operator to be omitted would be a better fit for D, and provide the same function. ie. auto x = a ? a : b; auto x = a ? : b;Personally I had '|||' in mind, but I'm OK with '?:'. I think it should be one single token and not an extension of the tertiary operator, though: auto x = condition ? a : b; // tertiary operator auto x = condition ? : b; // error, did you forget the middle operand? auto x = a ?: b; // OK -- Cheers, Per .
Nov 16 2010
On Tue, 16 Nov 2010 09:44:06 +0100 Per =C3=85ngstr=C3=B6m <d-news autark.se> wrote:On 2010-11-16 01:10, Daniel Murphy wrote:ittedI think allowing the second expression in the ternary operator to be om==20 Yes, then it becomes a binary operator :-) Read "a if defined, else b". Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.comwould be a better fit for D, and provide the same function. ie. auto x =3D a ? a : b; auto x =3D a ? : b;=20 Personally I had '|||' in mind, but I'm OK with '?:'. I think it should=20 be one single token and not an extension of the tertiary operator, though: =20 auto x =3D condition ? a : b; // tertiary operator auto x =3D condition ? : b; // error, did you forget the middle operand? auto x =3D a ?: b; // OK
Nov 16 2010
spir Wrote:On Tue, 16 Nov 2010 09:44:06 +0100 Per Ångström <d-news autark.se> wrote:They now added Scala to scriptometer http://rigaux.org/language-study/scripting-language/ it sees abomination i/o classes don't stop it being better script language then d. What can do? Scala bad competition and straight better. Next release has std.script?On 2010-11-16 01:10, Daniel Murphy wrote:Yes, then it becomes a binary operator :-) Read "a if defined, else b". Denis -- -- -- -- -- -- -- vit esse estrany ☣ spir.wikidot.comI think allowing the second expression in the ternary operator to be omitted would be a better fit for D, and provide the same function. ie. auto x = a ? a : b; auto x = a ? : b;Personally I had '|||' in mind, but I'm OK with '?:'. I think it should be one single token and not an extension of the tertiary operator, though: auto x = condition ? a : b; // tertiary operator auto x = condition ? : b; // error, did you forget the middle operand? auto x = a ?: b; // OK
Nov 16 2010
"Script mode" (actually - simple wrapper) would be better: It could do simple parsing of script, bringing all "import" clauses to the beginning and add some default imports (like std.stdio). It seems that all code below imports can be wrapped into main declaration. So for writeln("hello, world!"); we get import std.stdio; int main(char[] argv) { writeln("hello, world!"); return 0; } Trick will be to intercept error messages and change line numbers in them to correct. 2010/11/16 gooba <gooba digitalmars.com>:spir Wrote:omittedOn Tue, 16 Nov 2010 09:44:06 +0100 Per =C3=85ngstr=C3=B6m <d-news autark.se> wrote:On 2010-11-16 01:10, Daniel Murphy wrote:I think allowing the second expression in the ternary operator to be=dwould be a better fit for D, and provide the same function. ie. auto x =3D a ? a : b; auto x =3D a ? : b;Personally I had '|||' in mind, but I'm OK with '?:'. I think it shoul=ugh:be one single token and not an extension of the tertiary operator, tho=d?auto x =3D condition ? a : b; // tertiary operator auto x =3D condition ? : b; // error, did you forget the middle operan=ipting-language/ it sees abomination i/o classes don't stop it being better= script language then d. What can do? Scala bad competition and straight be= tter. Next release has std.script?They now added Scala to scriptometer http://rigaux.org/language-study/scr=auto x =3D a ?: b; // OKYes, then it becomes a binary operator :-) Read "a if defined, else b". Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.com--=20 =D0=A1 =D1=83=D0=B2=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC, =D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9 =D0=A5=D0=BC=D0=B0=D1=80=D0=B0
Nov 16 2010
"Script mode" (actually - simple wrapper) would be better: It could do simple parsing of script, bringing all "import" clauses to the beginning and add some default imports (like std.stdio). It seems that all code below imports can be wrapped into main declaration.My rund.d program does this. http://arsdnet.net/dcode/rund.d As you can see, it's a trivial program.
Nov 16 2010
I really think that it would be good to ship something like this with dmd and promote it default "D script" handler. May be, parsing must be more complicated (I'm not sure that all features will work inside main()), but as D is easy for parsing I see no big problems.Of cource, we can add more complicated code wrapper - for example, something that will give null when trying to get non-existant arg, or default key hadling, or something else. Of cource, special module also could be useful for this purpose. Hmm, it's interesting to write this toy... Compiled language being as easy as script at least looks interesting, so this can help to promote D with minimal resources involved. 2010/11/16 Adam Ruppe <destructionator gmail.com>:--=20 =F3 =D5=D7=C1=D6=C5=CE=C9=C5=CD, =E1=CC=C5=CB=D3=C5=CA =E8=CD=C1=D2=C1"Script mode" =9A(actually - simple wrapper) would be better: It could do simple parsing of script, bringing all "import" clauses to the beginning and add some default imports (like std.stdio). It seems that all code below imports can be wrapped into main declaration.My rund.d program does this. http://arsdnet.net/dcode/rund.d As you can see, it's a trivial program.
Nov 16 2010
Daniel Murphy, el 16 de noviembre a las 10:10 me escribiste:"Per ngstrm" <d-news autark.se> wrote in message news:ibr8bs$22mu$1 digitalmars.com...Yes, the "elvis operator" ?: -- Leandro Lucarella (AKA luca) http://llucax.com.ar/ ---------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------- Sometimes I think the sure sign that life exists elsewhere in the universe Is that that none of them tried to contact usreturn s || "default";I think allowing the second expression in the ternary operator to be omitted would be a better fit for D, and provide the same function. ie. auto x = a ? a : b; auto x = a ? : b; I think bearophile might have already proposed this?
Nov 16 2010
By the way, I found a bug that I think is quite serious if DMD wants to hit the scripting languages world: http://d.puremagic.com/issues/show_bug.cgi?id=5243 Copied for convenience: dmd -run potentially removes user files See this example: $ mkdir x $ echo 'void main() {}' > x/test.d $ echo "my very important data that shouldn't be ereased" > test $ ls test test $ cat test my very important data that shouldn't be ereased $ dmd -run x/test.d $ ls test ls: cannot access test: No such file or directory $ cat test cat: test: No such file or directory I think this is a very serious bug. It's really unexpected that DMD removes the test file (I can understand why it happens, but it shouldn't). test.d being in another directory is just to point how much surprising could be that running a "script" in an unrelated directory removes files in the current directory. If DMD wants to put D in the scripting world, this should be fixed ASAP, as no scripting language EVER will remove your files unexpectedly. -- Leandro Lucarella (AKA luca) http://llucax.com.ar/ ---------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------- SATANAS EN COMISARIA -- Crónica TV
Nov 19 2010
On 07/11/2010 21:29, Tomek Sowiski wrote:This wraps up a thread from a few days ago. Pascal featured my D examples on his Scriptometer site. http://rigaux.org/language-study/scripting-language/ D comes 17th out of 28, so it's so-so for scripting.Hum, nice, I think this is a very interesting benchmark/metric. -- Bruno Medeiros - Software Engineer
Nov 26 2010