digitalmars.D - Interactive D?
- Oskar Linde (71/99) Feb 22 2008 I got the idea to investigate the possibility of an interactive D
- bearophile (5/9) Feb 22 2008 A interactive shell interpreter is very useful to learn the language, an...
- Oskar Linde (25/33) Feb 23 2008 I don't use exe-lib. What Burton Radons has done is seriously impressive...
- oliver (7/26) Feb 24 2008 This sounds both interesting and helpful! I often find that a repl reduc...
- renoX (6/20) Feb 24 2008 Well D being statically typed and this 'interactive D' being dynamically...
- Oskar Linde (8/23) Feb 26 2008 The only part where the dynamical typing takes place is during
- Jarrett Billingsley (5/11) Feb 22 2008 [snip a ton of amazingness]
- torhu (4/9) Feb 22 2008 This is definitely interesting. I remember wanting something like this
- Alexander Panek (4/9) Feb 22 2008 Awesome! How are you doing this? Wrapping your constructs into int main
- Ary Borenszweig (2/7) Feb 22 2008
- =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= (8/12) Feb 22 2008 I've been waiting for a repl for years. Great work.
- Oskar Linde (25/47) Feb 26 2008 a = [1,2,3] (int[])
- Jarrett Billingsley (4/15) Feb 26 2008 This one is correct, as far as I can see. A!(int) a; is just sugar for
- Oskar Linde (13/37) Feb 26 2008 Nope, if implicit template properties is in action, A!(int) is the only
- Jarrett Billingsley (7/17) Feb 26 2008 Ah, I see. You're right that A!(int).A does not compile.
- Matti Niemenmaa (32/46) Feb 26 2008 Don't forget that .stringof can be overridden in structs/classes. For in...
- =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= (15/60) Feb 26 2008 Oh god. Here's some other results of overriding properties. Again some
- =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= (16/42) Feb 26 2008 This message is in MIME format. The first part should be readable tex...
- bearophile (6/9) Mar 06 2008 Now I have realized that such interpreter may allow to port to D one *wo...
I got the idea to investigate the possibility of an interactive D interpreter. A lazy afternoon of hacking resulted in a proof of concept, and what follows is a short demo. Could there be any interest in pursuing this? $ ./interactiveD Interactive D version 0.0.1 Type "help" for more information.ans = 2 (int)1+1x = 2 (int)x = 2x = 10 (double)x = x * 5.0ans = 10 (double)x++Variables: x = 11 (double) ans = 10 (double)whoinput:1: Error: undefined identifier foo input:1: Error: function expected before (), not foo of type int Failed to evaluatefoo(5)import testans = 26 (int)foo(5)test.d changed on disk. Recompiling. ans = 25 (int)foo(5)import std.mathans = 0.540302 (real)cos(1.0)import std.stdioHello Worldwritefln("Hello World")a = [1,5] (test.Vec)a = Vec(1,5)b = [3,2] (test.Vec)b = Vec(3,2)ans = [4,7] (test.Vec)a+bImports: test std.mathimportimport std.stringans = [l,e,.,,s] (char[][])"a b c d e".split()ans = [a,b,c,d,e] (char[][])"a b c d e".dup.split()import multiarrayx = (3x4) 0 0 0 0 0 0 0 0 0 0 0 0 (multiarray.ArraySlice!(int,2))x = ArraySlice!(int,2)(3,4)ans = (3) 1 1 1 (multiarray.ArraySlice!(int,1))x.diag[] = 1ans = (3x4) 1 0 0 0 1 0 0 0 1 0 0 0 (multiarray.ArraySlice!(int,2))xx.transpose()ans = (4x3) 1 0 0 0 0 1 0 0 0 0 1 0 (multiarray.ArraySlice!(int,2))xans = (4) 2 2 2 2 (multiarray.ArraySlice!(int,1))x[range(0,$), 1] = 2ans = (4x3) 1 0 0 0 2 2 2 2 0 0 1 0 (multiarray.ArraySlice!(int,2)) -- Oskarx
Feb 22 2008
Oskar Linde:I got the idea to investigate the possibility of an interactive D interpreter. A lazy afternoon of hacking resulted in a proof of concept, and what follows is a short demo. Could there be any interest in pursuing this?A interactive shell interpreter is very useful to learn the language, and to try little snippets of code before copying them into the code. Python and Scheme programmers do it all the time, and it's one of the advantages of those languages. So I think this may become quite useful. How does it work? Do you use the run-time compiler lib recently announced? Bye, bearophile
Feb 22 2008
bearophile wrote:Oskar Linde:I don't use exe-lib. What Burton Radons has done is seriously impressive and is a much bigger project than my small hack. I have constrained myself to using the system built-in dynamic linking tools (dlopen,dlclose et. al. or LoadLibrary/FreeLibrary on win32). What the code does is basically creating some run-time d-code wrapping the expression together with some helpers to feed data and type information back and forth. It then compiles the generated code into object code and transforms it into a dynamic library loadable with dlopen. The generated library is then loaded, executed and unloaded within the interpreters memory space. The "import" statement compiles the corresponding .d source file and its dependencies into one dynamic library per module, and then loads them into the interpreter. If, at any time, a .d source file is changed the corresponding module (and modules depending on that module) are unloaded, recompiled and reloaded. Burton's approach seems very interesting though. Not primarily speed wise, since interactive speeds are enough for an interactive application and a 50 ms delay compared to Burton's 1 ms is not very noticeable. Instead, the major advantage of exe-lib is that it allows a much finer control over library loading than the blunt dlopen/LoadLibrary. For example, the possibility of having a callback resolving missing symbols would be extremely useful. -- OskarI got the idea to investigate the possibility of an interactive D interpreter. A lazy afternoon of hacking resulted in a proof of concept, and what follows is a short demo. Could there be any interest in pursuing this?A interactive shell interpreter is very useful to learn the language, and to try little snippets of code before copying them into the code. Python and Scheme programmers do it all the time, and it's one of the advantages of those languages. So I think this may become quite useful. How does it work? Do you use the run-time compiler lib recently announced?
Feb 23 2008
Oskar Linde Wrote:bearophile wrote:This sounds both interesting and helpful! I often find that a repl reduces development time. [...snip....]Oskar Linde:I got the idea to investigate the possibility of an interactive D interpreter. A lazy afternoon of hacking resulted in a proof of concept, and what follows is a short demo. Could there be any interest in pursuing this?What the code does is basically creating some run-time d-code wrapping the expression together with some helpers to feed data and type information back and forth. It then compiles the generated code into object code and transforms it into a dynamic library loadable with dlopen. The generated library is then loaded, executed and unloaded within the interpreters memory space. The "import" statement compiles the corresponding .d source file and its dependencies into one dynamic library per module, and then loads them into the interpreter. If, at any time, a .d source file is changed the corresponding module (and modules depending on that module) are unloaded, recompiled and reloaded.I am curious on how you did that. Did you put the code somewhere (dsource) to look at? Is it possible to write some text file with a couple of commands, read that into the interpreter and, once i like the output, compile it? [ ...snip...] Oliver
Feb 24 2008
bearophile a écrit :Oskar Linde:Well D being statically typed and this 'interactive D' being dynamically typed, I'm not sure that the interpreter is usable for this purpose. That said, I'm quite impressed with the work.. Only one afternoon of work? Wow! renoXI got the idea to investigate the possibility of an interactive D interpreter. A lazy afternoon of hacking resulted in a proof of concept, and what follows is a short demo. Could there be any interest in pursuing this?A interactive shell interpreter is very useful to learn the language, and to try little snippets of code before copying them into the code.Python and Scheme programmers do it all the time, and it's one of the advantages of those languages. So I think this may become quite useful. How does it work? Do you use the run-time compiler lib recently announced? Bye, bearophile
Feb 24 2008
renoX wrote:bearophile a écrit :The only part where the dynamical typing takes place is during assignment to the interactive variables. One could quite easily remove that dynamic typing. It was just easier doing it this way. :)Oskar Linde:Well D being statically typed and this 'interactive D' being dynamically typed, I'm not sure that the interpreter is usable for this purpose.I got the idea to investigate the possibility of an interactive D interpreter. A lazy afternoon of hacking resulted in a proof of concept, and what follows is a short demo. Could there be any interest in pursuing this?A interactive shell interpreter is very useful to learn the language, and to try little snippets of code before copying them into the code.That said, I'm quite impressed with the work.. Only one afternoon of work? Wow!I'll put the code online in a few days so you can see that it is much less impressive than it might seem. :P -- Oskar
Feb 26 2008
"Oskar Linde" <oskar.lindeREM OVEgmail.com> wrote in message news:fpmpa6$2muq$1 digitalmars.com...I got the idea to investigate the possibility of an interactive D interpreter. A lazy afternoon of hacking resulted in a proof of concept, and what follows is a short demo. Could there be any interest in pursuing this?[snip a ton of amazingness]-- Oskar:O I think you get a cookie for this. Nay, an entire _cake_.
Feb 22 2008
Oskar Linde wrote:I got the idea to investigate the possibility of an interactive D interpreter. A lazy afternoon of hacking resulted in a proof of concept, and what follows is a short demo. Could there be any interest in pursuing this?This is definitely interesting. I remember wanting something like this a while ago. If it's properly done, it could move D one step closer to Python. Interactive testing of algorithms is very handy.
Feb 22 2008
Oskar Linde wrote:I got the idea to investigate the possibility of an interactive D interpreter. A lazy afternoon of hacking resulted in a proof of concept, and what follows is a short demo. Could there be any interest in pursuing this?Awesome! How are you doing this? Wrapping your constructs into int main () {} and returning/outputting the result of the operation, catching the pipe and pretty-printing it? Anyways, impressive!
Feb 22 2008
I would love to see that as a Descent view. It looks really awesome! Oskar Linde escribió:I got the idea to investigate the possibility of an interactive D interpreter. A lazy afternoon of hacking resulted in a proof of concept, and what follows is a short demo. Could there be any interest in pursuing this?
Feb 22 2008
On Fri, 22 Feb 2008, Oskar Linde wrote:I got the idea to investigate the possibility of an interactive D interpreter. A lazy afternoon of hacking resulted in a proof of concept, and what follows is a short demo. Could there be any interest in pursuing this?I've been waiting for a repl for years. Great work. Some further ideas: catching exceptions, displaying the values and types of structs/classes and their members recursively (if the default uses toString) -- hopefully this will encourage Walter to fix some of the unspecified behavior with .stringof, exporting the current state to a file, locating symbol definitions.
Feb 22 2008
Jari-Matti Mäkelä wrote:On Fri, 22 Feb 2008, Oskar Linde wrote:Catching exceptions actually already work:I got the idea to investigate the possibility of an interactive D interpreter. A lazy afternoon of hacking resulted in a proof of concept, and what follows is a short demo. Could there be any interest in pursuing this?I've been waiting for a repl for years. Great work. Some further ideas: catching exceptions, displaying the values and types of structs/classes and their members recursively (if the default uses toString) -- hopefully this will encourage Walter to fix some of the unspecified behavior with .stringof, exporting the current state to a file, locating symbol definitions.a = [1,2,3] (int[])a = [1,2,3][]ArrayBoundsError input(1)a[3] = 4ans = [1,2,3,4] (int[]) Regarding stringof. The following is irritating, given: template A(T) { struct A {} } template B(T) { struct A {} struct B {} } A!(int) a; B!(int).B b; How do I reliably get the string representation of the type of a and b? There are two ways that I know of: 1. typeid(typeof(x)).toString 2. typeof(x).stringof The problem is that the results are: 1A: test.A!(int).A WRONG 1B: test.B!(int).B CORRECT 2A: A!(int) CORRECT (although not fully qualified) 2B: B WRONG So neither way works for both cases... Your other points are interesting and useful, but some of them are quite hard. I can't do much more than the D compiler can do at compile + runtime together. -- Oskara ~= 4
Feb 26 2008
"Oskar Linde" <oskar.lindeREM OVEgmail.com> wrote in message news:fq126m$enh$1 digitalmars.com...Regarding stringof. The following is irritating, given: template A(T) { struct A {} } template B(T) { struct A {} struct B {} } A!(int) a; B!(int).B b; How do I reliably get the string representation of the type of a and b? There are two ways that I know of: 1. typeid(typeof(x)).toString 2. typeof(x).stringof The problem is that the results are: 1A: test.A!(int).A WRONGThis one is correct, as far as I can see. A!(int) a; is just sugar for A!(int).A a;.
Feb 26 2008
Jarrett Billingsley wrote:"Oskar Linde" <oskar.lindeREM OVEgmail.com> wrote in message news:fq126m$enh$1 digitalmars.com...Nope, if implicit template properties is in action, A!(int) is the only valid way to refer to the template instance. If that weren't the case, consider: template A(T) { struct A { int A; }} what is A!(int).A ? And that reminds me that this ( http://d.puremagic.com/issues/show_bug.cgi?id=242 ) ancient bug is still unresolved: template A() { template A() { alias int A; }} A!()!() x; // found '!' when expecting ';' following 'statement' -- OskarRegarding stringof. The following is irritating, given: template A(T) { struct A {} } template B(T) { struct A {} struct B {} } A!(int) a; B!(int).B b; How do I reliably get the string representation of the type of a and b? There are two ways that I know of: 1. typeid(typeof(x)).toString 2. typeof(x).stringof The problem is that the results are: 1A: test.A!(int).A WRONGThis one is correct, as far as I can see. A!(int) a; is just sugar for A!(int).A a;.
Feb 26 2008
"Oskar Linde" <oskar.lindeREM OVEgmail.com> wrote in message news:fq18lf$120r$1 digitalmars.com...Ah, I see. You're right that A!(int).A does not compile. However I can still understand that the compiler would stringize it as "A!(int).A", since that's how it's defined and how it's represented. I suppose that the question of whether .stringof should give compilable code or not is under debate.Nope, if implicit template properties is in action, A!(int) is the only valid way to refer to the template instance. If that weren't the case, consider: template A(T) { struct A { int A; }} what is A!(int).A ?1A: test.A!(int).A WRONGThis one is correct, as far as I can see. A!(int) a; is just sugar for A!(int).A a;.
Feb 26 2008
Oskar Linde wrote:Regarding stringof. The following is irritating, given: template A(T) { struct A {} } template B(T) { struct A {} struct B {} } A!(int) a; B!(int).B b; How do I reliably get the string representation of the type of a and b? There are two ways that I know of: 1. typeid(typeof(x)).toString 2. typeof(x).stringofDon't forget that .stringof can be overridden in structs/classes. For instance: import tango.io.Stdout; class A { static char[] stringof = "foo"; } class B {} void main() { A a; B b; Stdout(A.stringof).newline; Stdout(typeof(a).stringof).newline; Stdout((new A).stringof).newline; Stdout(B.stringof).newline; Stdout(typeof(b).stringof).newline; Stdout((new B).stringof).newline; } The above prints: foo foo foo B B new B So .stringof can't really be considered "reliable" per se. Library developers should probably always document in big, bold letters: ".stringof should never be redefined!!" I wouldn't be surprised if something like the above were to break much existing template code. (Although I don't really know how much .stringof is used in practice.) -- E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi
Feb 26 2008
On Tue, 26 Feb 2008, Matti Niemenmaa wrote:Oskar Linde wrote:Oh god. Here's some other results of overriding properties. Again some signs of inconsistency can be found: override can be used on property can be overridden runtime compiletime .stringof - y y y .tupleof - y n n .mangleof - n* n y .init - y y y .sizeof - n* n y * = override gives error, but still works on compile time Are there any good reasons for overriding any of those? The override doesn't even need to be of the same type.Regarding stringof. The following is irritating, given: template A(T) { struct A {} } template B(T) { struct A {} struct B {} } A!(int) a; B!(int).B b; How do I reliably get the string representation of the type of a and b? There are two ways that I know of: 1. typeid(typeof(x)).toString 2. typeof(x).stringofDon't forget that .stringof can be overridden in structs/classes. For instance: import tango.io.Stdout; class A { static char[] stringof = "foo"; } class B {} void main() { A a; B b; Stdout(A.stringof).newline; Stdout(typeof(a).stringof).newline; Stdout((new A).stringof).newline; Stdout(B.stringof).newline; Stdout(typeof(b).stringof).newline; Stdout((new B).stringof).newline; } The above prints: foo foo foo B B new B So .stringof can't really be considered "reliable" per se. Library developers should probably always document in big, bold letters: ".stringof should never be redefined!!"I wouldn't be surprised if something like the above were to break much existing template code. (Although I don't really know how much .stringof is used in practice.).stringof is pretty much the only way to provide decent compile time reflection with D1.
Feb 26 2008
This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---1463811840-1942746821-1204051296=:23763 Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8BIT On Tue, 26 Feb 2008, Oskar Linde wrote:Jari-Matti Mäkelä wrote:Cool.Some further ideas: catching exceptions, displaying the values and types of structs/classes and their members recursively (if the default uses toString) -- hopefully this will encourage Walter to fix some of the unspecified behavior with .stringof, exporting the current state to a file, locating symbol definitions.Catching exceptions actually already work:Regarding stringof. The following is irritating, given: template A(T) { struct A {} } template B(T) { struct A {} struct B {} } A!(int) a; B!(int).B b; How do I reliably get the string representation of the type of a and b? There are two ways that I know of: 1. typeid(typeof(x)).toString 2. typeof(x).stringof The problem is that the results are: 1A: test.A!(int).A WRONG 1B: test.B!(int).B CORRECT 2A: A!(int) CORRECT (although not fully qualified) 2B: B WRONGdemangle(x.mangleof), x.init.stringof, and typeid(typeof(x)).stringof) seem to be the only ways to return the full FQN (including template member names) on compile time, but one needs to have a demangle routine then first.Your other points are interesting and useful, but some of them are quite hard. I can't do much more than the D compiler can do at compile + runtime together.The reflection stuff should be possible to do on compile time (only enums fail). I'm not sure about exporting current state, now that I heard how the utility works. Locating definitions is probably the hardest and needs FQNs, maybe something more. ---1463811840-1942746821-1204051296=:23763--
Feb 26 2008
Oskar Linde:I got the idea to investigate the possibility of an interactive D interpreter. A lazy afternoon of hacking resulted in a proof of concept, and what follows is a short demo.Now I have realized that such interpreter may allow to port to D one *wonderful* thing present in the Python std lib, that I sorely miss, that is the doctest, it's the lowest-complexity unit testing (invented by Tim Peters and partially by Peter Norvig): http://docs.python.org/lib/module-doctest.html This module alone can justify this work of yours, Oskar. Bye, bearophile
Mar 06 2008