Re: Const Tuples

2014-04-25 Thread Meta via Digitalmars-d-learn
On Friday, 25 April 2014 at 11:51:48 UTC, bearophile wrote: They are not the same type: void main() { import std.typecons: Tuple; alias T1 = const Tuple!(int, int); alias T2 = Tuple!(const int, const int); static assert(is(T1 == T2)); // Fails. } This type difference causes

Creating a List Type Using std.variant.algebraic

2014-04-27 Thread Meta via Digitalmars-d-learn
I'm trying to create a basic List type using Algebraic, but the compiler keeps complaining about recursive aliasing. import std.variant; struct Cons(T, U: List) { public static opCall(T t, U u) { } } //Error alias List = Algebraic!(typeof(null), Cons!(int, This));

Re: Creating a List Type Using std.variant.algebraic

2014-04-27 Thread Meta via Digitalmars-d-learn
On Sunday, 27 April 2014 at 20:22:12 UTC, bearophile wrote: Meta: I'm trying to create a basic List type using Algebraic, but the compiler keeps complaining about recursive aliasing. As stated in its docs, Algebraic is not yet finished and good for recursive data structures. But here I have

Re: Creating a List Type Using std.variant.algebraic

2014-04-27 Thread Meta via Digitalmars-d-learn
On Sunday, 27 April 2014 at 20:38:37 UTC, Meta wrote: Is it necessary to use This[]? I tried changing it to This* and it blew up on me. I should specify. This did not work: alias T = Algebraic!(int, This*); void main() { auto l = T(1, new T(2, new T(3, null))); }

Re: Creating a List Type Using std.variant.algebraic

2014-04-27 Thread Meta via Digitalmars-d-learn
On Sunday, 27 April 2014 at 20:28:28 UTC, bearophile wrote: Meta: alias List = Algebraic!(typeof(null), Cons!(int, This)); Also your Cons seems a value type, like Algebraic itself. You have to avoid creating an infinite-size algebraic value. Bye, bearophile Yes, it's hard to figure out

Re: Creating a List Type Using std.variant.algebraic

2014-04-27 Thread Meta via Digitalmars-d-learn
On Sunday, 27 April 2014 at 20:54:02 UTC, bearophile wrote: An Algebraic is a sum type, so you can't store two value in it, only one, an int or a T*. But this is not going to solve your problems... Bye, bearophile Ah, you're right. I'm getting mixed up from my own initial example. Fiddling

Re: Is this a bug?

2014-04-29 Thread Meta via Digitalmars-d-learn
On Tuesday, 29 April 2014 at 16:52:27 UTC, Ali Çehreli wrote: That may be misleading because there is no need to allocate with an explicit new. For example, the slice below is owned by the GC as well: int[] foo() { int[] a; a ~= 42;// on memory owned by the GC return a; } I

Re: Making enum join variadic

2014-05-02 Thread Meta via Digitalmars-d-learn
On Friday, 2 May 2014 at 13:38:39 UTC, Nordlöw wrote: enums.d(25,46): Error: static variable allMembers cannot be read at compile time enums.d(25,21):while evaluating: static assert(a in allMembers) Is there a solution to this problem? Associative arrays are not CTFE-able.

Re: Making enum join variadic

2014-05-02 Thread Meta via Digitalmars-d-learn
On Friday, 2 May 2014 at 15:18:06 UTC, Artur Skawina via Digitalmars-d-learn wrote: On 05/02/14 15:38, Nordlöw via Digitalmars-d-learn wrote: template MemberNamesUnion(E...) if (allSatisfy!(isEnum, E)) { bool[string] allMembers; // used to detect member collisions mixin({

Re: const ref parameters and r-value references

2014-05-02 Thread Meta via Digitalmars-d-learn
On Friday, 2 May 2014 at 21:29:51 UTC, Mark Isaacson wrote: Auto ref parameters seem to be just what I need. Thanks! I'd still be curious if anyone has additional information regarding the rationale at play (I'm spoiled, reading TDPL and having each decision explained in text). The C++ way

Re: Math-Parser

2014-05-04 Thread Meta via Digitalmars-d-learn
You could replace all those `op=='+'||op=='-'? ...` with `op.among!('+', '-')? ...`.

Re: Need help with movement from C to D

2014-05-05 Thread Meta via Digitalmars-d-learn
On Monday, 5 May 2014 at 04:05:35 UTC, Mark Isaacson wrote: Something like: unittest { enum offsetof(string type, string field) = mixin(type ~ . ~ field ~ .offsetof); struct StrToBob { string str; int bob; } writeln(offsetof!(StrToBob, bob)); } ? If not that then I'm not

Re: [Rosettacode] D code line length limit

2014-05-07 Thread Meta via Digitalmars-d-learn
On Wednesday, 7 May 2014 at 13:25:55 UTC, bearophile wrote: So far in Rosettacode D entries I've kept a line length limit of 72 or 73 chars. But now a little larger monitors are common, D UFCS chains are common, and we also have longer function signatures with pure nothrow @safe @nogc (that

Re: [Rosettacode] D code line length limit

2014-05-07 Thread Meta via Digitalmars-d-learn
On Wednesday, 7 May 2014 at 18:51:59 UTC, Meta wrote: On Wednesday, 7 May 2014 at 14:40:37 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: My eyes... Oh, how that hurts readibily. While I agree that pure @safe @nogc nothrow void doSomething(int n) { } is quite ugly, it is really not

Re: Down the VisualD0.3.38-1.exe ,found virus!

2014-05-08 Thread Meta via Digitalmars-d-learn
On Friday, 9 May 2014 at 01:02:39 UTC, FrankLike wrote: Hi,everyone, down VisulaD from http://rainers.github.io/visuald/visuald/StartPage.html found the virus:Win32.Troj.Undef.(kcloud) Why? Frank I've been using VisualD for a long time without problems. If it makes you nervous, you can

Re: Down the VisualD0.3.38-1.exe ,found virus!

2014-05-10 Thread Meta via Digitalmars-d-learn
On Saturday, 10 May 2014 at 08:42:14 UTC, FrankLike wrote: I've been using VisualD for a long time without problems. If it makes you nervous, you can get the source from Github and compile it yourself. Hello,Meta When I compile the Visual D projects: at first,I compile the 'build'

Re: Inspecting lambda parameters

2014-05-10 Thread Meta via Digitalmars-d-learn
On Saturday, 10 May 2014 at 10:56:57 UTC, Jacob Carlborg wrote: I know that there are templates to inspect function parameters, like ParameterIdentifierTuple and ParameterTypeTuple. But these don't work for templated/untyped lambdas, they're apparently not callables. I don't expect

Re: Array!T and find are slow

2014-05-14 Thread Meta via Digitalmars-d-learn
On Wednesday, 14 May 2014 at 22:32:01 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: Yeah, much as Andrei would hate to hear it (enforce was his idea, and he quite likes the idiom), the fact that lazy is so inefficient makes it so that it's arguably bad practice to use it in high

Re: randomSample

2014-05-17 Thread Meta via Digitalmars-d-learn
On Sunday, 18 May 2014 at 04:19:05 UTC, David Held wrote: How do I get an array from randomSample()? int[] source = [ ... ]; int[] sample = randomSample(source, 3); src\main.d(30): Error: cannot implicitly convert expression (randomSample(source, 3u)) of type RandomSample!(int[], void) to

Re: Bounds check

2014-05-23 Thread Meta via Digitalmars-d-learn
On Friday, 23 May 2014 at 15:14:47 UTC, Chris wrote: The following: import std.stdio; void main() { int[5] arg; arg[10] = 3; // Compiler says (of course): Error: array index 10 is out of bounds arg[0 .. 5] } import std.stdio; void main() { int[5] arg; foreach (i;

Examining Members of a module at Compile Time

2014-05-29 Thread Meta via Digitalmars-d-learn
I'd like to get a list of all classes in the current module, so I came up with this code: class Test {} class TestChild: Test {} class TestChildChild: TestChild {} void main() { foreach (item; __traits(allMembers, mixin(__MODULE__))) { static if

Re: Examining Members of a module at Compile Time

2014-05-29 Thread Meta via Digitalmars-d-learn
On Thursday, 29 May 2014 at 23:18:32 UTC, Dicebot wrote: class Test {} class TestChild: Test {} class TestChildChild: TestChild {} alias Alias(alias Symbol) = Symbol; // this does the trick void main() { foreach (item; __traits(allMembers, mixin(__MODULE__))) { alias sym =

Re: How to assign a delegate to a var ?

2014-06-02 Thread Meta via Digitalmars-d-learn
On Monday, 2 June 2014 at 22:18:39 UTC, bioinfornatics wrote: Hi, I would like store the delegate to another var but when i try i get: testTraitsWithDelegate.d(13): Error: expression template __lambda2 is void and has no value I do not want to run it only to save the «function» somewhere.

Re: alias with lambda syntax: alias fun2=a=fun(a);

2014-06-05 Thread Meta via Digitalmars-d-learn
On Thursday, 5 June 2014 at 07:19:07 UTC, timotheecour wrote: ok I remembered we can use std.typetuple.Alias for that. Or std.functional.unaryFun.

Re: Create const regex?

2014-06-06 Thread Meta via Digitalmars-d-learn
On Friday, 6 June 2014 at 14:25:26 UTC, hane wrote: On Friday, 6 June 2014 at 12:01:55 UTC, AntonSotov wrote: const r1 = regex(bla); matchFirst( big string, r1 ); // ERROR! immutable r2 = regex(bla); // ERROR! Why can I not use const/immutable regex? I think it's a Phobos bug that can't

Re: Create const regex?

2014-06-07 Thread Meta via Digitalmars-d-learn
On Saturday, 7 June 2014 at 00:48:59 UTC, hane wrote: On Friday, 6 June 2014 at 15:42:41 UTC, Meta wrote: You should not do this, as it will create a new regex everywhere you use it. Unlike const or immutable, enum in this situation is more or less like a C macro. #define r1 regex(bla) I

Re: Create const regex?

2014-06-07 Thread Meta via Digitalmars-d-learn
On Saturday, 7 June 2014 at 16:15:47 UTC, hane wrote: At std.regex. BTW, I found that immutable regex can be created with enum. enum r1_ = regex(bla); immutable r1 = r1_; Regex struct created during compiling can be immutable? In this case, it must be using enum to force CTFE. As for

Universal Construction Syntax for Pointers?

2014-06-13 Thread Meta via Digitalmars-d-learn
I thought this was possible, but DMD 2.065 doesn't allow it, saying no constructor for int: int* p = new int(3); Is something like this planned for the future? I know we can already do: int n = int(3);

Re: Universal Construction Syntax for Pointers?

2014-06-14 Thread Meta via Digitalmars-d-learn
On Saturday, 14 June 2014 at 06:39:56 UTC, Ali Çehreli wrote: On 06/13/2014 10:29 PM, Meta wrote: I thought this was possible, but DMD 2.065 doesn't allow it, saying no constructor for int: int* p = new int(3); Is something like this planned for the future? I know we can already do: int n

Re: Momentary Eh?! for a Dynamic Language Programmmer. Tuples vs Arrays. Just rambling.

2014-06-23 Thread Meta via Digitalmars-d-learn
On Monday, 23 June 2014 at 22:11:57 UTC, John Carter wrote: On Monday, 23 June 2014 at 21:49:29 UTC, Ary Borenszweig wrote: Union types are very common (I use them every day), and IMHO it's very nice to have them included in the language (either built-in or as a library solution). As a

Re: Why does this work?

2014-06-24 Thread Meta via Digitalmars-d-learn
On Tuesday, 24 June 2014 at 10:11:05 UTC, bearophile wrote: I don't think it's solved. There are probably bugs worth reporting here. I have not found them, sorry for the noise. Bye, bearophile This looks really bad. I thought we weren't going to allow variable templates, just enums and

Re: Assosiative array pop

2014-06-25 Thread Meta via Digitalmars-d-learn
On Wednesday, 25 June 2014 at 09:30:54 UTC, seany wrote: Given an assosiative array : int[string] k, is there a way (either phobos or tango) to pop the first element of this array and append it to another array? I can come up with a primitive soluiton: int[string] k; // populate k here

Re: expose class declared in unittest

2014-06-25 Thread Meta via Digitalmars-d-learn
On Wednesday, 25 June 2014 at 20:17:35 UTC, rcor wrote: I'm trying to create a set of utility functions that cache objects of various types loaded from json files, but having trouble testing it. One function I'd like to test uses new to instantiate an object based on a compile-time parameter:

Re: Assosiative array pop

2014-06-26 Thread Meta via Digitalmars-d-learn
On Thursday, 26 June 2014 at 09:21:28 UTC, seany wrote: On Wednesday, 25 June 2014 at 14:17:50 UTC, Meta wrote: If you want something like a hash table that preserves insertion order, you could try using an array of tuples instead. Then to pop the first element, just do 'arr = arr[1..$]'.

Re: Using attributes inside template instantiation

2014-06-26 Thread Meta via Digitalmars-d-learn
On Thursday, 26 June 2014 at 07:11:03 UTC, Uranuz wrote: But if I write @(hello) struct Hello {} so all of the variables that have type Hello will have attribute @(hello) like come type qualifier because attribute is a part of declaration of Hello. Do I understand correctly? No, it is only

Re: Ranges containers : is it possible to get a SortedRange from a RedBlackTree ?

2014-07-07 Thread Meta via Digitalmars-d-learn
On Monday, 7 July 2014 at 12:06:21 UTC, Frédérik wrote: Hi all, I'm discovering the D language that seems very nice in many aspects, but I'm quite confused by the container and range APIs while trying to design a very simple interface-oriented API. Especially I can't figure out how

Re: [dmd 2.066-b1] std.range.array with shared objects and AA rehash

2014-07-07 Thread Meta via Digitalmars-d-learn
On Monday, 7 July 2014 at 09:53:22 UTC, NCrashed wrote: I am using ranges (wrapped in InputRangeObject for use in interfaces) of shared objects, with new beta some cases are broken: ``` import std.range; class A {} InputRange!(shared A) foo() { return [new A].inputRangeObject; }

Re: Ranges containers : is it possible to get a SortedRange from a RedBlackTree ?

2014-07-07 Thread Meta via Digitalmars-d-learn
On Monday, 7 July 2014 at 19:20:24 UTC, Fr wrote: It's in the example above : SortedRange!(MyObject[]) opSlice() { sequence[].array.assumeSorted; } I thought that that using .array would lead to instantiating something. Yes, this *will* instantiate an array and copy all of the items from

Re: [dmd 2.066-b1] std.range.array with shared objects and AA rehash

2014-07-08 Thread Meta via Digitalmars-d-learn
On Tuesday, 8 July 2014 at 12:42:44 UTC, NCrashed wrote: Oops, I forgot shared at new. But the major issue is that doesn't fix the problem: ``` import std.range; class A {} InputRange!(shared A) foo() { return [new shared A].inputRangeObject; } void bar() { auto res =

Re: Tuple and tie?

2014-07-08 Thread Meta via Digitalmars-d-learn
On Tuesday, 8 July 2014 at 17:42:00 UTC, Remo wrote: How to make something that work like std::tie in D2 ? Tuple!(float, float) sinCos(float n) { return tuple(cast(float)sin(n), cast(float)cos(n)); //please note cast(float)! } int main(string[] argv) { float s,c; tie!(s,c) =

Re: Tuple and tie?

2014-07-08 Thread Meta via Digitalmars-d-learn
On Tuesday, 8 July 2014 at 18:45:21 UTC, Remo wrote: On Tuesday, 8 July 2014 at 18:29:40 UTC, Meta wrote: On Tuesday, 8 July 2014 at 17:42:00 UTC, Remo wrote: How to make something that work like std::tie in D2 ? Tuple!(float, float) sinCos(float n) { return tuple(cast(float)sin(n),

Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-09 Thread Meta via Digitalmars-d-learn
On Monday, 7 July 2014 at 23:47:26 UTC, Aerolite wrote: Hey all, I've not posted here in a while, but I've been keeping up to speed with D's progress over the last couple of years and remain consistently impressed with the language. I'm part of a new computing society in the University of

Re: std.algorithm.among

2014-07-13 Thread Meta via Digitalmars-d-learn
On Sunday, 13 July 2014 at 11:18:05 UTC, bearophile wrote: The idea of not making std.algorithm.among!() a predicate was not so good: void main() { import std.stdio, std.algorithm; auto s = hello how\nare you; s.until!(c = c.among!('\n', '\r')).writeln; } (A normal workaround is

Re: std.algorithm.among

2014-07-13 Thread Meta via Digitalmars-d-learn
On Sunday, 13 July 2014 at 19:06:29 UTC, Timon Gehr wrote: On 07/13/2014 08:51 PM, Meta wrote: That's weird, I always assumed this worked. Was it always the case that numeric types can't be implicitly casted to bool? Yes, unless their range fits into [0,2). It seems that not even that is

Re: lazy construction of an immutable object

2014-07-15 Thread Meta via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 15:48:10 UTC, Puming wrote: wow, that's interesting :-) Is it the idiomatic approach to initiate immutable objects lazily? Or do people use data class with immutable fields and generate a companion builder class at compile time? There's no real idiomatic approach,

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.

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: mapstring, Address 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. vectorpairDWORD, Address values;

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_ptrDWORD. 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

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

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

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)

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

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

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: 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,

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

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

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

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: 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.

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

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),

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?

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

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: 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

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];

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: 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

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

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

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

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 worldd).textColor(0xFF); it would look much nicer with UFCS: window.mainWidget =

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: 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

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

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 to another place

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

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: 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();

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

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: 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

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

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

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: 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?

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

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,

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

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

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

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 -

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

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: 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: 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

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: 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: 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

  1   2   3   4   5   >