Re: simple static if / traits question...
On Wednesday, 22 February 2017 at 22:37:25 UTC, Profile Anaysis wrote: On Wednesday, 22 February 2017 at 21:27:47 UTC, WhatMeWorry wrote: I'm doing conditional compilation using static ifs like so: enum bool audio = true; // if audio flag is present and set to true, add to code build static if ( (__traits(compiles, audio)) && audio) playSound(soundSys, BLEEP ); This works, but I thought there might be a simpler way. For instance, after perusing std.traits, I thought I would find something like isPresent(audio) or isSymbol(audio) templates. Or am I being obtuse here? Thanks. You do realize that audio is a compile time constant? This means that in the binary, everything that depends on it is evaluated(as it can be, since it is known). This means that whatever app you are using will not be able to be able to "adapt" to the system changes. In this case, if the system has audio there is no way for the binary to use it because you compiled it out(if audio = false). In such a case you do not want to use a static or compile time variable unless you plan on creating multiple binaries. If your example above was just for demo then yes, you can do that but compiles is not what you want. Compiles only checks if the statement that follows is compilable as valid D code and it doesn't have anything to do with the value of the variables. Definitely overthought this one big time. But there is so much meta goodness in std.traits that I felt compelled to use "compiles" :) There are a few options: 1. static if(audio) 2. version(audio) 3. if (audio) It looks like you are trying to create the version(audio) semantic(if exists then use, else don't). Ultimately, though, if you are trying to make a binary that can either use audio or not depending on where it is ran, you'll have to stick to using actual run time variables and probably be a bit more organized about it. option 1 is the one I was shooting for. does the static if (audio) just check for the existence of audio, or does it also check to see if audio is true as well? I've got a game tutorial with 15 sequential projects. Each project introduces a new concept by building on the previous project code. But I soon had so much code duplication that I decided to use common modules/functions. The specific code could be injected via flags in the apps.d Hence my original question.
Re: Checking, whether string contains only ascii.
On Wednesday, 22 February 2017 at 20:01:57 UTC, Adam D. Ruppe wrote: On Wednesday, 22 February 2017 at 19:26:15 UTC, berni wrote: herefore I'd like to make sure that the string the program read is only made up of ascii characters. Easiest: foreach(char ch; postscript) if(ch > 127) throw new Exception("non-ascii detected"); :)
Re: simple static if / traits question...
On Wednesday, 22 February 2017 at 21:27:47 UTC, WhatMeWorry wrote: I'm doing conditional compilation using static ifs like so: enum bool audio = true; // if audio flag is present and set to true, add to code build static if ( (__traits(compiles, audio)) && audio) playSound(soundSys, BLEEP ); This works, but I thought there might be a simpler way. For instance, after perusing std.traits, I thought I would find something like isPresent(audio) or isSymbol(audio) templates. Or am I being obtuse here? Thanks. You do realize that audio is a compile time constant? This means that in the binary, everything that depends on it is evaluated(as it can be, since it is known). This means that whatever app you are using will not be able to be able to "adapt" to the system changes. In this case, if the system has audio there is no way for the binary to use it because you compiled it out(if audio = false). In such a case you do not want to use a static or compile time variable unless you plan on creating multiple binaries. If your example above was just for demo then yes, you can do that but compiles is not what you want. Compiles only checks if the statement that follows is compilable as valid D code and it doesn't have anything to do with the value of the variables. There are a few options: 1. static if(audio) 2. version(audio) 3. if (audio) It looks like you are trying to create the version(audio) semantic(if exists then use, else don't). Ultimately, though, if you are trying to make a binary that can either use audio or not depending on where it is ran, you'll have to stick to using actual run time variables and probably be a bit more organized about it.
Re: Vibe.d: Listening to port 8080 on external device doesn't work
On Wednesday, 22 February 2017 at 00:53:53 UTC, krzaq wrote: On Wednesday, 22 February 2017 at 00:38:30 UTC, aberba wrote: Using vibe.d, I bind to port 8080 at 127.0.0.1 but I can't access server on my phone through hotspot using the external IP from ip addr on Linux. But 127.0.0 running Apache server works. Don't if its vibe.d or OS (ubuntu 14.04) How do I reached my vibe.d server in this case on my phone? Listen on "0.0.0.0". Thanks. Worked! Just realized both 127.0.0.1 and 0.0.0.0 cannot be both activated on the same port.
Re: simple static if / traits question...
On Wednesday, 22 February 2017 at 21:27:47 UTC, WhatMeWorry wrote: I'm doing conditional compilation using static ifs like so: enum bool audio = true; // if audio flag is present and set to true, add to code build static if ( (__traits(compiles, audio)) && audio) playSound(soundSys, BLEEP ); I think you're thinking too deeply on this. During optimization branches of if statements that always evaluate to false are compiled out.
Re: Checking, whether string contains only ascii.
On Wed, Feb 22, 2017 at 09:16:24PM +, kinke via Digitalmars-d-learn wrote: [...] > One more again as I couldn't believe noone went for 'any' yet: > > --- > import std.algorithm; > return !s.any!"a > 127"; // code-point level > --- You win 1 intarwebs for the shortest solution posted so far. ;-) Though, according to the OP, an exception is wanted, so it should be more along the lines of: enforce(!s.any!"a > 127"); T -- A bend in the road is not the end of the road unless you fail to make the turn. -- Brian White
simple static if / traits question...
I'm doing conditional compilation using static ifs like so: enum bool audio = true; // if audio flag is present and set to true, add to code build static if ( (__traits(compiles, audio)) && audio) playSound(soundSys, BLEEP ); This works, but I thought there might be a simpler way. For instance, after perusing std.traits, I thought I would find something like isPresent(audio) or isSymbol(audio) templates. Or am I being obtuse here? Thanks.
Re: Checking, whether string contains only ascii.
On Wednesday, 22 February 2017 at 20:07:34 UTC, Ali Çehreli wrote: One more: bool isAscii(string s) { import std.string : representation; import std.algorithm : canFind; return !s.representation.canFind!(c => c >= 0x80); } unittest { assert(isAscii("hello world")); assert(!isAscii("hellö wörld")); } Ali One more again as I couldn't believe noone went for 'any' yet: --- import std.algorithm; return !s.any!"a > 127"; // code-point level ---
Re: Serializer class
Yes thank you it works.
Re: Checking, whether string contains only ascii.
On 02/22/2017 12:02 PM, ag0aep6g wrote: > On Wednesday, 22 February 2017 at 19:26:15 UTC, berni wrote: >> In my program, I read a postscript file. Normal postscript files >> should only be composed of ascii characters, but one never knows what >> users give us. Therefore I'd like to make sure that the string the >> program read is only made up of ascii characters. This simplifies the >> code thereafter, because I then can assume, that codeunit==codepoint. >> Is there a simple way to do so? >> >> Here a sketch of my function: >> >>> void foo(string postscript) >>> { >>>// throw Exception, if postscript is not all ascii >>>// other stuff, assuming codeunit=codepoint >>> } > > Making full use of the standard library: > > > import std.algorithm: all; > import std.ascii: isASCII; > import std.exception: enforce; > > enforce(postscript.all!isASCII); > > > That checks on the code point level (because strings are ranges of > dchars). If you want to be clever, you can avoid decoding and check on > the code unit level: > > > /* other imports as above */ > import std.utf: byCodeUnit; > > enforce(postscript.byCodeUnit.all!isASCII); > > > Or you can do it manually, avoiding all those imports: > > > foreach (char c; postscript) if (c > 0x7F) throw new Exception("not > ASCII"); > One more: bool isAscii(string s) { import std.string : representation; import std.algorithm : canFind; return !s.representation.canFind!(c => c >= 0x80); } unittest { assert(isAscii("hello world")); assert(!isAscii("hellö wörld")); } Ali
Re: Checking, whether string contains only ascii.
On Wednesday, 22 February 2017 at 19:26:15 UTC, berni wrote: In my program, I read a postscript file. Normal postscript files should only be composed of ascii characters, but one never knows what users give us. Therefore I'd like to make sure that the string the program read is only made up of ascii characters. This simplifies the code thereafter, because I then can assume, that codeunit==codepoint. Is there a simple way to do so? Here a sketch of my function: void foo(string postscript) { // throw Exception, if postscript is not all ascii // other stuff, assuming codeunit=codepoint } Making full use of the standard library: import std.algorithm: all; import std.ascii: isASCII; import std.exception: enforce; enforce(postscript.all!isASCII); That checks on the code point level (because strings are ranges of dchars). If you want to be clever, you can avoid decoding and check on the code unit level: /* other imports as above */ import std.utf: byCodeUnit; enforce(postscript.byCodeUnit.all!isASCII); Or you can do it manually, avoiding all those imports: foreach (char c; postscript) if (c > 0x7F) throw new Exception("not ASCII");
Re: Checking, whether string contains only ascii.
On Wednesday, 22 February 2017 at 19:26:15 UTC, berni wrote: herefore I'd like to make sure that the string the program read is only made up of ascii characters. Easiest: foreach(char ch; postscript) if(ch > 127) throw new Exception("non-ascii detected");
Re: how to pass stderr to core.stdc.stdio.fileno
On Wednesday, 22 February 2017 at 19:46:28 UTC, berni wrote: As I cannot find any PM-feature in this forum and don't know how to contact you else, I'm hijacking this thread to give you some feedback... You can always email me directly too, destructiona...@gmail.com Maybe you can figure out, why this is not included in the search result? It was a bug in the pagination, that function was on page two, which I don't show (my experience is if the search result isn't on page one, you're wasting your time anyway and should refine the terms)... but it should have been on page one. That's fixed, and I tweaked the score algorithm to give it a bonus because it is a free-standing function with a matching name instead of some member variable. So now it shows as the first result.
Re: Checking, whether string contains only ascii.
On Wednesday, 22 February 2017 at 19:57:22 UTC, jklm wrote: On Wednesday, 22 February 2017 at 19:26:15 UTC, berni wrote: In my program, I read a postscript file. Normal postscript files should only be composed of ascii characters, but one never knows what users give us. Therefore I'd like to make sure that the string the program read is only made up of ascii characters. This simplifies the code thereafter, because I then can assume, that codeunit==codepoint. Is there a simple way to do so? Here a sketch of my function: void foo(string postscript) { // throw Exception, if postscript is not all ascii // other stuff, assuming codeunit=codepoint } void foo(string postscript) { import std.ascii, astd.algorithm.ieration; if (!postscript.filter!(a => !isASCII(a)).empty) throw new Exception("bla"); } \s postscript args[0]
Re: Checking, whether string contains only ascii.
On Wednesday, 22 February 2017 at 19:26:15 UTC, berni wrote: In my program, I read a postscript file. Normal postscript files should only be composed of ascii characters, but one never knows what users give us. Therefore I'd like to make sure that the string the program read is only made up of ascii characters. This simplifies the code thereafter, because I then can assume, that codeunit==codepoint. Is there a simple way to do so? Here a sketch of my function: void foo(string postscript) { // throw Exception, if postscript is not all ascii // other stuff, assuming codeunit=codepoint } void foo(string postscript) { import std.ascii, astd.algorithm.ieration; if (!args[0].filter!(a => !isASCII(a)).empty) throw new Exception("bla"); }
Re: Checking, whether string contains only ascii.
On Wed, Feb 22, 2017 at 11:43:00AM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > import std.range.primitives; > > bool isAsciiOnly(R)(R input) > if (isInputRange!R && is(ElementType!R : dchar)) > { > import std.algorithm.iteration : fold; > return input.fold!((a, b) => a && b < 0x80)(true); > } > > unittest > { > assert(isAsciiOnly("abcdefg")); > assert(!isAsciiOnly("abcбвг")); > } [...] Ah, missing the Exception part: void foo(string input) { if (!input.isAsciiOnly) throw new Exception("..."); } T -- Why are you blatanly misspelling "blatant"? -- Branden Robinson
Re: Checking, whether string contains only ascii.
On Wed, Feb 22, 2017 at 07:26:15PM +, berni via Digitalmars-d-learn wrote: > In my program, I read a postscript file. Normal postscript files > should only be composed of ascii characters, but one never knows what > users give us. Therefore I'd like to make sure that the string the > program read is only made up of ascii characters. This simplifies the > code thereafter, because I then can assume, that codeunit==codepoint. > Is there a simple way to do so? [...] Hmm... What about: import std.range.primitives; bool isAsciiOnly(R)(R input) if (isInputRange!R && is(ElementType!R : dchar)) { import std.algorithm.iteration : fold; return input.fold!((a, b) => a && b < 0x80)(true); } unittest { assert(isAsciiOnly("abcdefg")); assert(!isAsciiOnly("abcбвг")); } Basically, it iterates over the string / range of characters and checks that every character is less than 0x80, since anything that's 0x80 or greater cannot be ASCII. T -- INTEL = Only half of "intelligence".
Re: how to pass stderr to core.stdc.stdio.fileno
As I cannot find any PM-feature in this forum and don't know how to contact you else, I'm hijacking this thread to give you some feedback... On Friday, 17 February 2017 at 19:16:44 UTC, Adam D. Ruppe wrote: Yes, that is my documentation fork, it has a search feature if you do dpldocs.info/some_term and it tries to be easier to read and navigate, let me know how you like it! I tried dpldocs.info/max looking for a function that gives the maximum of two or more values. I got a lot of results, but non of them was, what I was looking for. Meanwhile I found it, namely this one: http://dpldocs.info/experimental-docs/std.algorithm.comparison.max.html Maybe you can figure out, why this is not included in the search result?
Checking, whether string contains only ascii.
In my program, I read a postscript file. Normal postscript files should only be composed of ascii characters, but one never knows what users give us. Therefore I'd like to make sure that the string the program read is only made up of ascii characters. This simplifies the code thereafter, because I then can assume, that codeunit==codepoint. Is there a simple way to do so? Here a sketch of my function: void foo(string postscript) { // throw Exception, if postscript is not all ascii // other stuff, assuming codeunit=codepoint }
Re: Serializer class
On Wednesday, 22 February 2017 at 18:34:26 UTC, houdoux09 wrote: void Read(T)(T value) { foreach(i, mm; value.tupleof) { writeln(__traits(identifier, value.tupleof[i]), " = ", mm); if(isArray!(typeof(mm))) { Read(mm[0]); //Error } } } You need to use "static if" here inside foreach. Otherwise the body of your "if" gets compiled for all the different fields of "value" and of course fails for the fields that are not arrays.
Re: How do I use CTFE to generate an immutable associative array at compile time?
On Wed, Feb 22, 2017 at 06:17:14PM +, Stefan Koch via Digitalmars-d-learn wrote: > On Wednesday, 22 February 2017 at 17:05:17 UTC, H. S. Teoh wrote: > > On Wed, Feb 22, 2017 at 04:08:45PM +, Stefan Koch via > > Digitalmars-d-learn wrote: > > > [...] > > > > I'm not sure it's that simple. Just because AA's become CTFEable > > doesn't mean they will automatically be convertible to object code > > in the executable that allows runtime AA lookups. For instance, a > > CTFE pointer will have a value that has no correspondence with the > > object code in the executable, and neither will memory allocated > > during CTFE have any correspondence with the emitted object code > > (because this memory is allocated in the compiler, not in the object > > code). So if the CTFE AA implementation allocates nodes for storing > > key/value pairs, they will only exist in the CTFE engine, and > > pointers to them will only make sense within the CTFE engine. In > > order to make them work in the executable (so that you can do AA > > lookups to these computed nodes at runtime), you will need to > > somehow map them to object code. Just because AA's become CTFEable > > will not automatically solve this for you. > > > > [...] > > The CTFE allocated memory can be copied into the object file verbatim > because the structure is the same. Pointers are easy to fix up as > well, because by definition the have to point to static data that will > be in the object file. This will fail for cross-compilation. Unless you mean that the new CTFE engine is emulating the target machine directly? T -- Computers shouldn't beep through the keyhole.
Serializer class
Hello, i am new in D and i have a problem. I would like to retrieve the names of the variables and their value. But i can not retrieve the value of the array. class Test { public int a; public Test[] b; this() { a = 1; b = [new Test(), new Test()]; } } //== void Read(T)(T value) { foreach(i, mm; value.tupleof) { writeln(__traits(identifier, value.tupleof[i]), " = ", mm); if(isArray!(typeof(mm))) { Read(mm[0]); //Error } } } void main(string[] args) { Read(new Test()); } Thank you for your help.
Re: How do I use CTFE to generate an immutable associative array at compile time?
On Wednesday, 22 February 2017 at 17:05:17 UTC, H. S. Teoh wrote: On Wed, Feb 22, 2017 at 04:08:45PM +, Stefan Koch via Digitalmars-d-learn wrote: [...] I'm not sure it's that simple. Just because AA's become CTFEable doesn't mean they will automatically be convertible to object code in the executable that allows runtime AA lookups. For instance, a CTFE pointer will have a value that has no correspondence with the object code in the executable, and neither will memory allocated during CTFE have any correspondence with the emitted object code (because this memory is allocated in the compiler, not in the object code). So if the CTFE AA implementation allocates nodes for storing key/value pairs, they will only exist in the CTFE engine, and pointers to them will only make sense within the CTFE engine. In order to make them work in the executable (so that you can do AA lookups to these computed nodes at runtime), you will need to somehow map them to object code. Just because AA's become CTFEable will not automatically solve this for you. [...] The CTFE allocated memory can be copied into the object file verbatim because the structure is the same. Pointers are easy to fix up as well, because by definition the have to point to static data that will be in the object file.
Re: About void[] and asockets
On Wednesday, 22 February 2017 at 17:57:31 UTC, Adam D. Ruppe wrote: On Wednesday, 22 February 2017 at 17:53:21 UTC, Jolly James wrote: No matter how I try, I am always getting: Error: none of the overloads of '__ctor' are callable using argument types (Data*), candidates are: (my-project) I don't know the library, so I'd have to see the Data class, but you might just be using &data when you should be using plain data. Silly me! Now I used Xamarin's Find-Usage-Feature, found one usage in ae and realized that there is no reason for using the keyword `new`, as Data is a struct (and so one does not need `new` unlike in C#) ...
Re: About void[] and asockets
On Wednesday, 22 February 2017 at 17:53:21 UTC, Jolly James wrote: No matter how I try, I am always getting: Error: none of the overloads of '__ctor' are callable using argument types (Data*), candidates are: (my-project) I don't know the library, so I'd have to see the Data class, but you might just be using &data when you should be using plain data.
Re: About void[] and asockets
On Wednesday, 22 February 2017 at 17:06:51 UTC, Jolly James wrote: On Wednesday, 22 February 2017 at 17:01:11 UTC, Adam D. Ruppe wrote: On Wednesday, 22 February 2017 at 16:55:03 UTC, Jolly James wrote: Well, what are these void-arrays for real? I mean, they contain data what does not make them really void, does it? They represent an array of anything; the user can pass ubyte[] to it, or int[] to it, or char[] to it, or anything else (even string if it is in void[] or const void[]). And how to I get received data out of Data.content[]? How to use TcpConnection.send()? E.g. for sending a string? Cast it to `const(ubyte)[]` then use it as a bag of bytes. That's almost always what you want to do inside. The function signature uses `in void[]` instead of `ubyte[]` because void will accept strings and other stuff too, whereas ubyte specifically requires it to be typed as bye. You want to use it INTERNALLY as bytes, but the external interface can accept almost anything. Thank you very much! Now it makes sense and I understand. But I have one problem: How to use the constructor of the Data class? No matter how I try, I am always getting: Error: none of the overloads of '__ctor' are callable using argument types (Data*), candidates are: (my-project)
Re: How do I use CTFE to generate an immutable associative array at compile time?
On Wed, Feb 22, 2017 at 04:08:45PM +, Stefan Koch via Digitalmars-d-learn wrote: > On Wednesday, 22 February 2017 at 15:27:22 UTC, H. S. Teoh wrote: > > (In fact, now I'm wondering if we could just hack dmd to emit the > > equivalent of this code as a lowering, whenever the user tries to > > declare a compile-time initialized AA.) > > All the problems disappear if the AA's are compiler visible and > CTFEable code. I'm not sure it's that simple. Just because AA's become CTFEable doesn't mean they will automatically be convertible to object code in the executable that allows runtime AA lookups. For instance, a CTFE pointer will have a value that has no correspondence with the object code in the executable, and neither will memory allocated during CTFE have any correspondence with the emitted object code (because this memory is allocated in the compiler, not in the object code). So if the CTFE AA implementation allocates nodes for storing key/value pairs, they will only exist in the CTFE engine, and pointers to them will only make sense within the CTFE engine. In order to make them work in the executable (so that you can do AA lookups to these computed nodes at runtime), you will need to somehow map them to object code. Just because AA's become CTFEable will not automatically solve this for you. > There is as far as I know a project by Martin Nowak that does that. > And uses templates for AA's rather then whacky TypeInfos. > > So in the future this problem will disappear. Oh I know, the problem is that this "future" has been taking a long time arriving. I was involved in an early (but unfortunately unsuccessful) effort to rewrite AA's as library code. But there was simply too much compiler magic involved with AA's that it couldn't work at the time. Much of this magic has been dispelled over the past few years, though, so we should be in better shape now for moving AA's completely into the library. I'm very much looking forward to Martin's implementation when it's ready. But in the meantime, lowering compile-time initialized AA's could have the above hack as a temporary workaround until we can get AA literals to be embeddable in object code. T -- GEEK = Gatherer of Extremely Enlightening Knowledge
Re: About void[] and asockets
On Wednesday, 22 February 2017 at 17:01:11 UTC, Adam D. Ruppe wrote: On Wednesday, 22 February 2017 at 16:55:03 UTC, Jolly James wrote: Well, what are these void-arrays for real? I mean, they contain data what does not make them really void, does it? They represent an array of anything; the user can pass ubyte[] to it, or int[] to it, or char[] to it, or anything else (even string if it is in void[] or const void[]). And how to I get received data out of Data.content[]? How to use TcpConnection.send()? E.g. for sending a string? Cast it to `const(ubyte)[]` then use it as a bag of bytes. That's almost always what you want to do inside. The function signature uses `in void[]` instead of `ubyte[]` because void will accept strings and other stuff too, whereas ubyte specifically requires it to be typed as bye. You want to use it INTERNALLY as bytes, but the external interface can accept almost anything. Thank you very much! Now it makes sense and I understand.
Re: About void[] and asockets
On Wednesday, 22 February 2017 at 16:55:03 UTC, Jolly James wrote: Well, what are these void-arrays for real? I mean, they contain data what does not make them really void, does it? They represent an array of anything; the user can pass ubyte[] to it, or int[] to it, or char[] to it, or anything else (even string if it is in void[] or const void[]). And how to I get received data out of Data.content[]? How to use TcpConnection.send()? E.g. for sending a string? Cast it to `const(ubyte)[]` then use it as a bag of bytes. That's almost always what you want to do inside. The function signature uses `in void[]` instead of `ubyte[]` because void will accept strings and other stuff too, whereas ubyte specifically requires it to be typed as bye. You want to use it INTERNALLY as bytes, but the external interface can accept almost anything.
Re: Class Order Style
On Tuesday, 21 February 2017 at 23:06:23 UTC, Jonathan M Davis wrote: On Tuesday, February 21, 2017 22:41:40 Lenny Lowood via Digitalmars-d-learn wrote: [...] It's completely a stylistic preference. There are a number of different ways to order your member variables and functions, and there are several different ways to apply attributes to them. [...] thank you!
About void[] and asockets
For sure, some might know ae. I am trying to use it as TcpServer. I got almost everything working fine concerning connection establishment and disconnecting. But there is one thing that makes it hard for me to understand, how to handle data. https://github.com/CyberShadow/ae/blob/master/net/asockets.d Well, what are these void-arrays for real? I mean, they contain data what does not make them really void, does it? And how to I get received data out of Data.content[]? How to use TcpConnection.send()? E.g. for sending a string?
Re: How do I use CTFE to generate an immutable associative array at compile time?
On Wednesday, 22 February 2017 at 15:27:22 UTC, H. S. Teoh wrote: (In fact, now I'm wondering if we could just hack dmd to emit the equivalent of this code as a lowering, whenever the user tries to declare a compile-time initialized AA.) All the problems disappear if the AA's are compiler visible and CTFEable code. There is as far as I know a project by Martin Nowak that does that. And uses templates for AA's rather then whacky TypeInfos. So in the future this problem will disappear.
Re: How do I use CTFE to generate an immutable associative array at compile time?
On Wed, Feb 22, 2017 at 09:00:36AM +0100, Jacob Carlborg via Digitalmars-d-learn wrote: [...] > You can use an enum to declare the AA and then assign it to an > immutable variable using "static this". The you would only use to the > immutable variable and never the enum. > > enum aa = [1 : 2]; > > immutable int[int] iaa; > > static this() > { > iaa = aa; > } [...] Wow, this is miles better than the hacks that I've come up with! Also makes the no-static-AA issue much less of a problem that I thought it was. (In fact, now I'm wondering if we could just hack dmd to emit the equivalent of this code as a lowering, whenever the user tries to declare a compile-time initialized AA.) T -- Computers are like a jungle: they have monitor lizards, rams, mice, c-moss, binary trees... and bugs.
Re: FEM library?
On Wednesday, 22 February 2017 at 11:37:41 UTC, XavierAP wrote: @Nicholas yes such a FEM library to be developed would heavily depend on Mir. Ilya Yaroshenko pointed me to it in another thread. I didn't know about DlangScience, thanks. Looks like there is some overlap? I think mir used to be part of DlangScience, but I don't really know the history. Ilya and Seb are on both teams. From what I understand DlangScience is and aggregation of science related projects as well as some "in house" stuff see e.g. the stats stuff. @Dukc thanks! Whenever in the future I'm developing for a library project or following it... Looks like those development threads currently go in the General board? Wouldn't it be better to split them together into one board within the Development section? Looks like inside General, library/project threads get lost and buried too quickly. I know many/most people are using this via email though, but still. If you're looking for libraries (to use and/or to contribute) general is the place. If you're wondering how they work/ how to use them, learn is best, although it could go in general. If you've done something cool (like this!) put it on announce. If you're participating in the development of then you'll want to use whatever medium the other dev use e.g. gitter/github
Re: Returning the address of a reference return value in @safe code - 2.072 regression?
On Monday, 20 February 2017 at 20:49:43 UTC, Johan Engelen wrote: The error is: "cannot take address of ref return of this.foo() in @safe function bar". Maybe a bugfix in safety system? Should it go through deprecation process?
Re: FEM library?
@Nicholas yes such a FEM library to be developed would heavily depend on Mir. Ilya Yaroshenko pointed me to it in another thread. I didn't know about DlangScience, thanks. Looks like there is some overlap? @Dukc thanks! Whenever in the future I'm developing for a library project or following it... Looks like those development threads currently go in the General board? Wouldn't it be better to split them together into one board within the Development section? Looks like inside General, library/project threads get lost and buried too quickly. I know many/most people are using this via email though, but still.
Re: Getting nice print of struct for debugging
On Tuesday, 21 February 2017 at 14:02:54 UTC, Jacob Carlborg wrote: [...] Yes, this works, I would say this is the simplest: MyStruct s; foreach (index, name ; FieldNameTuple!MyStruct) writefln("%s: %s", name, s.tupleof[index]); If you want something more close to "send" in Ruby, you need to use a string mixin, like this: foreach (name ; FieldNameTuple!MyStruct) writefln("%s: %s", name, mixin("s." ~ name)); The string mixin example works for methods, opDispatch and similar as well. The tupleof example, the first one, works only for fields. Exactly what I was looking for, **thank you!** Both ways of accessing the struct elements are very interesting, giving an impression what is possible with D. Is it possible to overwrite "toString" for all structs in one step? Regards mt.
Re: Hello, folks! Newbie to D, have some questions!
On Wednesday, 22 February 2017 at 07:48:42 UTC, Steve Biedermann wrote: On Tuesday, 21 February 2017 at 17:13:30 UTC, timmyjose wrote: I would upvote you if I could! :-) ... that's not only an interesting read, but also fodder for mini-projects of my own! If you need more details about a specific topic, just post it in the forum and we will try to help :) If you want some sourcecode to look at you can write me a mail and I can give you access to some of my tools. The ones which are stored on bitbucket are pretty simple to understand, but not quite ready for public release (no polishing etc.). Thanks, Steve. That'd be great! I will surely take you up on that offer. Right now I'm working through "Learning D", and loving every bit of it! From there I plan to get right down to coding on some small but interesting projects, and any help I can get would be most welcome! :-)
Re: Vibe.d: Listening to port 8080 on external device doesn't work
On Wednesday, 22 February 2017 at 00:38:30 UTC, aberba wrote: Using vibe.d, I bind to port 8080 at 127.0.0.1 but I can't access server on my phone through hotspot using the external IP from ip addr on Linux. But 127.0.0 running Apache server works. Don't if its vibe.d or OS (ubuntu 14.04) How do I reached my vibe.d server in this case on my phone? Not forget to open 8080 port of incoming connections.
Re: How do I use CTFE to generate an immutable associative array at compile time?
Yes this is how I mean it. Dne 22. 2. 2017 9:05 napsal uživatel "Jacob Carlborg via Digitalmars-d-learn" : > On 2017-02-21 23:49, H. S. Teoh via Digitalmars-d-learn wrote: > > That may appear to work, but I would *strongly* recommend against it, >> because what happens when you use enum with an AA, is that the AA will >> be created *at runtime*, *every single time* it is referenced. (It is >> as if you copy-n-pasted the entire AA into the code each time you >> reference the enum.) Which will introduce ridiculous amounts of >> redundant work at runtime and cause a big performance penalty. >> > > You can use an enum to declare the AA and then assign it to an immutable > variable using "static this". The you would only use to the immutable > variable and never the enum. > > enum aa = [1 : 2]; > > immutable int[int] iaa; > > static this() > { > iaa = aa; > } > > -- > /Jacob Carlborg >
Re: How do I use CTFE to generate an immutable associative array at compile time?
On 2017-02-21 23:49, H. S. Teoh via Digitalmars-d-learn wrote: That may appear to work, but I would *strongly* recommend against it, because what happens when you use enum with an AA, is that the AA will be created *at runtime*, *every single time* it is referenced. (It is as if you copy-n-pasted the entire AA into the code each time you reference the enum.) Which will introduce ridiculous amounts of redundant work at runtime and cause a big performance penalty. You can use an enum to declare the AA and then assign it to an immutable variable using "static this". The you would only use to the immutable variable and never the enum. enum aa = [1 : 2]; immutable int[int] iaa; static this() { iaa = aa; } -- /Jacob Carlborg