www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - A C++ interpreter

reply "bearophile" <bearophileHUGS lycos.com> writes:
This not at the top of my enhancement request list, but having 
something like this shared by all D compilers seems a step 
forward for D:

http://blog.coldflake.com/posts/2012-08-09-On-the-fly-C%2B%2B.html

I use the Python shell all the time, for things like:
- As a calculator able to do basic things;
- to import files and process them on the fly in some ways (some 
of the things that are also doable with Unix shell commands);
- importing libraries to do lot of things, like graphing with 
matPlotLib;
- To try and fix lines/snippets of code to integrate in Python 
programs;
- To try things that later I will put inside unit tests 
(especially doctests);
- To import whole modules from the shell and try them, to see if 
they work, to understand how they need to be used, to try ideas 
to debug them, and so on.

There is a shell in Scala too:
http://www.scala-lang.org/node/166

Bye,
bearophile
Aug 12 2012
next sibling parent Marco Leise <Marco.Leise gmx.de> writes:
Am Mon, 13 Aug 2012 01:56:01 +0200
schrieb "bearophile" <bearophileHUGS lycos.com>:

 This not at the top of my enhancement request list, but having 
 something like this shared by all D compilers seems a step 
 forward for D:
 
 http://blog.coldflake.com/posts/2012-08-09-On-the-fly-C%2B%2B.html
 
 I use the Python shell all the time, for things like:
 - As a calculator able to do basic things;
 - to import files and process them on the fly in some ways (some 
 of the things that are also doable with Unix shell commands);
 - importing libraries to do lot of things, like graphing with 
 matPlotLib;
 - To try and fix lines/snippets of code to integrate in Python 
 programs;
 - To try things that later I will put inside unit tests 
 (especially doctests);
 - To import whole modules from the shell and try them, to see if 
 they work, to understand how they need to be used, to try ideas 
 to debug them, and so on.
 
 There is a shell in Scala too:
 http://www.scala-lang.org/node/166
 
 Bye,
 bearophile
Man, and I've been using JavaScript and a browser to prototype... While that's true, I also have a project called 'test' always open in MonoDevelop, so this is my ready to use main function. Sometimes I copy that code over into proper module, if it looks generally useful. -- Marco
Aug 12 2012
prev sibling next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 8/13/12, bearophile <bearophileHUGS lycos.com> wrote:
 http://blog.coldflake.com/posts/2012-08-09-On-the-fly-C%2B%2B.html
http://dlang.org/rdmd.html
Aug 12 2012
next sibling parent reply Marco Leise <Marco.Leise gmx.de> writes:
Am Mon, 13 Aug 2012 05:38:01 +0200
schrieb Andrej Mitrovic <andrej.mitrovich gmail.com>:

 On 8/13/12, bearophile <bearophileHUGS lycos.com> wrote:
 http://blog.coldflake.com/posts/2012-08-09-On-the-fly-C%2B%2B.html
http://dlang.org/rdmd.html
Aw come on, that is not a shell -- Marco
Aug 12 2012
next sibling parent reply "Era Scarecrow" <rtcvb32 yahoo.com> writes:
On Monday, 13 August 2012 at 04:25:19 UTC, Marco Leise wrote:
 Am Mon, 13 Aug 2012 05:38:01 +0200
 schrieb Andrej Mitrovic <andrej.mitrovich gmail.com>:

 On 8/13/12, bearophile <bearophileHUGS lycos.com> wrote:
 http://blog.coldflake.com/posts/2012-08-09-On-the-fly-C%2B%2B.html
http://dlang.org/rdmd.html
Aw come on, that is not a shell
Isn't rdmd just a wrapper for the compiler, then calls the compiled code (or previously saved version of it) afterwards? (That's the impression I get anyways)
Aug 12 2012
next sibling parent reply Russel Winder <russel winder.org.uk> writes:
On Mon, 2012-08-13 at 07:53 +0200, Era Scarecrow wrote:
 On Monday, 13 August 2012 at 04:25:19 UTC, Marco Leise wrote:
 Am Mon, 13 Aug 2012 05:38:01 +0200
 schrieb Andrej Mitrovic <andrej.mitrovich gmail.com>:

 On 8/13/12, bearophile <bearophileHUGS lycos.com> wrote:
 http://blog.coldflake.com/posts/2012-08-09-On-the-fly-C%2B%2B.html
=20 http://dlang.org/rdmd.html
Aw come on, that is not a shell
=20 Isn't rdmd just a wrapper for the compiler, then calls the=20 compiled code (or previously saved version of it) afterwards?=20 (That's the impression I get anyways)
Shells such as Python, Scala, etc. are good for some one-off experiments and tasks, but I think in general they are over-rated in general usefulness. Much better for non-trivial experimentation is to have a super-lightweight editor/execution. Groovy has GroovyConsole, Python has IDLE. Personally I find Emacs/rdmd excellent as an experimentation combination for D codes. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Aug 12 2012
next sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Russel Winder:

 Shells such as Python, Scala, etc. are good for some one-off 
 experiments
 and tasks, but I think in general they are over-rated in 
 general usefulness.
To me they seem underrated, go figure :-) In Python I use it all the time. Maybe in D it will be a little less useful. Bye, bearophile
Aug 13 2012
parent Matt Soucy <msoucy csh.rit.edu> writes:
On 08/13/2012 04:42 AM, bearophile wrote:
 Russel Winder:

 Shells such as Python, Scala, etc. are good for some one-off experiments
 and tasks, but I think in general they are over-rated in general
 usefulness.
To me they seem underrated, go figure :-) In Python I use it all the time. Maybe in D it will be a little less useful. Bye, bearophile
Agreed, I use Python's shell often at work - usually when I just need to test something, but sometimes when someone else asks me for a particular script that does something that (I feel) is only really good for their one situation. I use the scripts I have already and just manually write up a comprehension or five to convert the data into a format that will be useful for them. It doesn't seem worth the effort to make a whole new script just for that. -Matt Soucy
Aug 13 2012
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2012-08-13 08:51, Russel Winder wrote:

 Shells such as Python, Scala, etc. are good for some one-off experiments
 and tasks, but I think in general they are over-rated in general
 usefulness.  Much better for non-trivial experimentation is to have a
 super-lightweight editor/execution. Groovy has GroovyConsole, Python has
 IDLE. Personally I find Emacs/rdmd excellent as an experimentation
 combination for D codes.
I'm using TextMate (Mac OS X) and rdmd. I just create a new document, type the code and run it from within TextMate. I don't even have to save the document. I probably should make it so it automatically wraps the code in a main function for even easier and more script like usage. -- /Jacob Carlborg
Aug 13 2012
next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2012-08-13 16:03, Jacob Carlborg wrote:

 I'm using TextMate (Mac OS X) and rdmd. I just create a new document,
 type the code and run it from within TextMate. I don't even have to save
 the document. I probably should make it so it automatically wraps the
 code in a main function for even easier and more script like usage.
BTW, I'm using the same method with Ruby as well. I prefer this over the IRB, the Ruby shell. I mean, I have syntax highlighting and other nice features I'm missing in the shell. -- /Jacob Carlborg
Aug 13 2012
parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 8/13/12, Jacob Carlborg <doob me.com> wrote:
 On 2012-08-13 16:03, Jacob Carlborg wrote:

 I'm using TextMate (Mac OS X) and rdmd. I just create a new document,
 type the code and run it from within TextMate. I don't even have to save
 the document. I probably should make it so it automatically wraps the
 code in a main function for even easier and more script like usage.
BTW, I'm using the same method with Ruby as well. I prefer this over the IRB, the Ruby shell. I mean, I have syntax highlighting and other nice features I'm missing in the shell.
+ it's easier to re-edit or copy code in a text editor than in a shell.
Aug 13 2012
prev sibling parent reply "jerro" <a a.com> writes:
 I probably should make it so it automatically wraps the code in 
 a main function for even easier and more script like usage.
Rdmd already has this functionality with the --eval flag. You are supposed to pass the code as a command line parameter, but you can use it with files like this: cat - test.d <<< "--eval=" | xargs -0 rdmd I've only tried this on Linux.
Aug 13 2012
next sibling parent reply Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On Mon, 13 Aug 2012 17:36:13 +0200
"jerro" <a a.com> wrote:

 I probably should make it so it automatically wraps the code in 
 a main function for even easier and more script like usage.
Rdmd already has this functionality with the --eval flag. You are supposed to pass the code as a command line parameter, but you can use it with files like this: cat - test.d <<< "--eval=" | xargs -0 rdmd I've only tried this on Linux.
As a person who's still only half-way a Linux guy, I have to ask: What the hell is going on in that command? I understand bits and pieces of it, but my mind's having a hard time parsing it. Can any of you unix gurus help me out?
Aug 13 2012
next sibling parent "jerro" <a a.com> writes:
 cat - test.d <<< "--eval=" | xargs -0 rdmd
 
 I've only tried this on Linux.
As a person who's still only half-way a Linux guy, I have to ask: What the hell is going on in that command?
The minus on the cat command line means standard input and somecommand <<< "somestring" Sends "somestring" to the standard input of somecommand. So the first part here outputs the contents of test.d with --eval= prepended. That's what xargs get as a standard input. Xargs then calls rdmd with that string as a command line argument. The -0 flag tells xargs to treat the input as a bunch of zero separated strings and to treat backslashes and double quotes the same as other characters (the default is to treat newlines and spaces as separators and to use quotes and backslashes to prevent spliting strings on newlines and spaces). I did it that way to avoid issues with escaping characters.
 I understand bits and pieces of it, but my mind's having a hard 
 time
 parsing it. Can any of you unix gurus help me out?
I'm hardly a unix guru, I've been using linux for less than two years. I guess it's not hard to write hard to read bash commands :D
Aug 13 2012
prev sibling parent reply "Graham Fawcett" <fawcett uwindsor.ca> writes:
On Tuesday, 14 August 2012 at 04:09:22 UTC, Nick Sabalausky wrote:
 On Mon, 13 Aug 2012 17:36:13 +0200
 "jerro" <a a.com> wrote:

 I probably should make it so it automatically wraps the code 
 in a main function for even easier and more script like 
 usage.
Rdmd already has this functionality with the --eval flag. You are supposed to pass the code as a command line parameter, but you can use it with files like this: cat - test.d <<< "--eval=" | xargs -0 rdmd I've only tried this on Linux.
As a person who's still only half-way a Linux guy, I have to ask: What the hell is going on in that command? I understand bits and pieces of it, but my mind's having a hard time parsing it. Can any of you unix gurus help me out?
Run the "cat" program, which prints two file contents: the first file is stdin (denoted by "-"), which contains the text "--eval=", via the <<< redirector. Cat then prints the contents of test.d. All of this is piped in to "xargs", which calls dmd along with the command line arguments consisting of the piped input. It's overly complicated. Try this instead: rdmd --eval="$(cat test.d)" Best, Graham
Aug 17 2012
parent "Graham Fawcett" <fawcett uwindsor.ca> writes:
On Friday, 17 August 2012 at 12:53:50 UTC, Graham Fawcett wrote:
 On Tuesday, 14 August 2012 at 04:09:22 UTC, Nick Sabalausky 
 wrote:
 On Mon, 13 Aug 2012 17:36:13 +0200
 "jerro" <a a.com> wrote:

 I probably should make it so it automatically wraps the 
 code in a main function for even easier and more script 
 like usage.
Rdmd already has this functionality with the --eval flag. You are supposed to pass the code as a command line parameter, but you can use it with files like this: cat - test.d <<< "--eval=" | xargs -0 rdmd I've only tried this on Linux.
As a person who's still only half-way a Linux guy, I have to ask: What the hell is going on in that command? I understand bits and pieces of it, but my mind's having a hard time parsing it. Can any of you unix gurus help me out?
Run the "cat" program, which prints two file contents: the first file is stdin (denoted by "-"), which contains the text "--eval=", via the <<< redirector. Cat then prints the contents of test.d. All of this is piped in to "xargs", which calls dmd along with the command line arguments consisting of the piped input. It's overly complicated. Try this instead: rdmd --eval="$(cat test.d)" Best, Graham
I meant to add, the point of this appears to be that you can execute a "toplevel expression." So test.d should contain bare statements, e.g. import std.stdio; writeln("hi"); rather than void main() { import std.stdio; writeln("hi"); }
Aug 17 2012
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-08-13 17:36, jerro wrote:

 Rdmd already has this functionality with the --eval flag. You are
 supposed to pass the code as a command line parameter, but you can use
 it with files like this:

 cat - test.d <<< "--eval=" | xargs -0 rdmd

 I've only tried this on Linux.
Yeah, but I need to hook it up from within TextMate, which isn't a problem. -- /Jacob Carlborg
Aug 14 2012
prev sibling parent "Mehrdad" <wfunction hotmail.com> writes:
On Monday, 13 August 2012 at 15:36:15 UTC, jerro wrote:
 Rdmd already has this functionality with the --eval flag. You 
 are supposed to pass the code as a command line parameter, but 
 you can use it with files like this:

 cat - test.d <<< "--eval=" | xargs -0 rdmd
Wow, no wonder I never found it handy in Windows...
Aug 14 2012
prev sibling next sibling parent Brad Anderson <eco gnuk.net> writes:
On Mon, Aug 13, 2012 at 12:51 AM, Russel Winder <russel winder.org.uk>wrote:

 On Mon, 2012-08-13 at 07:53 +0200, Era Scarecrow wrote:
 On Monday, 13 August 2012 at 04:25:19 UTC, Marco Leise wrote:
 Am Mon, 13 Aug 2012 05:38:01 +0200
 schrieb Andrej Mitrovic <andrej.mitrovich gmail.com>:

 On 8/13/12, bearophile <bearophileHUGS lycos.com> wrote:
 http://blog.coldflake.com/posts/2012-08-09-On-the-fly-C%2B%2B.html
http://dlang.org/rdmd.html
Aw come on, that is not a shell
Isn't rdmd just a wrapper for the compiler, then calls the compiled code (or previously saved version of it) afterwards? (That's the impression I get anyways)
Shells such as Python, Scala, etc. are good for some one-off experiments and tasks, but I think in general they are over-rated in general usefulness. Much better for non-trivial experimentation is to have a super-lightweight editor/execution. Groovy has GroovyConsole, Python has IDLE. Personally I find Emacs/rdmd excellent as an experimentation combination for D codes. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
I just use http://dpaste.dzfl.pl for my quick testing. I do miss not having vim keybindings but I do gain dmd-git support without the pain of setting it up locally. I'm often testing stuff during a discussion in #D IRC so the site makes it much easier to share as well. BA
Aug 13 2012
prev sibling parent 1100110 <10equals2 gmail.com> writes:
On Mon, 13 Aug 2012 01:51:17 -0500, Russel Winder <russel winder.org.uk>  
wrote:

 On Mon, 2012-08-13 at 07:53 +0200, Era Scarecrow wrote:
 On Monday, 13 August 2012 at 04:25:19 UTC, Marco Leise wrote:
 Am Mon, 13 Aug 2012 05:38:01 +0200
 schrieb Andrej Mitrovic <andrej.mitrovich gmail.com>:

 On 8/13/12, bearophile <bearophileHUGS lycos.com> wrote:
 http://blog.coldflake.com/posts/2012-08-09-On-the-fly-C%2B%2B.html
http://dlang.org/rdmd.html
Aw come on, that is not a shell
Isn't rdmd just a wrapper for the compiler, then calls the compiled code (or previously saved version of it) afterwards? (That's the impression I get anyways)
Shells such as Python, Scala, etc. are good for some one-off experiments and tasks, but I think in general they are over-rated in general usefulness. Much better for non-trivial experimentation is to have a super-lightweight editor/execution. Groovy has GroovyConsole, Python has IDLE. Personally I find Emacs/rdmd excellent as an experimentation combination for D codes.
Here come the flames, but check out vim + the D Syntastic plugin. (not you in particular. =P) I have it set to check every time I save the file. This, coupled with a barebones.d file, allows easy experimentation. It highlights the error the line is on, and shows the error msg when you are on that line. -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Aug 19 2012
prev sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 8/13/12, Marco Leise <Marco.Leise gmx.de> wrote:
 Am Mon, 13 Aug 2012 05:38:01 +0200
 schrieb Andrej Mitrovic <andrej.mitrovich gmail.com>:

 On 8/13/12, bearophile <bearophileHUGS lycos.com> wrote:
 http://blog.coldflake.com/posts/2012-08-09-On-the-fly-C%2B%2B.html
http://dlang.org/rdmd.html
Aw come on, that is not a shell
That C++ blog post begins with talking how hard it is to just compile something to test things out. All I ever have to do is hit CTRL+ALT+J and I get a new D file opened in my editor with some common Phobos imports. Then I hit F4 and RDMD compiles and runs the app. I've been using this for years, I've got well over 1000 files in my test directory. I don't see what a shell can provide when building D scripts is so damn fast anyway. :)
Aug 13 2012
prev sibling parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 13-Aug-12 07:38, Andrej Mitrovic wrote:
 On 8/13/12, bearophile <bearophileHUGS lycos.com> wrote:
 http://blog.coldflake.com/posts/2012-08-09-On-the-fly-C%2B%2B.html
http://dlang.org/rdmd.html
Also check the --eval and --loop thingy ;) -- Dmitry Olshansky
Aug 13 2012
prev sibling next sibling parent reply "Era Scarecrow" <rtcvb32 yahoo.com> writes:
On Sunday, 12 August 2012 at 23:56:02 UTC, bearophile wrote:
 This not at the top of my enhancement request list, but having 
 something like this shared by all D compilers seems a step 
 forward for D:

 http://blog.coldflake.com/posts/2012-08-09-On-the-fly-C%2B%2B.html
There's also CInt, but I've never tried it myself. http://root.cern.ch/drupal/content/cint
Aug 13 2012
parent Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On Mon, 13 Aug 2012 14:13:19 +0200
"Era Scarecrow" <rtcvb32 yahoo.com> wrote:

 On Sunday, 12 August 2012 at 23:56:02 UTC, bearophile wrote:
 This not at the top of my enhancement request list, but having 
 something like this shared by all D compilers seems a step 
 forward for D:

 http://blog.coldflake.com/posts/2012-08-09-On-the-fly-C%2B%2B.html
There's also CInt, but I've never tried it myself. http://root.cern.ch/drupal/content/cint
Heh, "CInt" sounds more like a boxed integer :)
Aug 13 2012
prev sibling parent "Dejan Lekic" <dejan.lekic gmail.com> writes:
On Sunday, 12 August 2012 at 23:56:02 UTC, bearophile wrote:
 This not at the top of my enhancement request list, but having 
 something like this shared by all D compilers seems a step 
 forward for D:

 http://blog.coldflake.com/posts/2012-08-09-On-the-fly-C%2B%2B.html

 I use the Python shell all the time, for things like:
 - As a calculator able to do basic things;
 - to import files and process them on the fly in some ways 
 (some of the things that are also doable with Unix shell 
 commands);
 - importing libraries to do lot of things, like graphing with 
 matPlotLib;
 - To try and fix lines/snippets of code to integrate in Python 
 programs;
 - To try things that later I will put inside unit tests 
 (especially doctests);
 - To import whole modules from the shell and try them, to see 
 if they work, to understand how they need to be used, to try 
 ideas to debug them, and so on.

 There is a shell in Scala too:
 http://www.scala-lang.org/node/166

 Bye,
 bearophile
Doing shell scripting in ANY language not designed for shell scripting is the same as shooting yourself in the foot with AK-47 ... Whoever does that is just blindly loyal to the language. Following BASH one-liner will (hopefully) explain my point. -Try to implement the following in D, Scala, and any other language not made for shell scripting: history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -n | tail | sort -nr It will output 10 most used commands in your shell.
Aug 17 2012