Re: static init of associative array of enums not working.. why?
On Saturday, 27 February 2016 at 04:37:24 UTC, Øivind wrote: Should I file a ticket for this? It is already known, just nobody has fixed it yet (and probably won't for a long time still)
Re: static init of associative array of enums not working.. why?
On Saturday, 27 February 2016 at 04:35:41 UTC, Adam D. Ruppe wrote: It just isn't implemented in the compiler. Instead, you can declare it outside and set it in a static module constructor: That was quick! Thank you. Should I file a ticket for this?
Re: static init of associative array of enums not working.. why?
On Saturday, 27 February 2016 at 04:15:06 UTC, Øivind wrote: Shouldn't this work? According to "Static Initialization of AAs" on this page, it should: https://dlang.org/spec/hash-map.html It just isn't implemented in the compiler. Instead, you can declare it outside and set it in a static module constructor: immutable DevicePropDataType[DevicePropValType] propDType; shared static this() { propDType = [ DevicePropValType.property: DevicePropDataType.dString, DevicePropValType.miscDate: DevicePropDataType.dDateTime ]; } void main() { }
static init of associative array of enums not working.. why?
Shouldn't this work? According to "Static Initialization of AAs" on this page, it should: https://dlang.org/spec/hash-map.html enum DevicePropDataType { dString, dDateTime } enum DevicePropValType { property, miscDate } immutable DevicePropDataType[DevicePropValType] propDType = [ DevicePropValType.property: DevicePropDataType.dString, DevicePropValType.miscDate: DevicePropDataType.dDateTime ]; void main() { } I get the following error: /d847/f751.d(12): Error: non-constant expression [cast(DevicePropValType)0:cast(DevicePropDataType)0, cast(DevicePropValType)1:cast(DevicePropDataType)1]
Re: Calling python code from D
On Friday, 26 February 2016 at 17:15:02 UTC, Wyatt wrote: On Thursday, 25 February 2016 at 22:28:52 UTC, jmh530 wrote: I think PyD is really your best option. That's what I figured, but I wanted to be sure because, well... http://pyd.readthedocs.org/en/latest/embed.html ...these are some sparse docs. I did stumble into them, but it feels like a bit of a work-in-progress or second-class citizen, so I was kind of hoping someone else had taken the torch and run with it. Maybe I'll have to shave a yak. :/ -Wyatt I just remembered this video, I don't know how much of it is still true today though https://www.youtube.com/watch?v=y-k7GyOcs3o
Re: GStreamer and D
On Fri, 2016-02-26 at 14:40 +, Kagamin via Digitalmars-d-learn wrote: > https://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html > /chapter-helloworld.html#section-helloworld - Hello world. > https://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html > /index.html - GStreamer Application Development Manual > http://docs.gstreamer.com/display/GstSDK/Basic+tutorials - Basic > tutorials. This is the C documentation, the issue I have is about the D wrapper and some idiomatic usage examples of it. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: Calling python code from D
On Friday, 26 February 2016 at 17:15:02 UTC, Wyatt wrote: On Thursday, 25 February 2016 at 22:28:52 UTC, jmh530 wrote: I think PyD is really your best option. That's what I figured, but I wanted to be sure because, well... http://pyd.readthedocs.org/en/latest/embed.html ...these are some sparse docs. I did stumble into them, but it feels like a bit of a work-in-progress or second-class citizen, so I was kind of hoping someone else had taken the torch and run with it. Maybe I'll have to shave a yak. :/ -Wyatt Docs are quite sparse, but it mostly works as expected. I have a WIP cleanup of the library in my fork. It won't help with docs of course...
Re: Calling python code from D
On Thursday, 25 February 2016 at 22:28:52 UTC, jmh530 wrote: I think PyD is really your best option. That's what I figured, but I wanted to be sure because, well... http://pyd.readthedocs.org/en/latest/embed.html ...these are some sparse docs. I did stumble into them, but it feels like a bit of a work-in-progress or second-class citizen, so I was kind of hoping someone else had taken the torch and run with it. Maybe I'll have to shave a yak. :/ -Wyatt
Re: Shared static constructors from C# EXE
On Friday, 26 February 2016 at 08:37:35 UTC, Benjamin Thaut wrote: On Thursday, 25 February 2016 at 17:46:18 UTC, Thalamus wrote: On Thursday, 25 February 2016 at 16:05:37 UTC, Benjamin Thaut wrote: [...] Thanks Benjamin. When I went to whittle this down to its barest essentials, though, the repro is pretty simple. It involves LIBs, but not Dlls, and it doesn't require anything but a single D EXE. [...] The problem is that when you build with -lib the resulting library is optimized for linker stripping. E.g. everything that is not directly used will not be pulled into the final executable. If you want everything in the final exectuable you shouldn't be using a .lib file. Instead compile with -c resutling in a .obj file and link the resulting .obj file into your executable. Then everything will end up in the final executable even if its not directly used. Kind Regards Benjamin Thaut Thanks Benjamin! I knew there had to be some simple thing I didn't know I needed to do here. It worked like a charm in the simple repro. In my actual code, I'm running into _deh_beg already defined and a few more linker errors, but I haven't had the chance to delve there yet. thanks again!
Re: dub: how to reference a compiled package
On Fri, 26 Feb 2016 03:19:26 +, mahdi wrote: > Great! Thanks. > > I was looking for a feature like `jar` files in Java or `assemblies` in > C# where all compiled code and metadata/symbols are stored together > inside a single binary file. C# and Java provide their own linkers and specify their own object formats. One aspect of that was including enough metadata to reconstruct the source code from the binary in a convenient and performant manner. DMD could store an extra symbol in each file it output including the autogenerated .di file for each source file. However, that would require the frontend to be able to parse arbitrary library and object formats. It's much easier to solve this in an external tool like Dub.
Re: Minimise and collect by GC when OutOfMemory
On Fri, 26 Feb 2016 05:47:08 +, tcak wrote: > Would it be a good idea to call "collect" and "minimize" methods of > core.memory.GC when OutOfMemory error is received FOR A LONG RUNNING > PROGRAM? or there won't be any benefit of that? > > Example program: A web server that allocates and releases memory from > heap continuously. If OutOfMemoryError is thrown, the GC has already done everything it can to try to get more memory to use. If you find a case in which it helps to call GC.collect and GC.minimize, it's a bug that the GC threw an OutOfMemoryError. ...usually. If you are running on a 64-bit Linux system that has overcommit turned off and more address space than RAM + swap, you can get some mileage from GC.minimize() after OutOfMemoryError. Detecting this situation isn't necessarily easy, which is why the GC doesn't do it already.
Re: GStreamer and D
https://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-helloworld.html#section-helloworld - Hello world. https://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/index.html - GStreamer Application Development Manual http://docs.gstreamer.com/display/GstSDK/Basic+tutorials - Basic tutorials.
Re: Dynamic pitch shift
On Friday, 26 February 2016 at 13:21:12 UTC, Guillaume Piolat wrote: We are not talking of the same thing. I was thinking about the table frequency cutoff which is 2x lower every level of mipmap Ok. I think is most common to use high levels of oversampling for tables so one can get better SNR using cheap interpolation. But I've lately thought a bit about encoding the complexity of a segment of the function in the table so that the renderer can choose an interpolation technique that matches the location in the table (e.g. straight line, use lerp; high frequency wobble, use sinc). To make it work for realtime one would have to track the cost and revert to lower quality when the budget has been spent.
Re: how to initialise const variables
On Friday, 26 February 2016 at 03:18:02 UTC, Nicholas Wilson wrote: On Friday, 26 February 2016 at 02:48:35 UTC, cym13 wrote: On Friday, 26 February 2016 at 02:32:44 UTC, Nicholas Wilson wrote: struct A { const (void *) p; } struct B { Aa; this(void * _p) { a.p = _p; } } I cannot change the definition of A how do I initialise b.a.p? As you did: void main() { int i = 42; B b = B(); int* p = cast(int*)b.a.p; assert(*p == 42); } a.p = _p; fails to compile fixed by a = typeof(a)(_p); What compiler and version are you using ? Because I literally just copied your example and added my main and got no error.
Re: Template this parameter in constructor
On Sunday, 21 February 2016 at 21:48:21 UTC, Steven Schveighoffer wrote: This isn't a bug. Here is what happens. 1. template this is assigned the compile-time type of the object *when the function is called*. 2. A base class constructor is called from the next derived constructor. So C2's constructor is called from C3's, and C1's constructor is called from C2's. So it follows that the template this type will be the next derived constructor (or the type itself if that is the most derived type), because that's the compile-time type the object's ctor is called with. Many thanks to both of you, Steven and Ali! Now this makes much more sense! I think you may be able to do something like this: this(T = typeof(this))() { super!T(); } But I'm not sure if it works. class C1 { this(This = typeof(this))() { pragma(msg, "C1 constructor: "~__traits(identifier, This)); } } class C2 : C1 { this(This = typeof(this))() { pragma(msg, "C2 constructor: "~__traits(identifier, This)); super.__ctor!This(); } } class C3 : C2 { this(This = typeof(this))() { pragma(msg, "C3 constructor: "~__traits(identifier, This)); super.__ctor!This(); } } int main(string[] args) { auto test = new C3(); return 0; } Compilation output: C3 constructor: C3 C2 constructor: C3 C1 constructor: C3 C1 constructor: C1 C2 constructor: C2 C1 constructor: C2 A little bit modified solution compiles but doesn't work as expected(tested on dmd 2.070) and produces some quite strange results and I really don't get why. But now it's not critical for me cause I managed to solve my initial problem with major refactoring. Many thanks again!
Re: Dynamic pitch shift
On Thursday, 25 February 2016 at 07:02:24 UTC, Ola Fosheim Grøstad wrote: On Wednesday, 24 February 2016 at 17:52:39 UTC, Guillaume Piolat wrote: Though it isn't fantastic aliasing-wise on the last octave, I should try something than power-of-2s next time I need it. Why would it help to not use 2^n sized tables? I guess you could compute everything at 88khz and decimate... We are not talking of the same thing. I was thinking about the table frequency cutoff which is 2x lower every level of mipmap
Re: Dynamic pitch shift
On Thursday, 25 February 2016 at 15:15:20 UTC, Luis wrote: - Wavetables - band-limited resampling algorithm aka BLIP or BLEP algorithms (See http://www.cs.cmu.edu/~eli/L/icmc01/hardsync.html and http://slack.net/~ant/libs/audio.html#Blip_Buffer ) I suggest just porting STK from C++ to D. It is well documented, suitable for a D-range implementation, is written for clarity over speed and uses a BSD license: https://ccrma.stanford.edu/software/stk/ https://github.com/thestk/stk/blob/master/include/Blit.h It also contains a wide range of physical models (waveguides etc).
Re: Using double value in string template mixin
On Friday, 26 February 2016 at 11:37:32 UTC, BBasile wrote: Erratum! Actually you can, example: import std.stdio; string foo(double a)() { return "auto value = " ~ a.stringof ~ ";"; } void main(string[] args) { mixin(foo!0.1); writeln(value); // 0.1 writeln(typeof(value).stringof); // double } So you have to use .stringof on the template argument. Sorry for the previous answer. Thank you!
Re: Using double value in string template mixin
On Friday, 26 February 2016 at 11:26:51 UTC, BBasile wrote: No you cannot because you would have to convert the values to string using std.conv.to or std.format.format(), but they don't work at compile time (see https://issues.dlang.org/show_bug.cgi?id=13568). Erratum! Actually you can, example: import std.stdio; string foo(double a)() { return "auto value = " ~ a.stringof ~ ";"; } void main(string[] args) { mixin(foo!0.1); writeln(value); // 0.1 writeln(typeof(value).stringof); // double } So you have to use .stringof on the template argument. Sorry for the previous answer.
Re: Using double value in string template mixin
On Friday, 26 February 2016 at 11:13:08 UTC, Dibyendu Majumdar wrote: I am trying something like this: template MyTAlloc(int n_vars, double v) { const char[] MyT = "MyT_init(cast(MyT *) alloca(alloc_size(" ~ n_vars ~ ")), " ~ n_vars ~ ", " ~ v ~ ")"; No you cannot because you would have to convert the values to string using std.conv.to or std.format.format(), but they don't work at compile time (see https://issues.dlang.org/show_bug.cgi?id=13568). Ideally like this: template MyTAlloc(int n_vars, double v) { const char[] MyT = "MyT_init(cast(MyT *) alloca(alloc_size(" ~ to!string(n_vars) ~ ")), " ~ to!string(n_vars) ~ ", " ~ to!string(v) ~ ")"; But you can try with regular templates or mixin templates.
Re: Using double value in string template mixin
On Friday, 26 February 2016 at 11:07:28 UTC, BBasile wrote: On Friday, 26 February 2016 at 11:03:43 UTC, Dibyendu Majumdar wrote: How do I use a double value in a mixin template that is generating string? Have you an example of what's failing right now to show ? I am trying something like this: template MyTAlloc(int n_vars, double v) { const char[] MyT = "MyT_init(cast(MyT *) alloca(alloc_size(" ~ n_vars ~ ")), " ~ n_vars ~ ", " ~ v ~ ")"; } MyT *t = mixin(MyTAlloc!(2,5.0)); Error: incompatible types for (("MyT_init(cast(MyT *) alloca(alloc_size(" ~ cast(immutable(char))2 ~ ")), " ~ cast(immutable(char))2 ~ ", ") ~ (5.0)): 'string' and 'double'
Re: Using double value in string template mixin
On Friday, 26 February 2016 at 11:03:43 UTC, Dibyendu Majumdar wrote: Hi, How do I use a double value in a mixin template that is generating string? Thanks and Regards Dibyendu Have you an example of what's failing right now to show ?
Using double value in string template mixin
Hi, How do I use a double value in a mixin template that is generating string? Thanks and Regards Dibyendu
GStreamer and D
Has anyone got any examples of using GStreamer from D. I found that GtkD packages a GStreamer API which is great, but there are very few example codes – at least that I have found. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: how do you append arrays?
On 02/26/2016 01:01 AM, Ali Çehreli wrote: On 02/26/2016 12:47 AM, asdf wrote: Trying to uncook the terminal failed however. It can't recognize struct tag-declarations I think: I've just found the following code among my collection of D snippets, which uses a different method and supports Ctrl-D: import std.stdio : writef, writeln; import core.stdc.stdio; import core.sys.posix.termios; /* The declaration of cfmakeraw, which is missing from standard D modules. */ extern(C) void cfmakeraw(termios *termios_p); void main() { /* Saving the existing state of tty. */ termios oldState; tcgetattr(1, ); /* Ensuring that it will be restored upon exit. */ scope (exit) tcsetattr(1, TCSADRAIN, ); /* Make a new state and set it to raw mode. */ termios newState; tcgetattr(1, ); cfmakeraw(); /* Use the new state in this terminal. */ tcsetattr(1, TCSADRAIN, ); /* * We are ready to read characters in this raw mode... */ /* This is Ctrl-D, the EOF character under Linux. */ enum endOfFile = '\4'; for (char c; c != endOfFile; ) { c = cast(char)fgetc(stdin); writef("%02x ", c); } writeln(); } Ali
Re: how do you append arrays?
On 02/26/2016 12:47 AM, asdf wrote: Trying to uncook the terminal failed however. It can't recognize struct tag-declarations I think: The following compiles and seems to work. I've marked my changes with // Ali: /* copy-paste code from: http://tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html */ import std.stdio;// Ali import core.sys.linux.termios; // struct termios oldterm; // struct termios newterm; termios oldterm;// Ali termios newterm;// Ali void uncook_term() { tcgetattr(stdin.fileno, ); newterm = oldterm; newterm.c_cflag = /*BAUDRATE | Ali */ CRTSCTS | CS8 | CLOCAL | CREAD; newterm.c_iflag = IGNPAR; newterm.c_oflag = 0; newterm.c_lflag = 0; tcflush(stdin.fileno, TCIFLUSH); tcsetattr(stdin.fileno, TCSANOW, ); } void restore_term() { tcsetattr(stdin.fileno, TCSANOW, ); } void main() { uncook_term(); int ch = fgetc(core.stdc.stdio.stdin); //read(); Ali while(ch != 'q' && !stdin.eof) { write(ch); ch = fgetc(core.stdc.stdio.stdin); //read(); Ali } restore_term(); } Ali
Re: how do you append arrays?
On Friday, 26 February 2016 at 00:40:40 UTC, Steven Schveighoffer wrote: ugh! history = line ~ history[0 .. $ - 1]; That works alot better =) Trying to uncook the terminal failed however. It can't recognize struct tag-declarations I think: /* copy-paste code from: http://tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html */ import core.sys.linux.termios; // struct termios oldterm; // struct termios newterm; termios.termios oldterm; termios.termios newterm; void uncook_term() { tcgetattr(stdin.fileno, ); newterm = oldterm; newterm.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD; newterm.c_iflag = IGNPAR; newterm.c_oflag = 0; newterm.c_lflag = 0; tcflush(stdin.fileno, TCIFLUSH); tcsetattr(stdin.fileno, TCSANOW, ); } void restore_term() { tcsetattr(stdin.fileno, TCSANOW, ); } void main() { uncook_term(); char ch = read(); while(ch != 'q' && !stdin.eof) { write(ch); ch = read(); } restore_term(); }
Re: Shared static constructors from C# EXE
On Thursday, 25 February 2016 at 17:46:18 UTC, Thalamus wrote: On Thursday, 25 February 2016 at 16:05:37 UTC, Benjamin Thaut wrote: [...] Thanks Benjamin. When I went to whittle this down to its barest essentials, though, the repro is pretty simple. It involves LIBs, but not Dlls, and it doesn't require anything but a single D EXE. [...] The problem is that when you build with -lib the resulting library is optimized for linker stripping. E.g. everything that is not directly used will not be pulled into the final executable. If you want everything in the final exectuable you shouldn't be using a .lib file. Instead compile with -c resutling in a .obj file and link the resulting .obj file into your executable. Then everything will end up in the final executable even if its not directly used. Kind Regards Benjamin Thaut
Re: Installing DUB on OSX
On 2016-02-25 22:38, Joel wrote: .dub is grayed out on Finder, and isn't writable. I'm suspecting that you don't own that directory. You can see the owner by running this: ls -l -a ~/ | grep dub The third column is the owner. You change the owner like this from the Terminal: sudo chown -R joelcnz ~/.dub Assuming "joelcnz" is your user account name. If you do are the owner then it looks like the directory isn't writable. You can check that with the same "ls" command. The permissions are in the first column. It should look like this: drwxr-xr-x Meaning writable, readable and executable by the owner. Readable and executable by the group, readable and executable by everyone else. To make it have those exact permissions, run the following: chmod 755 ~/.dub -- /Jacob Carlborg