Re: Memoization in compile-time

2015-03-13 Thread Meta via Digitalmars-d-learn
On Friday, 13 March 2015 at 13:51:43 UTC, Dennis Ritchie wrote: And you can somehow memoization stuff at compile time? If you want memoization at compile time I would suggest using the template version of Factorial as template instantiations are cached by the compiler. However, std.functional

Re: Memoization in compile-time

2015-03-13 Thread Meta via Digitalmars-d-learn
On Friday, 13 March 2015 at 12:49:48 UTC, Dennis Ritchie wrote: On Friday, 13 March 2015 at 02:38:18 UTC, Rikki Cattermole wrote: You could assign it to e.g. an enum. Or force it over using meta-programming. And this code can be rewritten to D? template struct Factorial { enum { value =

Re: Parallelization of a large array

2015-03-10 Thread Meta via Digitalmars-d-learn
On Tuesday, 10 March 2015 at 22:37:29 UTC, Ali Çehreli wrote: On 03/10/2015 03:16 PM, Meta wrote: > Just add a condition variable. > > import std.stdio; > import std.algorithm; > import std.parallelism; > > void main() { > > int b = 2; > > auto a = [1, 2, 2, 3]; > > if (find(a, b)

Re: Parallelization of a large array

2015-03-10 Thread Meta via Digitalmars-d-learn
On Tuesday, 10 March 2015 at 22:11:57 UTC, Dennis Ritchie wrote: On Tuesday, 10 March 2015 at 21:27:42 UTC, Dennis Ritchie wrote: Thanks. No, it does not suit me, because of the parallel array in a foreach loop there is no break. import std.stdio; import std.algorithm; import std.parallelis

Re: expand variadic template parameters

2015-03-10 Thread Meta via Digitalmars-d-learn
On Tuesday, 10 March 2015 at 19:11:22 UTC, André wrote: Hi, in this minified example I try to expand the variadic parmaters of foo to bar: import std.typecons; void foo(T ...)(T args) { bar(args.expand); } void bar(int i, string s){} void main() { foo(1, "a"); } I got the syn

Re: 2.067 Beta: Behavior of enum and ref changed

2015-03-10 Thread Meta via Digitalmars-d-learn
On Tuesday, 10 March 2015 at 08:37:46 UTC, Jonathan M Davis wrote: It's the base type that isn't implicitly convertible to the enum type. Err, yes. I had that the wrong way around. Anyway, I filed an issue. https://issues.dlang.org/show_bug.cgi?id=14269

Re: 2.067 Beta: Behavior of enum and ref changed

2015-03-10 Thread Meta via Digitalmars-d-learn
On Tuesday, 10 March 2015 at 07:04:48 UTC, Andre wrote: Hi, following coding raises a compiler error with the beta of 2.067. Is this error intended or not? It is working if I change first line of main to: ulong bits; enum Bits: ulong { none = 0 } bool hasBit(ref ulong rBits, ulong rBit

Re: std.stdio.writeln

2015-03-09 Thread Meta via Digitalmars-d-learn
On Monday, 9 March 2015 at 22:00:46 UTC, ketmar wrote: i remember that deprecation was rejected. maybe this is false memory, though. btw, there are legit uses of comma, in c-style `for`, for example. this should be left intact, i think (oh, can c-style `for` be deprecated too?! ). I think

Re: string-int[] array

2015-03-08 Thread Meta via Digitalmars-d-learn
On Sunday, 8 March 2015 at 21:41:44 UTC, FG wrote: On 2015-03-08 at 20:26, Meta wrote: On Sunday, 8 March 2015 at 18:57:38 UTC, Kagamin wrote: http://dpaste.dzfl.pl/2c8d4a7d9ef0 like this. What in the world is that code doing? I'm having a hard time wrapping my head around this. It's a tri

Re: Template pred is true for pred!(pred!(pred)) but not for value "true"

2015-03-08 Thread Meta via Digitalmars-d-learn
On Sunday, 8 March 2015 at 21:17:31 UTC, Meta wrote: Urgh, I'm all messed up now. The results in the second case are correct, but the results in the first case are wrong, as !canBeAlias!true should be !false, not !true. I also get the same results with __traits(compiles, { alias _ = T[0]; }).

Re: Template pred is true for pred!(pred!(pred)) but not for value "true"

2015-03-08 Thread Meta via Digitalmars-d-learn
On Sunday, 8 March 2015 at 21:11:12 UTC, Meta wrote: Yeah, definitely wrong. template canBeAlias(T...) if (T.length == 1) { static if (is(typeof({alias _ = T[0];}))) { enum canBeAlias = true; } else { enum canBeAlias = false

Re: Template pred is true for pred!(pred!(pred)) but not for value "true"

2015-03-08 Thread Meta via Digitalmars-d-learn
On Sunday, 8 March 2015 at 20:36:34 UTC, anonymous wrote: I get an error on your code: "test.d(16): Error: static assert (canBeAlias!(true)) is false". But when commenting out the first assert (line 15), there's no error. Hmm, I might have made a mistake reducing my actual code. Played arou

Re: string-int[] array

2015-03-08 Thread Meta via Digitalmars-d-learn
On Sunday, 8 March 2015 at 18:57:38 UTC, Kagamin wrote: http://dpaste.dzfl.pl/2c8d4a7d9ef0 like this. What in the world is that code doing? I'm having a hard time wrapping my head around this.

Re: string-int[] array

2015-03-08 Thread Meta via Digitalmars-d-learn
On Sunday, 8 March 2015 at 18:38:02 UTC, Dennis Ritchie wrote: On Sunday, 8 March 2015 at 18:18:15 UTC, Baz wrote: import std.stdio; import std.typecons; alias T = Tuple!(string, int); void main(string[] args) { T[] tarr; tarr ~= T("a",65); tarr ~= T("b",66); writeln(tarr); }

Template pred is true for pred!(pred!(pred)) but not for value "true"

2015-03-08 Thread Meta via Digitalmars-d-learn
template canBeAlias(T...) if (T.length == 1) { static if (is(typeof({alias _ = T[0];}))) { enum canBeAlias = true; } else { enum canBeAlias = false; } } pragma(msg, canBeAlias!canBeAlias); //prints "true" static asser

Re: Will D have a serious dedicated well supported IDE like Visual Studio or Eclipse?

2015-02-26 Thread Meta via Digitalmars-d-learn
On Thursday, 26 February 2015 at 20:55:52 UTC, Rinzler wrote: Thanks! Actually I had already seen that page, but I was asking for other open-source projects. If there's someone working on a D dedicated IDE or not. I've been using DlangIDE on Linux, which is young but solid so far, and VisualD

Re: Wrong overload resolution

2015-02-16 Thread Meta via Digitalmars-d-learn
On Sunday, 15 February 2015 at 23:48:50 UTC, rumbu wrote: This problem appears only if one of the parameters is an interface. Without it or using any other type as a second parameter instead of the interface, it compiles. Also it compiles if the passed interface is null. The example below us

Re: Ncurses deprecated "~master" issue

2015-02-10 Thread Meta via Digitalmars-d-learn
On Tuesday, 10 February 2015 at 21:14:36 UTC, H. S. Teoh wrote: Judging by the name of the object file (test.o) and the name of the code section (.text), I'd say this is definitely Posix. :-) So the question is why that ctor isn't defined in spite of it being Posix. T Heh, you are right. I

Re: Ncurses deprecated "~master" issue

2015-02-10 Thread Meta via Digitalmars-d-learn
On Tuesday, 10 February 2015 at 20:50:28 UTC, Paul wrote: On Tuesday, 10 February 2015 at 19:49:26 UTC, ketmar wrote: On Tue, 10 Feb 2015 19:37:59 +, Meta wrote: I can't answer your question, but if you're just prototyping you could use Adam Ruppe's terminal.d until you get ncurses workin

Re: Ncurses deprecated "~master" issue

2015-02-10 Thread Meta via Digitalmars-d-learn
On Tuesday, 10 February 2015 at 13:18:34 UTC, Paul wrote: On Wednesday, 3 December 2014 at 19:37:03 UTC, Paul wrote: On Wednesday, 3 December 2014 at 17:37:18 UTC, Matt Soucy wrote: On 12/03/2014 07:07 AM, Paul wrote: Sorry if this is a little off-topic, I posted this in the Dub forum on 23/11

Re: hasmap with tuple as key

2015-02-09 Thread Meta via Digitalmars-d-learn
On Monday, 9 February 2015 at 21:22:29 UTC, Ondra wrote: Is there any drawback of doing this: string[Tuple!(int, int)] a; Especially performance one. Thanks. Tuples are really just structs generated "on the fly", so they are very fast. Hashmaps use the GC, though, so keep that in mind.

Re: Fun with floating point

2015-02-07 Thread Meta via Digitalmars-d-learn
On Saturday, 7 February 2015 at 16:06:14 UTC, Kenny wrote: Hi, D community! I have this program: import std.stdio; import std.conv; int main(string[] argv) { float eps = 1.0f; float f = 0.0f; while (f + eps != f) f += 1.0f; writeln("eps = " ~ to!string(eps) ~

Re: Using "reduce" with user types

2015-02-07 Thread Meta via Digitalmars-d-learn
On Saturday, 7 February 2015 at 13:38:00 UTC, Kadir Erdem Demir wrote: How can I imagine what "map" does in my mind, because it doesn't matches with the transform concept in my mind? You can think of map as taking a range of something (in this case, an array of A), and calling a user-supplied

Re: shared Variant[string]

2015-01-28 Thread Meta via Digitalmars-d-learn
On Wednesday, 28 January 2015 at 12:46:20 UTC, Fyodor Ustinov wrote: On Wednesday, 28 January 2015 at 12:32:29 UTC, Tobias Pankrath wrote: In your case above, it's std.variant : Variant, which does not work when shared. I look into variant.d and after seeing so many lines "@@@ BUG" - strange

Re: "Cannot infer argument types" for foreach over byLine

2015-01-24 Thread Meta via Digitalmars-d-learn
On Saturday, 24 January 2015 at 08:44:45 UTC, Ali Çehreli wrote: On 01/24/2015 12:14 AM, Meta wrote: > import std.stdio; > > void main() > { > foreach (i, line; file.byLine()) Unless the range itself provides explicitly, automatic counter is available only for arrays. Otherwise, you have

"Cannot infer argument types" for foreach over byLine

2015-01-24 Thread Meta via Digitalmars-d-learn
import std.stdio; void main() { foreach (i, line; file.byLine()) { writeln(line); } } This code gives me the error: Error: cannot infer argument types, expected 1 argument, not 2 This is a very obtuse compiler message considering how simple the code is; I know it's got som

Re: Defining a static array with values in a range

2015-01-22 Thread Meta via Digitalmars-d-learn
On Thursday, 22 January 2015 at 19:13:46 UTC, Meta wrote: On Thursday, 22 January 2015 at 19:12:32 UTC, zeljkog wrote: On 22.01.15 20:05, Meta wrote: On Thursday, 22 January 2015 at 19:00:47 UTC, zeljkog wrote: On 22.01.15 19:26, Meta wrote: On Thursday, 22 January 2015 at 18:23:00 UTC, Meta

Re: Defining a static array with values in a range

2015-01-22 Thread Meta via Digitalmars-d-learn
On Thursday, 22 January 2015 at 19:12:32 UTC, zeljkog wrote: On 22.01.15 20:05, Meta wrote: On Thursday, 22 January 2015 at 19:00:47 UTC, zeljkog wrote: On 22.01.15 19:26, Meta wrote: On Thursday, 22 January 2015 at 18:23:00 UTC, Meta wrote: Whoops, I forgot to make it a template to force CTFE

Re: Defining a static array with values in a range

2015-01-22 Thread Meta via Digitalmars-d-learn
On Thursday, 22 January 2015 at 19:00:47 UTC, zeljkog wrote: On 22.01.15 19:26, Meta wrote: On Thursday, 22 January 2015 at 18:23:00 UTC, Meta wrote: Whoops, I forgot to make it a template to force CTFE. You can force CTFE assigning to manifest constant. enum t = charRange!... By wrapping

Re: Defining a static array with values in a range

2015-01-22 Thread Meta via Digitalmars-d-learn
On Thursday, 22 January 2015 at 18:23:00 UTC, Meta wrote: Whoops, I forgot to make it a template to force CTFE. import std.stdio; template charRange(string spec) { static processInput(string spec) { import std.algorithm; import std.ascii; import std.conv;

Re: Defining a static array with values in a range

2015-01-22 Thread Meta via Digitalmars-d-learn
On Thursday, 22 January 2015 at 17:45:59 UTC, tcak wrote: So, at the end of the day (I left working on my Matcher class in the morning waiting an answer for this question), there is nothing to convert ['a'..'d', '0'..'3'] to ['a', 'b', 'c', 'd', '0', '1', '2', '3'] at compile time automatically

Re: On Variable References

2015-01-22 Thread Meta via Digitalmars-d-learn
On Thursday, 22 January 2015 at 14:52:26 UTC, Marc Schütz wrote: On Wednesday, 21 January 2015 at 17:14:29 UTC, Meta wrote: On Wednesday, 21 January 2015 at 08:23:44 UTC, Per Nordlöw wrote: On Wednesday, 21 January 2015 at 08:22:44 UTC, Per Nordlöw wrote: int x; auto ref xr; Correction: I,

Re: On Variable References

2015-01-21 Thread Meta via Digitalmars-d-learn
On Wednesday, 21 January 2015 at 08:23:44 UTC, Per Nordlöw wrote: On Wednesday, 21 January 2015 at 08:22:44 UTC, Per Nordlöw wrote: int x; auto ref xr; Correction: I, of course mean, int x = 42; auto ref xr = x; Walter is strongly against adding references a la C++ to D, as he

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-07 Thread Meta via Digitalmars-d-learn
On Wednesday, 7 January 2015 at 23:27:19 UTC, anonymous wrote: Don't do this without `dup`ing. Quoting the documentation: Oh, whoops. I thought those special variadic args were always allocated on the heap.

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-07 Thread Meta via Digitalmars-d-learn
On Wednesday, 7 January 2015 at 16:17:47 UTC, Tobias Pankrath wrote: A slice seems overkill to refer to just one object, but is that the best way ? struct Tree { Tree[] children; } Is one way to do it. You can add some nice sugar for this as well: struct Tree { this(string data, T

Re: Template function type inference with default arguments

2015-01-03 Thread Meta via Digitalmars-d-learn
On Sunday, 4 January 2015 at 00:22:01 UTC, ixid wrote: Why don't templates take a type from the default argument if nothing else is supplied? It would be useful to be able to use an enum to set a default. I doubt anyone's ever thought of that particular use-case. Using your typeof(MAX) workar

Re: Passing string literals to C

2014-12-31 Thread Meta via Digitalmars-d-learn
On Wednesday, 31 December 2014 at 12:25:45 UTC, John Colvin wrote: String literals can implicitly convert to const(char)* or immutable(char)*. Neat. It doesn't appear to apply to array literals in general though... I believe this is a special case specifically for strings added for convenienc

Re: `shared Mutex`?

2014-12-28 Thread Meta via Digitalmars-d-learn
On Sunday, 28 December 2014 at 09:24:31 UTC, Aiden wrote: Hello all, This is my first post on these forums. I've been learning D for the past couple of months or so and have been quite impressed by the language thus far. One stumbling block that I have encountered is with using `shared`, and

Re: Enum template with mixin, need 'this'

2014-12-24 Thread Meta via Digitalmars-d-learn
On Wednesday, 24 December 2014 at 20:08:07 UTC, Meta wrote: I am curious, however, why changing `enum` to `auto` (or bool) doesn't work. You said that the mixin tries to interpret the expression `cast(bool)(embeddedTest.bits & )` at compile time, but I don't understand why that would be so when

Re: Enum template with mixin, need 'this'

2014-12-24 Thread Meta via Digitalmars-d-learn
I am curious, however, why changing `enum` to `auto` (or bool) doesn't work. You said that the mixin tries to interpret the expression `cast(bool)(embeddedTest.bits & )` at compile time, but I don't understand why that would be so when the storage is auto and not enum. I guess mixin doesn't wor

Re: Enum template with mixin, need 'this'

2014-12-24 Thread Meta via Digitalmars-d-learn
On Wednesday, 24 December 2014 at 17:41:09 UTC, ketmar via Digitalmars-d-learn wrote: On Wed, 24 Dec 2014 17:05:45 + Meta via Digitalmars-d-learn wrote: So `if (isSet!bit1)` becomes `if (cast(bool)(embeddedTest.bits & bit1)`. That doesn't work, however. I get an error messag

Enum template with mixin, need 'this'

2014-12-24 Thread Meta via Digitalmars-d-learn
The code I currently have is as follows: import std.stdio; import std.traits; import std.typecons; struct EmbeddedTest { int bits; } struct Test { //Other stuff EmbeddedTest embeddedTest; enum isSet(alias bit) = `cast(bool)(embeddedTest.bits & `

Re: Asssociative Array by Key-Value-Pair

2014-12-15 Thread Meta via Digitalmars-d-learn
On Monday, 15 December 2014 at 18:55:13 UTC, bearophile wrote: Now this yields tuples: assert(aa.byPair!Tuple.array == aa.pairs!Tuple); But I'd really like tuples as built-ins for D -.- This is a work-around that cements the ugly Phobos tuples in the language... -.- Bye, bearophile Kenji

Re: How can I define a label inside a switch?

2014-12-14 Thread Meta via Digitalmars-d-learn
On Sunday, 14 December 2014 at 18:41:54 UTC, MachineCode wrote: The labels are disabled then? I find that goto case case_value ugly and prefer goto labelName; but if it's the only way to go let's do it I'm not sure if it's intentionally not supported, or just an oversight. Probably the former

Re: Learning D for a non computer science background person : pre-requisite knowledge?

2014-12-02 Thread Meta via Digitalmars-d-learn
On Tuesday, 2 December 2014 at 16:38:34 UTC, Mayuresh Kathe wrote: While I have been a programmer for close to 23 years, it's been mostly API level code cobbling work. Would like to learn "D", but am a bit intimidated by the fact that I don't have much of a grasp over the foundational stuff (

Re: curl: catching exception on connect.

2014-11-30 Thread Meta via Digitalmars-d-learn
On Sunday, 30 November 2014 at 19:24:39 UTC, Suliman wrote: I can't understand why I am getting exception on next code: void downloadFile() { foreach(link; links) { try {

Re: Can't understand templates

2014-11-29 Thread Meta via Digitalmars-d-learn
On Saturday, 29 November 2014 at 18:19:40 UTC, Sly wrote: You miss another definition which introduces a conflict: T getResponse(T)(string question) {...} In that case, you're better off with a pair of declarations: struct Point(T) { T x; T y; } T getResponse(T)(string message

Re: Can't understand templates

2014-11-29 Thread Meta via Digitalmars-d-learn
On Saturday, 29 November 2014 at 11:07:34 UTC, Sly wrote: On Saturday, 29 November 2014 at 09:11:51 UTC, Ali Çehreli wrote: Point!T getResponse(P : Point!T, T)(string question) { // ... } This doesn't work because now this definition has 2 parameters P and T. I have to specify both like

Re: Uninitialized object hangs without warning.

2014-11-25 Thread Meta via Digitalmars-d-learn
On Wednesday, 26 November 2014 at 05:24:49 UTC, Bear Cherian wrote: I ran into this a while ago and have already moved on, but I had a class such as this Class MyClass{ this(){} void someFunction(){ //body } } And in my app I had something like MyClass classObject;

Re: A nice D coding pattern

2014-11-25 Thread Meta via Digitalmars-d-learn
That's a neat trick, although if preconditions were able to be run at compile time when possible you wouldn't have to resort to using enum to force CTFE (you've talked a bit about this before I remember). Thinking about something like a good ranged number implementation, we can now get almost a

Re: Functional Sort

2014-11-15 Thread Meta via Digitalmars-d-learn
On Saturday, 15 November 2014 at 03:47:25 UTC, Steven Schveighoffer wrote: err... this isn't what you want. That will sort the range, and then make a copy of the sorted range as an array. Yes, I didn't see the the second constraint to not sort the original range. Sort before .array -> origin

Re: Functional Sort

2014-11-14 Thread Meta via Digitalmars-d-learn
On Saturday, 15 November 2014 at 01:01:57 UTC, Nordlöw wrote: On Saturday, 15 November 2014 at 00:47:57 UTC, Meta wrote: `sort` returns a SortedRange, so sort is the function you're looking for. Sorry, and if you want a copy, just add a `.array` on the end to create a new array from the retur

Re: Functional Sort

2014-11-14 Thread Meta via Digitalmars-d-learn
On Saturday, 15 November 2014 at 00:47:41 UTC, Nordlöw wrote: On Saturday, 15 November 2014 at 00:45:11 UTC, Meta wrote: `sort` returns a SortedRange, so sort is the function you're looking for. Do you mean std.algorithm.sort? I want a sort that doesn't mutate its input argument. In that ca

Re: Functional Sort

2014-11-14 Thread Meta via Digitalmars-d-learn
On Saturday, 15 November 2014 at 00:45:11 UTC, Meta wrote: On Saturday, 15 November 2014 at 00:33:11 UTC, Nordlöw wrote: Is there a functional variant of std.algorithm.sort, say sorted, that returns a sorted copy of its input use typically as const y = x.sorted; ? If not any recommendati

Re: Functional Sort

2014-11-14 Thread Meta via Digitalmars-d-learn
On Saturday, 15 November 2014 at 00:33:11 UTC, Nordlöw wrote: Is there a functional variant of std.algorithm.sort, say sorted, that returns a sorted copy of its input use typically as const y = x.sorted; ? If not any recommendations on its implementation? `sort` returns a SortedRange, s

Re: status of D optimizers benefiting from contracts ?

2014-11-09 Thread Meta via Digitalmars-d-learn
On Sunday, 9 November 2014 at 16:31:46 UTC, bearophile wrote: H. S. Teoh: It's only a bad idea because people abuse assert() where it's not appropriate. It's a bad idea because Walter seems unable to understand the difference between verifying and proving. Bye, bearophile On the other ha

Re: How to tell how an object/class is declared

2014-11-06 Thread Meta via Digitalmars-d-learn
One other thing. I know about `template this`, but I'm not sure if that's a tenable solution or not in my case. In addition to templating the struct or class, would I not also have to template the constructor so it could pick up the type of `this` at the declaration site?

How to tell how an object/class is declared

2014-11-06 Thread Meta via Digitalmars-d-learn
Say I have the following struct and object definitions: struct Test1(T) { static if (???) { void doSomething() { writeln(typeof(this).stringof); } } T t; } class Test2(T) { static if (???) { void doSomething() {

Re: Why does this declaration exist inside std.range.put?

2014-11-06 Thread Meta via Digitalmars-d-learn
On Thursday, 6 November 2014 at 21:57:36 UTC, Steven Schveighoffer wrote: github blame is quite useful: https://github.com/D-Programming-Language/phobos/blame/master/std/range.d#L668 The commit: https://github.com/D-Programming-Language/phobos/commit/c717b503e7305a92410c23ca2bc2ea14b40f8aa2

Why does this declaration exist inside std.range.put?

2014-11-06 Thread Meta via Digitalmars-d-learn
This is the code for std.range.put: void put(R, E)(ref R r, E e) { //Why? @property ref E[] EArrayInit(); //@@@9186@@@: Can't use (E[]).init //First level: simply straight up put. static if (is(typeof(doPut(r, e { doPut(r, e); } //Optional optimization b

Re: Struct template

2014-11-04 Thread Meta via Digitalmars-d-learn
On Monday, 3 November 2014 at 17:05:21 UTC, John Colvin wrote: static if (is(typeof(T) == int)) should be static if (is(T == int)) T is already a type. I thought this was supposed to produce an error message rather than fail silently... I'm positive this used to be an error. Did it change

Re: state of the art with Typedef

2014-11-01 Thread Meta via Digitalmars-d-learn
On Saturday, 1 November 2014 at 23:18:35 UTC, John Colvin wrote: Doesn't support "is" keyword. Another good use-case for allowing a user-defined operator for is.

Re: Multiple declarations in a C++ namespace

2014-10-31 Thread Meta via Digitalmars-d-learn
On Friday, 31 October 2014 at 23:22:50 UTC, Paul O'Neil wrote: Thanks for the response. That does work. Should I file a bug report or create a PR for the docs? It might be a good idea to create a thread in DigitalMars.D to get clarification on the intended behaviour. A doc PR never hurts ei

Re: Multiple declarations in a C++ namespace

2014-10-30 Thread Meta via Digitalmars-d-learn
On Friday, 31 October 2014 at 02:01:00 UTC, Paul O'Neil wrote: I'm trying to bind to some C++ code, but when I compile the D side, there are errors. Here's my reduced test case: // C++ namespace ns { void func1(); void func2(); } // D module cpp; extern(C++, ns) void func1(); extern(C++,

Re: String range to dchar.

2014-10-30 Thread Meta via Digitalmars-d-learn
On Friday, 31 October 2014 at 00:17:02 UTC, Samuel Pike wrote: Hi all. First time posting here. I recently downloaded the dmd compiler and started making a few exercises with the language. Nice language features but still somewhat confused with the library. If I use byDchar() over a "string"

Re: Global const variables

2014-10-21 Thread Meta via Digitalmars-d-learn
On Tuesday, 21 October 2014 at 16:56:06 UTC, Solomon E wrote: On Tuesday, 21 October 2014 at 15:51:27 UTC, MachineCode wrote: ... ... pure functions are also supposed to don't use global variables at all, according to functional programming paradigm Pure functions are immutables (constants b

Re: Assignment to "enumerated string", is content copied or array information?

2014-10-18 Thread Meta via Digitalmars-d-learn
On Saturday, 18 October 2014 at 23:51:53 UTC, tcak wrote: enum Values: string{ NONE = "", Value1 = "Apple", Value2 = "Peach", Value3 = "Lemon" } Values lastHeldValue = Value3; Is the "lastHeldValue" just "pointer + length" information, and it points to "Lemon"; or is "Lemon" copied t

Re: Returning multiple arrays from function - struct or byref the only option?

2014-10-18 Thread Meta via Digitalmars-d-learn
On Saturday, 18 October 2014 at 14:56:06 UTC, Meta wrote: The problem is that D does not allow implicit conversions when returning results from a function. "Implicit conversion" is not correct. I meant "implicit contruction".

Re: Returning multiple arrays from function - struct or byref the only option?

2014-10-18 Thread Meta via Digitalmars-d-learn
On Wednesday, 15 October 2014 at 17:56:06 UTC, Ali Çehreli wrote: - Unlike a struct, the members are anonymous. (Yes, tuples members can have names as well but not when returning or creating conveniently by 'return tuple(a, b)'.) This works, but I agree it is a bit obscure (you may want to add

Re: Returning multiple arrays from function - struct or byref the only option?

2014-10-15 Thread Meta via Digitalmars-d-learn
On Wednesday, 15 October 2014 at 16:48:24 UTC, Laeeth Isharc wrote: Hi. I have to write a bunch of functions that operate on input arrays to return multiple output arrays. In case helpful the inputs are price bars or economic data points (datetime, ohlc) and the outputs are nx1 arrays (I won

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Meta via Digitalmars-d-learn
On Sunday, 28 September 2014 at 20:50:07 UTC, Jay wrote: On Sunday, 28 September 2014 at 20:30:42 UTC, Meta wrote: class Button { typeof(this) text(string t) { return this; } typeof(this) textColour(int c) { return

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Meta via Digitalmars-d-learn
On Sunday, 28 September 2014 at 19:11:23 UTC, Jay wrote: i want to chain 'new' with method calls on the created object. i found this on the internet: window.mainWidget = (new Button()).text("Hello world"d).textColor(0xFF); it would look much nicer with UFCS: window.mainWidget = Button.n

Re: isArray and std.container.Array

2014-09-28 Thread Meta via Digitalmars-d-learn
On Sunday, 28 September 2014 at 08:01:00 UTC, Nordlöw wrote: Is there a reason why isArray!T doesn't match T when T is a std.container.Array? I'm asking because after looking into msgpack-d because of http://forum.dlang.org/thread/aclapseyptgcwntda...@forum.dlang.org#post-aclapseyptgcwntdavwt:

Re: Recursive data-types

2014-09-27 Thread Meta via Digitalmars-d-learn
On Saturday, 27 September 2014 at 11:26:33 UTC, ponce wrote: I'm dabbling with Scheme interpreter and ultimately I would need to declare the following types. -- struct Function { Environment env; Atom params; Atom body_; } // An atom is either a string, a double, a sym

"Undefined identifier FILE" when building Druntime

2014-09-25 Thread Meta via Digitalmars-d-learn
This happens with a freshly checked out master. I first build DMD, which completes successfully. However, when I then try to build Druntime, I got the following error messages: src\core\stdc\wchar_.d(32): Error: undefined identifier FILE src\core\stdc\wchar_.d(33): Error: undefined identifier F

Re: with (auto p = new ...)

2014-09-23 Thread Meta via Digitalmars-d-learn
I think this is just a language oversight. It's allowed in if statements, and people have made a good case for allowing it for switch statements. It just hasn't been implemented. I made an attempt one evening to implement it for switch statements, but I'm not at all familiar with DMD, so I put

Re: std.algorithm.reduce on an array of structs

2014-09-11 Thread Meta via Digitalmars-d-learn
On Thursday, 11 September 2014 at 21:28:59 UTC, Colin wrote: Using the "alias x this" solution would work, but my actual struct is not a simple struct, so the comparison isn't exactly (a.x < b.x). You could always override opCmp as well: http://dlang.org/operatoroverloading.html#compare

Re: std.algorithm.reduce on an array of structs

2014-09-11 Thread Meta via Digitalmars-d-learn
On Thursday, 11 September 2014 at 14:49:03 UTC, bearophile wrote: void main() { //... immutable ar2 = [Thing(10), Thing(20), Thing(40)]; ar2.minimum.writeln; } Bye, bearophile Even better: void main { immutable(Thing)[] ar2 = [10, 20, 40]; ar2.minimum.write

Re: Building a string from n chars

2014-09-03 Thread Meta via Digitalmars-d-learn
On Wednesday, 3 September 2014 at 20:20:09 UTC, Meta wrote: On Wednesday, 3 September 2014 at 19:43:26 UTC, Nordlöw wrote: Is there a simpler way to way to s ~= repeat('*', n).array.to!string; if s has to be of type string? Does this work? s ~= "*".replicate(n); Sorry, I should qualify th

Re: Building a string from n chars

2014-09-03 Thread Meta via Digitalmars-d-learn
On Wednesday, 3 September 2014 at 19:43:26 UTC, Nordlöw wrote: Is there a simpler way to way to s ~= repeat('*', n).array.to!string; if s has to be of type string? Does this work? s ~= "*".replicate(n);

Re: Are there any exercises/challenges for D?

2014-08-25 Thread Meta via Digitalmars-d-learn
On Tuesday, 26 August 2014 at 01:57:06 UTC, Meta wrote: Have you heard of Project Euler? https://projecteuler.net/ The problems are mostly mathematical, and once you answer you can compare your solution to the other solutions people have written in other languages. The early questions also hav

Re: Are there any exercises/challenges for D?

2014-08-25 Thread Meta via Digitalmars-d-learn
On Sunday, 24 August 2014 at 23:20:21 UTC, maik klein wrote: On Sunday, 24 August 2014 at 21:51:39 UTC, Weaseldog wrote: On Sunday, 24 August 2014 at 20:32:02 UTC, maik klein wrote: Are there any exercises/challenges for D? Something like this? http://www.haskell.org/haskellwiki/99_questions/

Re: Iterating over the tupleof of a struct

2014-08-23 Thread Meta via Digitalmars-d-learn
On Saturday, 23 August 2014 at 20:34:35 UTC, Ali Çehreli wrote: There are a number of inconsistencies around tuples. The behavior you expect is present for ranges that return tuple fronts: import std.stdio; import std.typecons; import std.range; void main() { auto t = [ tuple(1.5, 100), t

Re: Iterating over the tupleof of a struct

2014-08-23 Thread Meta via Digitalmars-d-learn
On Saturday, 23 August 2014 at 01:56:06 UTC, Dicebot wrote: On Saturday, 23 August 2014 at 01:32:13 UTC, Meta wrote: On Saturday, 23 August 2014 at 01:24:10 UTC, Meta wrote: What is happening here? Are these two extra ulongs the offsets of the fields in the struct? And I just realized that th

Re: Iterating over the tupleof of a struct

2014-08-22 Thread Meta via Digitalmars-d-learn
On Saturday, 23 August 2014 at 01:24:10 UTC, Meta wrote: What is happening here? Are these two extra ulongs the offsets of the fields in the struct? And I just realized that that's obviously not the case. It's just an iteration variable. Problem solved.

Iterating over the tupleof of a struct

2014-08-22 Thread Meta via Digitalmars-d-learn
Something weird happens when I try to foreach over test.tupleof. If the foreach loop has 2 variables like so: struct Test { string name = "'null'"; int id; } void main() { auto test = Test(); assert(test.name == "'null'"); assert(test.id == 0);

Re: Auto attributes for functions

2014-08-19 Thread Meta via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 01:38:53 UTC, uri wrote: Hi all, Bit new to D so this might be a very naive question... Can the compiler auto infer function attributes? I am often adding as many attributes as possible and use the compiler to show me where they're not applicable and take them

Re: drop* and take* only for specific element values

2014-08-13 Thread Meta via Digitalmars-d-learn
On Wednesday, 13 August 2014 at 12:37:34 UTC, Nordlöw wrote: Are there variants of drop* and take* that only drop element if its equal to a value kind of like strip does? If not I believe they should be added. No, but it'd probably be useful. Maybe call them dropIf/takeIf, or just add an ove

Re: implicit conversion

2014-08-12 Thread Meta via Digitalmars-d-learn
On Tuesday, 12 August 2014 at 14:26:46 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: AFAIK, the only time that the implicit conversion would take place is when the type is being used in a situation where it doesn't work directly but where the aliased type is used. In that case, the compil

Re: implicit conversion

2014-08-12 Thread Meta via Digitalmars-d-learn
On Tuesday, 12 August 2014 at 06:37:45 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: The problem is that isNaN is now templatized, and its constraint uses isFloatingPoint, which requires that the type _be_ a floating point type, not that it implicitly convert to one. So, as it stands, isN

Re: tuple slicing operator

2014-08-09 Thread Meta via Digitalmars-d-learn
On Saturday, 9 August 2014 at 20:32:05 UTC, Vlad Levenfeld wrote: Are there any specific cases where they're not? Not that I know of, and it doesn't really make sense for them not to be, but it could happen. If you want to be certain that slicing a type will produce a valid range, you can do

Re: tuple slicing operator

2014-08-09 Thread Meta via Digitalmars-d-learn
On Saturday, 9 August 2014 at 16:39:34 UTC, Vlad Levenfeld wrote: I may be misunderstanding the intended semantics of the [] operator but I've come to interpret x[] to mean "give me x as a range" and this is the meaning I intend when I overload it in my own structs. But - auto z = tuple (1,1

Re: opDispatch compiles fine, but still fails to resolve?

2014-08-08 Thread Meta via Digitalmars-d-learn
On Saturday, 9 August 2014 at 01:20:33 UTC, Vlad Levenfeld wrote: More opDispatch woes. This feature keeps biting me, yet I keep trying to use it. This time I'm trying to access elements of a vector GLSL-style (without swizzling... for now). Here's the relevant code: struct Vector (uint len

Re: alias to fully qualified enum in scope where enum is expected

2014-08-06 Thread Meta via Digitalmars-d-learn
On Wednesday, 6 August 2014 at 07:23:32 UTC, Rikki Cattermole wrote: The magic of with statements! enum A { a1, a2 } void func(A a){} void main(){ func(A.a1); with(A) { func(a1); } } And if you want to be *really* concise: with (A) fun(

Re: fuction Return function

2014-07-26 Thread Meta via Digitalmars-d-learn
On Saturday, 26 July 2014 at 20:49:30 UTC, seany wrote: Can a function return a function in D? Sorry if i missed the answer somewhere Yup, you can return functions, delegates, or function pointers. int function(int) returnsFunc1() { return function(int n) { return n; }; } int function

Re: D JSON (WAT?!)

2014-07-25 Thread Meta via Digitalmars-d-learn
On Saturday, 26 July 2014 at 00:26:08 UTC, Ary Borenszweig wrote: Or use Algebraic, but it currently doesn't support recursive type definitions. Algebraic does support recursive type definitions. import std.variant; alias Rec = Algebraic!(int, This*); void main() { //I'm not sure why thi

Re: SImple C++ code to D

2014-07-17 Thread Meta via Digitalmars-d-learn
On Thursday, 17 July 2014 at 13:40:20 UTC, bearophile wrote: Meta: For `Tuple!(DWORD, DWORD*)[] addrs;`, DWORD* is not same as shared_ptr. It's important to keep that in mind. OK. How do you suggest to translate it in D? Bye, bearophile I don't know. I just wanted to make sure OP knew that

Re: SImple C++ code to D

2014-07-17 Thread Meta via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 16:04:26 UTC, bearophile wrote: Alexandre: map syms; If you don't need the key ordering then use a built-in associative array: Address[string] syms; Otherwise use a RedBlackTree from std.container. vector> values; vector>> addrs; Tuple!(DWORD, Address)[] v

Re: lazy construction of an immutable object

2014-07-16 Thread Meta via Digitalmars-d-learn
On Wednesday, 16 July 2014 at 00:38:46 UTC, Puming wrote: 3. define all classes and use template magic to generate companion builders just like protobuffer does. But that would be complicated and I don't know how to do it. Do you have any suggestion for this approach? This would probably be a

Re: is there a way to pause a program and resume with just a key press (or enter key)

2014-07-15 Thread Meta via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 10:22:52 UTC, rumbu wrote: getch() reads any key and continues; On Windows you can pipe you executable with the "more" command to pause after each page: your.exe | more Don't forget that getch() is also Windows-specific.

<    1   2   3   4   5   >