Re: Weird opEquals Problem
On 23 February 2012 15:55, H. S. Teoh hst...@quickfur.ath.cx wrote: On Wed, Feb 22, 2012 at 09:32:55PM -0500, Kevin wrote: [...] Thanks for all the help. Although you guys should be careful because if you keep giving such in depth answers I might start asking stupid questions just to learn the language in more depth :) We don't mind. :-) T -- Truth, Sir, is a cow which will give [skeptics] no more milk, and so they are gone to milk the bull. -- Sam. Johnson Just don't start asking too stupid questions (like how does 1+1 work?) :P. -- James Miller
Re: MySQL connection strange behavior (again...)
You are right, coffimplib with -e switch does it.
Wrapping c variadic functions
Say i have a c function (didn't include first format argument for simplicity) void print(...); I wrap it up: extern(System) void print(...); And then I try to wrap it up in some safer D way: void print(Args...)(Args args) { print(args); // only the first argument is printed } void print(...) { print(_argptr); // no go either } How am I supposed to do this? http://dlang.org/function.html#variadic doesn't make my any smarter.
DbC bug?
I think I've stumbled across a DbC bug. In an out-block, I have the assertion `assert(id objs.length);`. Now, if I don't have an in-block, this fails. However, if I add an in-block (with basically any code that isn't optimized away, or so it seems), the assertion succeeds. (Before this was an assertion, the failure was a range violation from objs[id]; the behavior is equivalent for that.) And this happens even though both id and objs are const...(!) And: If I place the same assertion just before the return statement (which just returns the result, without any computation), the assertion before return succeeds, but the one immediately inside the out block fails. Unless, of course, there is an in block, which magically fixes everything (without really doing anything). It seems that the id variable (a parameter of the method) is actually undefined in the out-block, and that this is the reason for the error. (The program is run with the same random seeds, but the id variable, which *should* be in 0..1000, ends up with varying values such as 1609528144, 1653547856 or 1816621904. I'm guessing this is a bug in the DbC functionality, somehow? Is it a known bug? (Couldn't find anything relevant -- but then again, I wasn't sure exactly what to search for...) My code runs lots of experiments, and this only happens after the method has been used a *lot* (i.e., this doesn't happen all the time -- though it *does* happen every time the program is run) -- which means producing a minimal example would require some effort... :-}
Re: Wrapping c variadic functions
On Thu, 23 Feb 2012 11:35:32 +0100, simendsjo simend...@gmail.com wrote: Say i have a c function (didn't include first format argument for simplicity) void print(...); I wrap it up: extern(System) void print(...); And then I try to wrap it up in some safer D way: void print(Args...)(Args args) { print(args); // only the first argument is printed } void print(...) { print(_argptr); // no go either } How am I supposed to do this? http://dlang.org/function.html#variadic doesn't make my any smarter. My bad. The first version works just fine. I passed a float and had the format string as %d...
IPC: Pipes std.process
I'm working on IPC's. I already figured out that the implementation depends on the operation system. Is there any solution to support both - windows posix systems? I'm developing on a win-machine and don't want to re-write my app on linux. As I saw on dlang.org, std.process of Phobos (prerelease) seems to support creating pipes for both system types. So I downloaded the latest version from https://github.com/kyllingstad/phobos/blob/new-std-process. When I run win32.mak using make -f win32.mak, I got the following error: Error: don't know how to make '..\druntime\lib\druntime.lib So, I first try to build druntime.lib using win32.make and I got: masm386 -DM_I386=1 -D_WIN32 -Mx src\rt\minit.asm; Can't run 'masm386', check PATH I also downloaded masm386 and I just get the following error: dmc -c src\rt\minit.asm masm386 -DM_I386=1 -D_WIN32 -Mx src\rt\minit.asm; Assembling: src\rt\minit.asm; MASM : fatal error A1000: cannot open file : src\rt\minit.asm; Does anyone know how to solve this error (minit.asm exists in src\rt\) or is there any other solution (for e.g. based on the stable version of phobos)? Thx in advance!
Re: Alias this with array can only be used once
Good points on why an explicit range distinction is desired; I probably should have looked harder at how std.container worked. I'm also probably spoiled/unlearning from C#'s IEnumerableT syntactic sugar (foreach over enumerator, LINQ) which handles most of these considerations for you. You could say it encourages conflating the container with the iteration mechanism (range in D, enumerator in C#). I see the distinction now but old habits die hard, I guess. :)
Re: Examples of Windows services in D?
On Thu, 23 Feb 2012 02:33:04 +0100, DNewbie wrote: Here is a simple service in D http://my.opera.com/run3/blog/2012/02/23/windows-services-in-d It's basically c translated to d. Hey, thanks for this. I ended up doing the same thing (translating an existing service from C++). But my code is messy, and I shall mine your example for improvements. :) I am *very* glad I could write this thing in D! One thing that bit me: if you want to use an extended Service Control Handler (RegisterServiceCtrlHandlerEx), these functions are absent from advapi32.lib (at least in my recent version of DMD). I had to include a linkage.def file, when linking, to get it working: EXETYPE NT IMPORTS RegisterServiceCtrlHandlerExA@12 = advapi32.RegisterServiceCtrlHandlerExA Cheers, Graham On Tue, Feb 21, 2012, at 03:08 PM, Graham Fawcett wrote: Hi folks, I've got a Windows service that I'd like to write in D, if possible. I see that Andrej Mitrovic has provided a binding for the relevant parts of the Windows API (thanks!): https://github.com/AndrejMitrovic/DWinProgramming/blob/master/win32/ winsvc.d Has anyone used this (or another binding) to write an actual service? Particularly, I was hoping to find a base class that takes care of common tasks (installing, removing, starting, etc.). Thanks! Graham
SONAME and D
dear, for set soname with: - gdc: -Xlinker -soname myLib.so.1 - ldc2: -soname myLib.so.1 - dmd: ? someone know how set soname with dmd ?
Re: SONAME and D
On 02/23/2012 05:27 PM, bioinfornatics wrote: dear, for set soname with: - gdc: -Xlinker -soname myLib.so.1 - ldc2: -soname myLib.so.1 - dmd: ? someone know how set soname with dmd ? dmd -L-soname=mylib.so.1 -- Mike Wey
Re: DbC bug?
On Thu, Feb 23, 2012 at 11:42:35AM +0100, Magnus Lie Hetland wrote: I think I've stumbled across a DbC bug. In an out-block, I have the assertion `assert(id objs.length);`. Now, if I don't have an in-block, this fails. However, if I add an in-block (with basically any code that isn't optimized away, or so it seems), the assertion succeeds. (Before this was an assertion, the failure was a range violation from objs[id]; the behavior is equivalent for that.) [...] It seems that the id variable (a parameter of the method) is actually undefined in the out-block, and that this is the reason for the error. (The program is run with the same random seeds, but the id variable, which *should* be in 0..1000, ends up with varying values such as 1609528144, 1653547856 or 1816621904. [...] Looks like a compiler bug. You should never be able to access invalid values. T -- A man's wife has more power over him than the state has. -- Ralph Emerson
Re: Weird opEquals Problem
On Thu, Feb 23, 2012 at 10:20:58PM +1300, James Miller wrote: On 23 February 2012 15:55, H. S. Teoh hst...@quickfur.ath.cx wrote: On Wed, Feb 22, 2012 at 09:32:55PM -0500, Kevin wrote: [...] Thanks for all the help. Although you guys should be careful because if you keep giving such in depth answers I might start asking stupid questions just to learn the language in more depth :) [...] Just don't start asking too stupid questions (like how does 1+1 work?) :P. [...] Well, that question may not be that stupid if you're talking about it from the context of operator overloading... Or code generation. Or compile-time constant folding. ;-) T -- MAS = Mana Ada Sistem?
Re: Wrapping c variadic functions
On 23 February 2012 23:35, simendsjo simend...@gmail.com wrote: Say i have a c function (didn't include first format argument for simplicity) void print(...); I wrap it up: extern(System) void print(...); And then I try to wrap it up in some safer D way: void print(Args...)(Args args) { print(args); // only the first argument is printed } void print(...) { print(_argptr); // no go either } How am I supposed to do this? http://dlang.org/function.html#variadic doesn't make my any smarter. I'm pretty sure that std.c.stdarg is where you want to go, unfortunately, due to the fact that C varargs is a bit of black magic, you can only really wrap functions that provide v* versions. On top of that, std.c.stdarg is just a wrapper for the C library of the same name, so it doesn't provide a proper way to convert anything to a va_list. However, if you experiment with v* functions from C, then you might be able to trick it...
Re: Wrapping c variadic functions
On 02/23/12 11:35, simendsjo wrote: Say i have a c function (didn't include first format argument for simplicity) void print(...); I wrap it up: extern(System) void print(...); And then I try to wrap it up in some safer D way: void print(Args...)(Args args) { print(args); // only the first argument is printed } void print(...) { print(_argptr); // no go either } How am I supposed to do this? http://dlang.org/function.html#variadic doesn't make my any smarter. You may want to check if a va_list based version of the C function is available. Anyway, the above should work, with a valid C prototype; this works here: -- import std.string; extern (C) int printf(const char*, ...); int dp(A...)(A args) { return printf(args); } void main(string[] argv) { dp(cast(char*)%s\n, argv[0].toStringz); dp(cast(char*)%s, %s\n, argv[0].toStringz, argv[1].toStringz); dp(cast(char*)%s, %s, %s\n, argv[0].toStringz, argv[1].toStringz, argv[2].toStringz); dp(cast(char*)%s, %d, %s\n, argv[0].toStringz, 42, argv[2].toStringz); } -- and you can even do things like: -- import std.string; import std.typetuple; extern (C) int printf(const char*, ...); int dp(A...)(A args) { alias ReplaceAll!(immutable(char)[], char*, A) CA; CA cargs; foreach (i, arg; args) { static if (is(typeof(arg):const(char)[])) cargs[i] = cast(char*)arg.toStringz; else cargs[i] = arg; } return printf(cargs); } void main(string[] argv) { dp(%s\n, argv[0]); dp(%s, %s\n, argv[0], argv[1]); dp(%s, %s, %s\n, argv[0], argv[1], argv[2]); dp(%s, %d, %s\n, argv[0], 42, argv[2]); } -- to expose a more sane API. Note: this example only handles D strings. BTW, is there a simpler and/or more generic way to achieve this? Thinking about using it in C bindings... artur
Re: D, Derelict2, and OpenGL
I find that when learning a complicated system or library, the best way is to write out the code examples, compile them, then change things until they break, fix it, then make more changes. Eventually you end up with the worst code ever known to man and a thorough understanding of the system at hand. I did it recently when figuring out that there is more to terminal emulation than just IO redirection and interpreting Terminal codes. Most of the time, you'll bang your head against your desk screaming why wont you work until you brain-damage your way into an epiphany, fix everything, achieve enlightenment, ???, PROFIT!
Re: SONAME and D
Le jeudi 23 février 2012 à 19:46 +0100, Mike Wey a écrit : On 02/23/2012 05:27 PM, bioinfornatics wrote: dear, for set soname with: - gdc: -Xlinker -soname myLib.so.1 - ldc2: -soname myLib.so.1 - dmd: ? someone know how set soname with dmd ? dmd -L-soname=mylib.so.1 Thanks i will do so a $(SONAME_FLAG) in my makefile and maybe i will do a pull request for gtkd because ldc do not use -L-soname instead of dmd
Re: Wrapping c variadic functions
On Thu, 23 Feb 2012 18:42:51 +0100, Artur Skawina art.08...@gmail.com wrote: On 02/23/12 11:35, simendsjo wrote: Say i have a c function (didn't include first format argument for simplicity) void print(...); I wrap it up: extern(System) void print(...); And then I try to wrap it up in some safer D way: void print(Args...)(Args args) { print(args); // only the first argument is printed } void print(...) { print(_argptr); // no go either } How am I supposed to do this? http://dlang.org/function.html#variadic doesn't make my any smarter. You may want to check if a va_list based version of the C function is available. Anyway, the above should work, with a valid C prototype; this works here: -- import std.string; extern (C) int printf(const char*, ...); int dp(A...)(A args) { return printf(args); } void main(string[] argv) { dp(cast(char*)%s\n, argv[0].toStringz); dp(cast(char*)%s, %s\n, argv[0].toStringz, argv[1].toStringz); dp(cast(char*)%s, %s, %s\n, argv[0].toStringz, argv[1].toStringz, argv[2].toStringz); dp(cast(char*)%s, %d, %s\n, argv[0].toStringz, 42, argv[2].toStringz); } -- and you can even do things like: -- import std.string; import std.typetuple; extern (C) int printf(const char*, ...); int dp(A...)(A args) { alias ReplaceAll!(immutable(char)[], char*, A) CA; CA cargs; foreach (i, arg; args) { static if (is(typeof(arg):const(char)[])) cargs[i] = cast(char*)arg.toStringz; else cargs[i] = arg; } return printf(cargs); } void main(string[] argv) { dp(%s\n, argv[0]); dp(%s, %s\n, argv[0], argv[1]); dp(%s, %s, %s\n, argv[0], argv[1], argv[2]); dp(%s, %d, %s\n, argv[0], 42, argv[2]); } -- to expose a more sane API. Note: this example only handles D strings. BTW, is there a simpler and/or more generic way to achieve this? Thinking about using it in C bindings... artur Hmm. Didn't my previous post make it to the newsgroup? Is visible at my end. I wrote: My bad. The first version works just fine. I passed a float and had the format string as %d... So print(Args...)(Args args) { c_print(args); // works just fine }
Re: Wrapping c variadic functions
On 02/23/12 20:37, simendsjo wrote: Hmm. Didn't my previous post make it to the newsgroup? Is visible at my end. The mailing list gets stuck sometimes and does not forward messages for hours. Your question made it, but the later post only arrived here minutes ago... artur
Pure and higher-order functions
Hello! I have been asked few question recently from a Haskell programmer about D2 and, after experimenting a bit, have found that I really can't provide a good answe myself, as I am not getting a design limititations (if any). Here is the snippet, it is pretty self-descriptive: http://codepad.org/DBdCJYI2 Am i right, that all information about purity Co is lost at runtime and there is no way to write pure-aware higher-order function using dynamic function pointers? That would have made me really sad :(
Re: Pure and higher-order functions
Le 23/02/2012 21:00, mist a écrit : Hello! I have been asked few question recently from a Haskell programmer about D2 and, after experimenting a bit, have found that I really can't provide a good answe myself, as I am not getting a design limititations (if any). Here is the snippet, it is pretty self-descriptive: http://codepad.org/DBdCJYI2 Am i right, that all information about purity Co is lost at runtime and there is no way to write pure-aware higher-order function using dynamic function pointers? That would have made me really sad :( Information is lost because of what f2 accept as a type. f2'q param isn't pure, so you gat what you except. Within f2, the fact that your function is pure is lost. f2 accept any function, pure or not. pure function can be casted automatically to non pure, because it is safe, but the other way around, it is impossible (because purity constraint would be broken).
Re: Pure and higher-order functions
But is there any way to actually say D compiler that I want this function to accept only pure delegates?
Re: Pure and higher-order functions
On Thursday, February 23, 2012 21:17:46 mist wrote: But is there any way to actually say D compiler that I want this function to accept only pure delegates? Mark the delegate type that it accepts as pure. - Jonathan M Davis
Re: Wrapping c variadic functions
On Thu, Feb 23, 2012 at 08:53:00PM +0100, Artur Skawina wrote: On 02/23/12 20:37, simendsjo wrote: Hmm. Didn't my previous post make it to the newsgroup? Is visible at my end. The mailing list gets stuck sometimes and does not forward messages for hours. Your question made it, but the later post only arrived here minutes ago... My MX was getting Disk Full errors from the primary SMTP server. Probably traffic on D mailing lists is too high for the mailing list to handle. :) T -- Computerese Irregular Verb Conjugation: I have preferences. You have biases. He/She has prejudices. -- Gene Wirchenko
fedora/ldc where are druntime headers?
looking for core.stuff I would have thought they would be in ldc-druntime-devel, but they don't seem to be, and I can't find them elsewhere
Linking with d3d11.dll/lib
I'm trying to use the d3d11 bindings in http://www.dsource.org/projects/bindings/wiki/DirectX to call direct3d11 functions from my D program. I've managed to get the code to compiler but when it links I get this error - Error 42 Symbol Undefined _D3D11CreateDeviceAndSwapChain@48 I have copied the D3D11.lib from the D3D SDK into my project and then run COFFIMPLIB d3d11.lib -f to convert it and included the library in my project settings. Is there something else I need to do to make this link? Any help appreciated.
Re: Adding overloaded methods
On Fri, Feb 24, 2012 at 04:06:52AM +1300, James Miller wrote: On 23 February 2012 13:15, BLM blm...@gmail.com wrote: After messing around for a while, I figured out what is making DMD choke on my file. The methods were defined in the base class using template mixins, and apparently DMD doesn't like it when mixins, inheritance, overloading, and aliases are all in the same piece of code :) And the award for Most Meta Code goes too... [...] I dunno, but most meta to me implies recursive mixins... T -- For every argument for something, there is always an equal and opposite argument against it. Debates don't give answers, only wounded or inflated egos.
Re: fedora/ldc where are druntime headers?
Le jeudi 23 février 2012 à 16:29 -0600, Ellery Newcomer a écrit : looking for core.stuff I would have thought they would be in ldc-druntime-devel, but they don't seem to be, and I can't find them elsewhere in ldc-druntime-devel see above command $ rpm -ql ldc-druntime-devel /usr/include/d/core /usr/include/d/core/atomic.di /usr/include/d/core/bitop.di /usr/include/d/core/cpuid.di /usr/include/d/core/demangle.di /usr/include/d/core/exception.di /usr/include/d/core/math.di /usr/include/d/core/memory.di /usr/include/d/core/runtime.di /usr/include/d/core/simd.di /usr/include/d/core/stdc /usr/include/d/core/stdc/complex.di /usr/include/d/core/stdc/config.di /usr/include/d/core/stdc/ctype.di /usr/include/d/core/stdc/errno.di /usr/include/d/core/stdc/fenv.di /usr/include/d/core/stdc/float_.di /usr/include/d/core/stdc/inttypes.di /usr/include/d/core/stdc/limits.di /usr/include/d/core/stdc/locale.di /usr/include/d/core/stdc/math.di /usr/include/d/core/stdc/signal.di /usr/include/d/core/stdc/stdarg.di /usr/include/d/core/stdc/stddef.di /usr/include/d/core/stdc/stdint.di /usr/include/d/core/stdc/stdio.di /usr/include/d/core/stdc/stdlib.di /usr/include/d/core/stdc/string.di /usr/include/d/core/stdc/tgmath.di /usr/include/d/core/stdc/time.di /usr/include/d/core/stdc/wchar_.di /usr/include/d/core/stdc/wctype.di /usr/include/d/core/sync /usr/include/d/core/sync/barrier.di /usr/include/d/core/sync/condition.di /usr/include/d/core/sync/config.di /usr/include/d/core/sync/exception.di /usr/include/d/core/sync/mutex.di /usr/include/d/core/sync/rwmutex.di /usr/include/d/core/sync/semaphore.di /usr/include/d/core/sys /usr/include/d/core/sys/posix /usr/include/d/core/sys/posix/arpa /usr/include/d/core/sys/posix/arpa/inet.di /usr/include/d/core/sys/posix/config.di /usr/include/d/core/sys/posix/dirent.di /usr/include/d/core/sys/posix/dlfcn.di /usr/include/d/core/sys/posix/fcntl.di /usr/include/d/core/sys/posix/inttypes.di /usr/include/d/core/sys/posix/net /usr/include/d/core/sys/posix/net/if_.di /usr/include/d/core/sys/posix/netdb.di /usr/include/d/core/sys/posix/netinet /usr/include/d/core/sys/posix/netinet/in_.di /usr/include/d/core/sys/posix/netinet/tcp.di /usr/include/d/core/sys/posix/poll.di /usr/include/d/core/sys/posix/pthread.di /usr/include/d/core/sys/posix/pwd.di /usr/include/d/core/sys/posix/sched.di /usr/include/d/core/sys/posix/semaphore.di /usr/include/d/core/sys/posix/setjmp.di /usr/include/d/core/sys/posix/signal.di /usr/include/d/core/sys/posix/stdio.di /usr/include/d/core/sys/posix/stdlib.di /usr/include/d/core/sys/posix/sys /usr/include/d/core/sys/posix/sys/ipc.di /usr/include/d/core/sys/posix/sys/mman.di /usr/include/d/core/sys/posix/sys/select.di /usr/include/d/core/sys/posix/sys/shm.di /usr/include/d/core/sys/posix/sys/socket.di /usr/include/d/core/sys/posix/sys/stat.di /usr/include/d/core/sys/posix/sys/time.di /usr/include/d/core/sys/posix/sys/types.di /usr/include/d/core/sys/posix/sys/uio.di /usr/include/d/core/sys/posix/sys/un.di /usr/include/d/core/sys/posix/sys/utsname.di /usr/include/d/core/sys/posix/sys/wait.di /usr/include/d/core/sys/posix/termios.di /usr/include/d/core/sys/posix/time.di /usr/include/d/core/sys/posix/ucontext.di /usr/include/d/core/sys/posix/unistd.di /usr/include/d/core/sys/posix/utime.di /usr/include/d/core/thread.di /usr/include/d/core/time.di /usr/include/d/core/vararg.di /usr/include/d/ldc /usr/include/d/ldc/intrinsics.di /usr/include/d/ldc/llvmasm.di /usr/include/d/ldc/object.di /usr/lib64/libdruntime-ldc.so
Re: fedora/ldc where are druntime headers?
On 02/23/2012 05:08 PM, bioinfornatics wrote: Le jeudi 23 février 2012 à 16:29 -0600, Ellery Newcomer a écrit : looking for core.stuff I would have thought they would be in ldc-druntime-devel, but they don't seem to be, and I can't find them elsewhere in ldc-druntime-devel see above command [ellery@balsamroot rpmbuild]$ rpm -ql ldc-druntime-devel /usr/include/d/ldc /usr/include/d/ldc/intrinsics.di /usr/include/d/ldc/llvmasm.di /usr/include/d/object.di /usr/include/d/std/intrinsic.di /usr/include/d/ldc /usr/include/d/ldc/intrinsics.di /usr/include/d/ldc/llvmasm.di /usr/include/d/object.di /usr/include/d/std/intrinsic.di is all I get (I installed both i686 and x86_64 just in case)
Re: fedora/ldc where are druntime headers?
Le jeudi 23 février 2012 à 17:11 -0600, Ellery Newcomer a écrit : On 02/23/2012 05:08 PM, bioinfornatics wrote: Le jeudi 23 février 2012 à 16:29 -0600, Ellery Newcomer a écrit : looking for core.stuff I would have thought they would be in ldc-druntime-devel, but they don't seem to be, and I can't find them elsewhere in ldc-druntime-devel see above command [ellery@balsamroot rpmbuild]$ rpm -ql ldc-druntime-devel /usr/include/d/ldc /usr/include/d/ldc/intrinsics.di /usr/include/d/ldc/llvmasm.di /usr/include/d/object.di /usr/include/d/std/intrinsic.di /usr/include/d/ldc /usr/include/d/ldc/intrinsics.di /usr/include/d/ldc/llvmasm.di /usr/include/d/object.di /usr/include/d/std/intrinsic.di is all I get (I installed both i686 and x86_64 just in case) remove ldc $ su -c 'yum remove ldc* get latest ldc build here: http://koji.fedoraproject.org/koji/buildinfo?buildID=299767 install it with yum install after dowloading these rpm
D runtime Garbage Collector details
I am looking for the details on D Garbage Collection implementation. I will much appreciate if someone suggests the answers or give some links to existing documentation clarifying the following points: 1. Is it Mark-n-Sweep or copy or generational collector or simple reference counting? Or anything else? Any documentation on this would be very helpful 2. Sun/Oracle JVM publishes a number of counters in shared memory so that user may easily monitor the memory usage and the GC statistics real-time without affecting the application (and without modifying the application). Is there anything similar for D GC? 3. Is there any performance tests of D GC efficiency? Is it possible to write GC-predictable code (without manual allocate/free) or at least do something like System.gc()?
Re: mixin template FAIL
On Thu, Feb 23, 2012 at 05:27:03PM -0500, Zach the Mystic wrote: On 2/21/12 2:53 PM, Ali Çehreli wrote: According to the docs, template mixins can have only declarations but helpMe above has a statement. http://dlang.org/template-mixin.html Ali Thanks for your reply. You're right about the statement. But I still think something's wrong. For example, even this program produces the errors: import std.stdio; mixin template helpMe() { writeln(Satisfying!); The writeln call is a statement. I think what you want is this: template helpMe() { mixin(`writeln(Satisfying!);`); } T -- Real Programmers use cat a.out.
Re: mixin template FAIL
Thanks for your reply. You're right about the statement. But I still think something's wrong. For example, even this program produces the errors: import std.stdio; mixin template helpMe() { writeln(Satisfying!); } does it do that if you replace the statement with a declaration? like this: mixin template helpMe() { int durrr = (writeln(Satisfying!), 1); }
Re: fedora/ldc where are druntime headers?
grumph. is it not possible to fix the packages in repo? On 02/23/2012 05:17 PM, bioinfornatics wrote: get latest ldc build here: http://koji.fedoraproject.org/koji/buildinfo?buildID=299767 install it with yum install after dowloading these rpm
Re: D, Derelict2, and OpenGL
On Thursday, 23 February 2012 at 19:26:31 UTC, James Miller wrote: I find that when learning a complicated system or library, the best way is to write out the code examples, compile them, then change things until they break, fix it, then make more changes. Eventually you end up with the worst code ever known to man and a thorough understanding of the system at hand. I did it recently when figuring out that there is more to terminal emulation than just IO redirection and interpreting Terminal codes. Most of the time, you'll bang your head against your desk screaming why wont you work until you brain-damage your way into an epiphany, fix everything, achieve enlightenment, ???, PROFIT! I have followed this same pattern when I work with the UDK. Although, with that, its more about searching through source code, reading over the foundation I'm building upon and moving from there to try to implement my classes. For me, that method has been the best to learn. Along with some frustration when it doesn't go as planned. Is the documentation up-to-date on this site? So that I can search through and try to learn more about a certain library and how it could help me?
UnitTest and visual D
I am following the book The D Programming Language and am at the portion about functions and unittest. For some reason I cannot get unittest to do anything noticeable. I right clicked on my Project Properties Command Line and under additional options added -unittest (--main gave me an error saying unrecognized switch). After I compiled the code, the program ran as normal. Am I missing something? This is what I have so far: int[]find(int[] haystack, int needle) { while(haystack.length 0 haystack[0] != needle){ haystack = haystack[1 .. $]; } return haystack; } unittest { int[] a = []; assert(find(a, 5) == []); a = [ 1, 2, 3 ]; assert(find(a, 0) == []); assert(find(a, 1).length == 3); assert(find(a, 2).length == 2); assert(a[0 $ - find(a, 3).length] [ 1, 2 ]); } void main() { int[3] array = [3, 4, 5]; int needle = 4; find(array, needle); }
Re: UnitTest and visual D
On Friday, February 24, 2012 02:11:50 Chris Pons wrote: I am following the book The D Programming Language and am at the portion about functions and unittest. For some reason I cannot get unittest to do anything noticeable. If the unit tests pass, they don't print anything unless you add statements to them which do. You only get stuff being printed out on failure. This works particularly well for the command line (it's normal in Unix-land for stuff to print nothing on success unless them printing stuff out is their job - this makes it easier to pipe programs and the like). Some people complain about it from time to time, but that's the way it is. If you really want them to print something though, you can always add your own print statements. If you compiled with -unittest, the unit tests run before main does, so if all of your tests pass, then your program will run normally after the unit tests have been run. It's not uncommon for people to do something like this so that they can have the unit tests run without running their actual program: version(unittest) void main() {} else void main() { //Your normal main... } - Jonathan M Davis
Re: UnitTest and visual D
Ok, thanks. I haven't run into version(...) yet. Would I be correct if I assumed that this version of void main: void main() {} would only run if -unittest was in the command line? Also, what should be in a unit test? Test cases to make sure certain functions/classes are working as you intend them to? If the unit tests pass, they don't print anything unless you add statements to them which do. You only get stuff being printed out on failure. This works particularly well for the command line (it's normal in Unix-land for stuff to print nothing on success unless them printing stuff out is their job - this makes it easier to pipe programs and the like). Some people complain about it from time to time, but that's the way it is. If you really want them to print something though, you can always add your own print statements. If you compiled with -unittest, the unit tests run before main does, so if all of your tests pass, then your program will run normally after the unit tests have been run. It's not uncommon for people to do something like this so that they can have the unit tests run without running their actual program: version(unittest) void main() {} else void main() { //Your normal main... } - Jonathan M Davis
Re: UnitTest and visual D
On Friday, February 24, 2012 03:12:08 Chris Pons wrote: Ok, thanks. I haven't run into version(...) yet. Would I be correct if I assumed that this version of void main: void main() {} would only run if -unittest was in the command line? Yes. version(symbol) means that anything within that block is compiled in if the version symbol has been defined (either in code or via the command-line). For instance, version(Posix) {} else version(Windows) {} else static assert(Unsupported OS); would give you three different versions of the code. The Posix one gets compiled in on Posix systems. The Windows one gets compiled in on Windows systems, and the third block gets compiled in on everything else (in this case, with a static assertion so that you get an error when you try and compile with an unsupported OS). The version unittest is enabled when you compile with -unittest, so anything in version(unittest) gets compiled in. Also, what should be in a unit test? Test cases to make sure certain functions/classes are working as you intend them to? Yes. Typically, after every function you put a unittest block with assertions that verify that that function is working correctly. And unit tests which tests combinations of functions can be useful as well. But regardless, the idea is to use unit tests to verify that your code works how it's supposed to and fails how it's supposed to (e.g. when certain input should result in an exception being thrown) so that you know not only that your code works currently but that your code continues to work when you make changes to it in the future. It makes for much more robust code and often actually increases the speed of development, because you end up with fewer bugs (since you catch them when you write the tests, which you typically do when you write the code). - Jonathan M Davis
Re: UnitTest and visual D
I am having the same problem with visual d plugin for monodevelop. When I compile from the command line the tests run. A possibly related problem is that some files do not get recompiled when changed unless I do a rebuild. On Feb 23, 2012 8:38 PM, Jonathan M Davis jmdavisp...@gmx.com wrote: On Friday, February 24, 2012 02:11:50 Chris Pons wrote: I am following the book The D Programming Language and am at the portion about functions and unittest. For some reason I cannot get unittest to do anything noticeable. If the unit tests pass, they don't print anything unless you add statements to them which do. You only get stuff being printed out on failure. This works particularly well for the command line (it's normal in Unix-land for stuff to print nothing on success unless them printing stuff out is their job - this makes it easier to pipe programs and the like). Some people complain about it from time to time, but that's the way it is. If you really want them to print something though, you can always add your own print statements. If you compiled with -unittest, the unit tests run before main does, so if all of your tests pass, then your program will run normally after the unit tests have been run. It's not uncommon for people to do something like this so that they can have the unit tests run without running their actual program: version(unittest) void main() {} else void main() { //Your normal main... } - Jonathan M Davis
Re: UnitTest and visual D
On Thursday, February 23, 2012 21:38:43 Kevin Cox wrote: I am having the same problem with visual d plugin for monodevelop. When I compile from the command line the tests run. A possibly related problem is that some files do not get recompiled when changed unless I do a rebuild. There may very well be further problems due to what the IDE is doing (such as not doing a full recompile when you enable -unittest), but the unit tests won't print anything out on success regardless unless you use print statements in them. - Jonathan M Davis
Re: UnitTest and visual D
On Feb 23, 2012 9:41 PM, Jonathan M Davis jmdavisp...@gmx.com wrote There may very well be further problems due to what the IDE is doing (such as not doing a full recompile when you enable -unittest), but the unit tests won't print anything out on success regardless unless you use print statements in them It still doesn't run them when I do a full rebuild. In the build output I see -unittest in the command line. It is really weird. I haven't looked at it too closly. For now I am just compiling from the command line.
Re: D runtime Garbage Collector details
On 24 February 2012 12:49, Vadim vadim.goryu...@gmail.com wrote: I am looking for the details on D Garbage Collection implementation. I will much appreciate if someone suggests the answers or give some links to existing documentation clarifying the following points: 1. Is it Mark-n-Sweep or copy or generational collector or simple reference counting? Or anything else? Any documentation on this would be very helpful 2. Sun/Oracle JVM publishes a number of counters in shared memory so that user may easily monitor the memory usage and the GC statistics real-time without affecting the application (and without modifying the application). Is there anything similar for D GC? 3. Is there any performance tests of D GC efficiency? Is it possible to write GC-predictable code (without manual allocate/free) or at least do something like System.gc()? I don't know the answers to 1 or 2, but I know that there is a GC class with a bunch of methods on it for controlling the GC, including enabling and disabling it and getting GC-allocated memory. Whether that helps you write GC predictable code - I don't know, garbage collection is mostly a black art to me :-) -- James Miller
Re: Linking with d3d11.dll/lib
On 24 February 2012 12:03, John Burton john.bur...@jbmail.com wrote: I'm trying to use the d3d11 bindings in http://www.dsource.org/projects/bindings/wiki/DirectX to call direct3d11 functions from my D program. I've managed to get the code to compiler but when it links I get this error - Error 42 Symbol Undefined _D3D11CreateDeviceAndSwapChain@48 I have copied the D3D11.lib from the D3D SDK into my project and then run COFFIMPLIB d3d11.lib -f to convert it and included the library in my project settings. Is there something else I need to do to make this link? Any help appreciated. From another thread: Adam D. Ruppe: On Wednesday, 22 February 2012 at 17:02:01 UTC, miazo wrote: Error 42: Symbol Undefined _mysql_init@4 libmysql.dll with implib utility. I think the /s switch is needed on that one when doing the mysql libraries on implib. /s changes what's done with the _ in the front. I've done this before but don't remember exactly what I did though. The documentation for the mars implib is here: http://www.digitalmars.com/ctg/implib.html and has this: /s[ystem] - Prepend '_' to exported internal names. Used to create import library from Windows NT system DLLs (for example, kernel32.dll). Note that this switch is not available via the ID I hope that helps, I don't actually do any windows programming so I can't test this at all -- James Miller
Re: D runtime Garbage Collector details
On Feb 23, 2012 6:50 PM, Vadim vadim.goryu...@gmail.com wrote: I am looking for the details on D Garbage Collection implementation. I will much appreciate if someone suggests the answers or give some links to existing documentation clarifying the following points: 1. Is it Mark-n-Sweep or copy or generational collector or simple reference counting? Or anything else? Any documentation on this would be very helpful 2. Sun/Oracle JVM publishes a number of counters in shared memory so that user may easily monitor the memory usage and the GC statistics real-time without affecting the application (and without modifying the application). Is there anything similar for D GC? 3. Is there any performance tests of D GC efficiency? Is it possible to write GC-predictable code (without manual allocate/free) or at least do something like System.gc There is quite a lot of info in the mailing list. Off of the top of my head I know it is a mark and sweep. There is someone who did their Phd on GC in D and he did a fairly good analysis of the current situation. And as the fellow before me said, there is a garbage collector control.
Re: Adding overloaded methods
On 24 February 2012 12:06, H. S. Teoh hst...@quickfur.ath.cx wrote: On Fri, Feb 24, 2012 at 04:06:52AM +1300, James Miller wrote: On 23 February 2012 13:15, BLM blm...@gmail.com wrote: After messing around for a while, I figured out what is making DMD choke on my file. The methods were defined in the base class using template mixins, and apparently DMD doesn't like it when mixins, inheritance, overloading, and aliases are all in the same piece of code :) And the award for Most Meta Code goes too... [...] I dunno, but most meta to me implies recursive mixins... T -- For every argument for something, there is always an equal and opposite argument against it. Debates don't give answers, only wounded or inflated egos. True, I guess the Most Meta Code would be something that combines recursive mixins, string mixins, inheritance, overriding, overloading, aliases and is all inside a recursive template. Bonus points if the final result is a quine. -- James Miller
Re: UnitTest and visual D
On Thursday, February 23, 2012 21:47:26 Kevin Cox wrote: It still doesn't run them when I do a full rebuild. In the build output I see -unittest in the command line. It is really weird. I haven't looked at it too closly. For now I am just compiling from the command line. Well, I'm afraid that I've never used an IDE with D, so I can't really help with IDE-specific problems. It does sound like your not running the right binary though (like maybe you ended up with two of them, and it's the old one which is being run). I can only guess though. - Jonathan M Davis
Re: UnitTest and visual D
On Thu, Feb 23, 2012 at 09:28:07PM -0500, Jonathan M Davis wrote: On Friday, February 24, 2012 03:12:08 Chris Pons wrote: [...] Also, what should be in a unit test? Test cases to make sure certain functions/classes are working as you intend them to? Pretty much. The idea is to put stuff in there to check that your code actually does what you think it does. Especially useful are tests that check boundary conditions (i.e., corner cases, like empty input, input which is 0, off-by-1 input, null input). [...] But regardless, the idea is to use unit tests to verify that your code works how it's supposed to and fails how it's supposed to (e.g. when certain input should result in an exception being thrown) For which the assertThrown template is very useful: unittest { // Instantiate an object of the class you're writing auto o = new myClass; // Make sure an exception is thrown when you try to do // something illegal. assertThrown!Exception(o.parse(illegalInput)); } The template basically runs o.parse(...), and if it throws an Exception, then it catches it and continues running the unittest. However, if o.parse(...) returns without throwing an Exception, then the template will throw a unit test failure exception. so that you know not only that your code works currently but that your code continues to work when you make changes to it in the future. This is one of the big benefits of unittests. By putting in test cases that ensure your code does what you think it does, when you make a change in the future the same test cases will tell you if you also broke a previously working feature. It makes for much more robust code and often actually increases the speed of development, because you end up with fewer bugs (since you catch them when you write the tests, which you typically do when you write the code). [...] One thing I absolutely love about D unittests is that they're so dang easy to write that you really have no excuse not to write them. Which is the point, because most programmers in principle agree that unittests are good, but they don't actually write them because traditionally (1) unittests are external to the code you're writing, so there's the effort of putting your current code on hold, switching to a different directory, and adding a unittest there, then switch back. (2) They're often in a different language, like Python or Expect, and it's mentally taxing to keep switching back and forth between languages in the middle of your coding session. (3) They have to be run separately, which most programmers are too lazy to do. All of these, together with tight deadlines, often result in no unittests or outdated unittests. In D, by building unittests into the language and allowing unittest blocks pretty much anywhere in the code (except inside a function), as soon as you think of a corner case the complex algorithm you're writing might want to handle, you can just stick it in the unittest block next to the function and keep going. Often I find that before I even finish writing a function, I've already written 2-3 unittests for it, and after I finish it, I add a few more. By the time I actually run the program, the new code already has a stringent set of tests that will quickly catch any obvious bugs. Then if your tests missed some test case that you later discover to cause a bug, you just add it to the growing list of unittest blocks, and then any further changes after that will always run that new test, ensuring that the bug will never come back again. D's unittests also never stagnate and get outdated: once you compile with -unittest, your program will refuse to run until you fix the bug that caused unittest failure. It's good motivation to actually fix the bug instead of saying I'll do it later, which often means it won't get done 'cos I'll forget by then. T -- Uhh, I'm still not here. -- KD, while away on ICQ.
Re: UnitTest and visual D
Thanks for the response. There are a lot of great features to D that really excites me about using this language. Unittest is definitely one of them. It's hard for me to imagine myself going back to C++ at this point because of the amount of great features in D. :)
GDC: how to link with alternate version of Phobos?
I'm trying to test if a bug has been fixed in the latest Phobos git repository, but I'm having trouble convincing gdc to *not* use the default installation of Phobos. What option do I need on the commandline to tell it to use a different path to Phobos? -I only appends include paths *after* the default paths, so it'll always pick up the default installation first (plus it will cause import conflicts since there will be two modules claiming to be std.stdio). T -- Too many people have open minds but closed eyes.
Re: GDC: how to link with alternate version of Phobos?
On Thursday, February 23, 2012 20:21:57 H. S. Teoh wrote: I'm trying to test if a bug has been fixed in the latest Phobos git repository, but I'm having trouble convincing gdc to *not* use the default installation of Phobos. What option do I need on the commandline to tell it to use a different path to Phobos? -I only appends include paths *after* the default paths, so it'll always pick up the default installation first (plus it will cause import conflicts since there will be two modules claiming to be std.stdio). With dmd, you'd change dmd.conf, but I don't know if GDC has anything similar. I would have thought so though, because otherwise it would have to hardcode the paths and linker options for Phobos. But maybe it does hardcode them. I don't know. - Jonathan M Davis
Re: UnitTest and visual D
On Fri, Feb 24, 2012 at 05:17:27AM +0100, Chris Pons wrote: [...] It's hard for me to imagine myself going back to C++ at this point because of the amount of great features in D. :) Yeah I starting using D recently, and now I just can't convince myself to start another C/C++ project. It's just maintenance now, until I port my projects to D. :P T -- Life would be easier if I had the source code. -- YHL
vfprintf equivalent in D
Hi, Is there an equivalent to vfprintf(const char *fmt, , va_list ap) in D? -- Thanks, Sarath
Re: Linking with d3d11.dll/lib
On 2/23/2012 5:03 PM, John Burton wrote: I'm trying to use the d3d11 bindings in http://www.dsource.org/projects/bindings/wiki/DirectX to call direct3d11 functions from my D program. I've managed to get the code to compiler but when it links I get this error - Error 42 Symbol Undefined _D3D11CreateDeviceAndSwapChain@48 I have copied the D3D11.lib from the D3D SDK into my project and then run COFFIMPLIB d3d11.lib -f to convert it and included the library in my project settings. Is there something else I need to do to make this link? Any help appreciated. Its been quite a while since I've had time to work on my side project (which is what prompted the d3d11 module to get written). I can look into this later when I get home, as well as strip down my test app and publish it somewhere. The app is pretty simple - it creates a window, a d3d11 device, a vertex and pixel shader, a vertex and index buffer, and draws a triangle. It would be more but I had been working on a stripped down version of the an ATL/WTL like wrapper for D in the meantime, in order to handle HWND objects and generate message maps with mixins.
Re: vfprintf equivalent in D
On Friday, February 24, 2012 05:22:58 Sarath Kumar wrote: Hi, Is there an equivalent to vfprintf(const char *fmt, , va_list ap) in D? If you're dealing with C variadics, then your going to need to use C functions. D doesn't just recreate C functions (at least, the standard library doesn't). C functions get wrapped when doing so adds some benefit, but with something like this, there's no reason to. If you're using typesafe variadics void func(int[] arr...) then you can just pass the array to the next function. If you're using D-style variadics (which are similar to C variadics but include type information), maybe there is, I don't know. Probably. I never use them. However, the typical thing to do in D is to use variadic templates. That's what writefln does. void func(Args...)(Args args) And with that, you can just pass the arguments on to another function. http://dlang.org/function.html http://dlang.org/template.html - Jonathan M Davis
Re: vfprintf equivalent in D
On Thursday, February 23, 2012 21:38:27 Jonathan M Davis wrote: On Friday, February 24, 2012 05:22:58 Sarath Kumar wrote: Hi, Is there an equivalent to vfprintf(const char *fmt, , va_list ap) in D? If you're dealing with C variadics, then your going to need to use C functions. D doesn't just recreate C functions (at least, the standard library doesn't). C functions get wrapped when doing so adds some benefit, but with something like this, there's no reason to. If you're using typesafe variadics void func(int[] arr...) then you can just pass the array to the next function. If you're using D-style variadics (which are similar to C variadics but include type information), maybe there is, I don't know. Probably. I never use them. However, the typical thing to do in D is to use variadic templates. That's what writefln does. void func(Args...)(Args args) And with that, you can just pass the arguments on to another function. http://dlang.org/function.html http://dlang.org/template.html And if your intention was to specifically pass on arguments to writefln, then you can just do it, since it's a variadic template. void myWritefln(Args...)(Args args) { writefln(args); } But if you're looking to specifically pass on a C variadic, then use C's vfprintf. - Jonathan M Davis
Re: vfprintf equivalent in D
On Fri, Feb 24, 2012 at 05:22:58AM +, Sarath Kumar wrote: Hi, Is there an equivalent to vfprintf(const char *fmt, , va_list ap) in D? [...] You don't need one. You can just write: void myWritelnWrapper(T...)(T args) { ... // insert your own processing here, modify args // if you like, etc. writeln(args); } T -- Life would be easier if I had the source code. -- YHL
2.058 broke my build. Is this a bug?
88 import std.datetime : benchmark; import std.stdio : writefln; struct A(int r, int c){ public: alias float[r * c] Data; Data _data; auto opBinary(A a){ float t; foreach(i; 0..r*c) foreach(j; 0..r*c) t += this[i,j]; return a; } pure float opIndex(size_t rr, size_t cc = 0) const{ return _data[cc + rr * c]; } pure ref float opIndex(size_t rr, size_t cc = 0){ return _data[cc + rr * c]; } } void bench(alias fun)(string msg, uint n = 1_000_000){ auto b = benchmark!fun(n); writefln( %s %s ms, msg, b[0].to!(msecs, int)); } unittest{ alias A!(3, 3) AA; AA a; bench!( {auto r = a * a;})(broken); } void main(){ } 88 Other parts of my code using bench() works fine, except in rare cases. So I'm guessing this is a bug? I can't tell if it's in DMD or std.datetime. Can anyone help? I will bug report myself tomorrow if it turns out to be a bug for sure. DMD 2.058, 64-bit GNU/Linux
Re: vfprintf equivalent in D
Thanks Jonathan and Teoh. I just have to pass the var args in my function to writefln and Variadic templates is the right solution for me. -- Thanks, Sarath