Re: Feature or bug: print braces

2015-05-15 Thread Ivan Kazmenko via Digitalmars-d-learn
On Thursday, 14 May 2015 at 00:29:06 UTC, Dennis Ritchie wrote: Why doesn't the compiler produces an error? - import std.stdio; void main() { writeln({}); } - http://ideone.com/qTZCAd Somehow reminds me of this lambda:

Re: Linking to Dynamic Library on Mac OS X

2015-05-15 Thread John Colvin via Digitalmars-d-learn
On Friday, 15 May 2015 at 03:33:47 UTC, TJB wrote: I have built a toy dynamic shared library on Mac OS X (in C), and I have verified that it works from C. Now I would like to call it from D. So I have created the following interface file: $ cat hello.di extern (C): void printHelloWorld();

Re: How to simulate a new type

2015-05-15 Thread tired_eyes via Digitalmars-d-learn
On Friday, 15 May 2015 at 06:11:41 UTC, Charles Hixson wrote: On 05/14/2015 06:38 PM, Adam D. Ruppe via Digitalmars-d-learn wrote: On Friday, 15 May 2015 at 01:03:32 UTC, Charles Hixson wrote: Yes, that looks as if it would do the job, but what are its advantages over a simple struct?

Re: What wrong?

2015-05-15 Thread thedeemon via Digitalmars-d-learn
On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote: Simple code: http://pastebin.com/raw.php?i=7jVeMFXQ What I'm doing wrong? Try using class instead of struct. Last time I played with std.concurrency it used Variants to store the messages, so when something bigger than a little

Re: What wrong?

2015-05-15 Thread Gary Willoughby via Digitalmars-d-learn
On Friday, 15 May 2015 at 07:51:29 UTC, thedeemon wrote: On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote: Simple code: http://pastebin.com/raw.php?i=7jVeMFXQ What I'm doing wrong? Try using class instead of struct. Last time I played with std.concurrency it used Variants to

Re: Array of objects and their inheritance

2015-05-15 Thread tired_eyes via Digitalmars-d-learn
Thank you for the explanation

Re: How to simulate a new type

2015-05-15 Thread Charles Hixson via Digitalmars-d-learn
On 05/14/2015 06:38 PM, Adam D. Ruppe via Digitalmars-d-learn wrote: On Friday, 15 May 2015 at 01:03:32 UTC, Charles Hixson wrote: Yes, that looks as if it would do the job, but what are its advantages over a simple struct? None really, except perhaps automatic forwarding of operators which

Destructured Tuple Assignment

2015-05-15 Thread via Digitalmars-d-learn
I recall having seen an example of using some D magic (via mixin perhaps?) to realize tuple destructuring in assignments like magic(first, _, second) = expression.findSplit(separator); somewhere. But I can't seem to find it right now. References anyone? BTW :I'm aware of Kenjis PR, which

Re: Destructured Tuple Assignment

2015-05-15 Thread Artur Skawina via Digitalmars-d-learn
import std.algorithm; template magicassign(A...) { void magicassign(B)(B b) @property { foreach(I, ref a; A) static if (!is(typeof(A[I]):typeof(null))) a = b[I]; } } template let(string D) { mixin({ enum sdsl =

Re: Destructured Tuple Assignment

2015-05-15 Thread via Digitalmars-d-learn
On Friday, 15 May 2015 at 11:04:24 UTC, Per Nordlöw wrote: I'm guessing the closest thing we can get in current D version is something like let(q{first, _, second}, expression.findSplit(separator)); right? Correction: I believe it must look like let!q{first, _,

Re: What wrong?

2015-05-15 Thread Daniel Kozak via Digitalmars-d-learn
On Friday, 15 May 2015 at 09:20:32 UTC, Gary Willoughby wrote: On Friday, 15 May 2015 at 07:51:29 UTC, thedeemon wrote: On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote: Simple code: http://pastebin.com/raw.php?i=7jVeMFXQ What I'm doing wrong? Try using class instead of

Re: Destructured Tuple Assignment

2015-05-15 Thread John Colvin via Digitalmars-d-learn
On Friday, 15 May 2015 at 10:23:24 UTC, Per Nordlöw wrote: I recall having seen an example of using some D magic (via mixin perhaps?) to realize tuple destructuring in assignments like magic(first, _, second) = expression.findSplit(separator); somewhere. But I can't seem to find it right

Re: Destructured Tuple Assignment

2015-05-15 Thread via Digitalmars-d-learn
On Friday, 15 May 2015 at 10:23:24 UTC, Per Nordlöw wrote: I recall having seen an example of using some D magic (via mixin perhaps?) to realize tuple destructuring in assignments like magic(first, _, second) = expression.findSplit(separator); I found it:

SIG11 crashing - can't figure it out

2015-05-15 Thread via Digitalmars-d-learn
Working my way through Ali Çehreli's rather amazing e-book, I've hit a snag where some code I've written is pretty crashy. I consistently get Segmentation fault: 11 (dmd 2.067.1, OSX). I can't figure out where things are going wrong, because any attempt I make to debug via extra print

Re: SIG11 crashing - can't figure it out

2015-05-15 Thread John Colvin via Digitalmars-d-learn
On Friday, 15 May 2015 at 11:08:06 UTC, Rob Pieké wrote: Working my way through Ali Çehreli's rather amazing e-book, I've hit a snag where some code I've written is pretty crashy. I consistently get Segmentation fault: 11 (dmd 2.067.1, OSX). I can't figure out where things are going wrong,

Re: Destructured Tuple Assignment

2015-05-15 Thread via Digitalmars-d-learn
On Friday, 15 May 2015 at 10:46:32 UTC, Per Nordlöw wrote: Can this be solved with a mixin somehow? To clarify, I want to be able to write let(first, _, second) = expression.findSplit(separator); without having to first declare `first`, `_` and `second`. I'm guessing the closest thing

Re: SIG11 crashing - can't figure it out

2015-05-15 Thread John Colvin via Digitalmars-d-learn
On Friday, 15 May 2015 at 11:44:32 UTC, John Colvin wrote: On Friday, 15 May 2015 at 11:08:06 UTC, Rob Pieké wrote: Working my way through Ali Çehreli's rather amazing e-book, I've hit a snag where some code I've written is pretty crashy. I consistently get Segmentation fault: 11 (dmd 2.067.1,

Re: SIG11 crashing - can't figure it out

2015-05-15 Thread via Digitalmars-d-learn
https://issues.dlang.org/show_bug.cgi?id=14587 And confirmed that ldc2 seems to work, thanks again :)

Re: Destructured Tuple Assignment

2015-05-15 Thread via Digitalmars-d-learn
On Friday, 15 May 2015 at 12:22:55 UTC, Artur Skawina wrote: template let(string D) { mixin({ enum sdsl = D.findSplit(=); mixin(`struct S { int `~sdsl[0]~`; }`); string code = `auto v = ` ~ sdsl[2] ~ `;`; foreach (I, _; typeof(S.tupleof))

Re: What wrong?

2015-05-15 Thread anonymous via Digitalmars-d-learn
On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote: Simple code: http://pastebin.com/raw.php?i=7jVeMFXQ This code works compiled by DMD v2.066.1 and LDC2 (0.15.1) based on DMD v2.066.1 and LLVM 3.5.0. $ ./z TUQLUE 42 11 Compiled by DMD v2.067.1 the program crashes: $ ./aa TUQLUE

Re: Destructured Tuple Assignment

2015-05-15 Thread via Digitalmars-d-learn
On Friday, 15 May 2015 at 12:22:55 UTC, Artur Skawina wrote: import std.algorithm; template let(string D) { mixin({ enum sdsl = D.findSplit(=); mixin(`struct S { int `~sdsl[0]~`; }`); string code = `auto v = ` ~ sdsl[2] ~ `;`; foreach (I, _;

Re: problem with parallel foreach

2015-05-15 Thread Gerald Jansen via Digitalmars-d-learn
On Thursday, 14 May 2015 at 17:12:07 UTC, John Colvin wrote: Would it be OK if I showed some parts of this code as examples in my DConf talk in 2 weeks? Sure!!!

Re: Destructured Tuple Assignment

2015-05-15 Thread via Digitalmars-d-learn
On Friday, 15 May 2015 at 13:40:01 UTC, Per Nordlöw wrote: I added support for auto, const and immutable declarations at https://github.com/nordlow/justd/blob/master/ties.d#L96 And support for ignoring `_` as a variable as: import std.algorithm.searching: findSplit; mixin let!q{ c,

Re: SIG11 crashing - can't figure it out

2015-05-15 Thread via Digitalmars-d-learn
Thanks John, I'll log the issue and start brewing ldc. I'm happy that I wasn't doing something obviously stupid with my code (again, in terms of crashing, not design). And also thanks for the with tip! - Rob

Re: Returning an empty range of a given type

2015-05-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/14/15 11:22 PM, rcorre wrote: On Thursday, 14 May 2015 at 18:44:58 UTC, Steven Schveighoffer wrote: It depends on the guts of MyContainer.Range. I'm assuming MyContainer.Range has SOME sort of references (i.e. pointers) to the data in the container, so why not just have: bool empty() {

Re: SIG11 crashing - can't figure it out

2015-05-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/15/15 7:08 AM, Rob =?UTF-8?B?UGlla8OpIg==?= robpi...@gmail.com wrote: Working my way through Ali Çehreli's rather amazing e-book, I've hit a snag where some code I've written is pretty crashy. I consistently get Segmentation fault: 11 (dmd 2.067.1, OSX). Using dustmite (and 2.067.0), I

'const' and 'in' parameter storage classes

2015-05-15 Thread ref2401 via Digitalmars-d-learn
What is the difference between 'const' and 'in' parameter storage classes? When should I use 'const' or 'in'? The documentation says 'in' is the same as 'const scope' but I can't write 'const scope ref' though it's legal to write 'in ref'. Thank you

Re: 'const' and 'in' parameter storage classes

2015-05-15 Thread Adam D. Ruppe via Digitalmars-d-learn
The scope storage class means you promise not to escape any reference to the data. This isn't enforced but it is similar in concept to Rust's borrowed pointers - it may someday be implemented to be an error to store them in an outside variable. Only use 'in' if you are looking at the data,

Re: UFCS

2015-05-15 Thread Timon Gehr via Digitalmars-d-learn
On 05/15/2015 11:31 PM, Manfred Nowak wrote: class C{} int main(){ void opOpAssign( string op)( C a, C b){ } C a, b; a+= b; } https://issues.dlang.org/show_bug.cgi?id=8062

Re: functors with template lambdas

2015-05-15 Thread weaselcat via Digitalmars-d-learn
On Saturday, 16 May 2015 at 02:06:45 UTC, weaselcat wrote: very long standing compiler bug https://issues.dlang.org/show_bug.cgi?id=3051 see also https://issues.dlang.org/show_bug.cgi?id=5710 unsure if they're duplicate bugs, never really looked into it.

Re: functors with template lambdas

2015-05-15 Thread weaselcat via Digitalmars-d-learn
On Saturday, 16 May 2015 at 02:04:39 UTC, Vlad Levenfeld wrote: I think this code should be allowed, but it isn't: struct Functor (T) { T a; auto ref fmap (alias f)() { return Functor (f(a));

Re: functors with template lambdas

2015-05-15 Thread Vlad Levenfeld via Digitalmars-d-learn
On Saturday, 16 May 2015 at 02:08:09 UTC, weaselcat wrote: On Saturday, 16 May 2015 at 02:06:45 UTC, weaselcat wrote: very long standing compiler bug https://issues.dlang.org/show_bug.cgi?id=3051 see also https://issues.dlang.org/show_bug.cgi?id=5710 unsure if they're duplicate bugs, never

functors with template lambdas

2015-05-15 Thread Vlad Levenfeld via Digitalmars-d-learn
I think this code should be allowed, but it isn't: struct Functor (T) { T a; auto ref fmap (alias f)() { return Functor (f(a)); } } auto ref identity (T)(auto ref T a)

Re: UFCS

2015-05-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, May 15, 2015 21:31:35 Manfred Nowak via Digitalmars-d-learn wrote: The following gives: Error: 'a += b' is not a scalar, it is a C although UFCS should engage. -manfred class C{} int main(){ void opOpAssign( string op)( C a, C b){ } C a, b; a+= b; } Overloaded

Re: Linking to Dynamic Library on Mac OS X

2015-05-15 Thread TJB via Digitalmars-d-learn
Off the top of my head: does adding -L-L$(pwd) help? This is what I get: $ dmd main.d -L-L$(pwd) -lhello Error: unrecognized switch '-lhello' Sorry if this is completely elementary and I am being quite dumb. Thanks, TJB

Re: Linking to Dynamic Library on Mac OS X

2015-05-15 Thread John Colvin via Digitalmars-d-learn
On Friday, 15 May 2015 at 19:39:53 UTC, TJB wrote: Off the top of my head: does adding -L-L$(pwd) help? This is what I get: $ dmd main.d -L-L$(pwd) -lhello Error: unrecognized switch '-lhello' Sorry if this is completely elementary and I am being quite dumb. Thanks, TJB should be $ dmd

Re: CTFE enums static assert

2015-05-15 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-05-04 18:22:17 +, Ali Çehreli said: There are many different kinds of tuples in D, only two of which I can handle: 1) Tuple from std.typecons, which are ordinarily created at run time 2) TypeTuple from std.typetuple, which are compile-time entities The documentation is not clear

Deprecation

2015-05-15 Thread Manfred Nowak via Digitalmars-d-learn
Deprecation: super is not an lvalue 1) How to know when this will indeed be deprecated? 2) What does it mean, when `super++' is signalled as depracation, but `super+=' is not signalled? -manfred

Re: Deprecation

2015-05-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/15/15 12:50 PM, Manfred Nowak wrote: Deprecation: super is not an lvalue 1) How to know when this will indeed be deprecated? 2) What does it mean, when `super++' is signalled as depracation, but `super+=' is not signalled? That seems like a bug. I think super being an lvalue in this

Re: 'const' and 'in' parameter storage classes

2015-05-15 Thread ref2401 via Digitalmars-d-learn
On Friday, 15 May 2015 at 16:30:29 UTC, Steven Schveighoffer wrote: On 5/15/15 12:04 PM, ref2401 wrote: What is the difference between 'const' and 'in' parameter storage classes? When should I use 'const' or 'in'? The documentation says 'in' is the same as 'const scope' but I can't write

Re: 'const' and 'in' parameter storage classes

2015-05-15 Thread ref2401 via Digitalmars-d-learn
On Friday, 15 May 2015 at 16:08:31 UTC, Adam D. Ruppe wrote: The scope storage class means you promise not to escape any reference to the data. This isn't enforced but it is similar in concept to Rust's borrowed pointers - it may someday be implemented to be an error to store them in an

Re: Clean way to tell whether a destructor is called by the GC

2015-05-15 Thread Kagamin via Digitalmars-d-learn
On Thursday, 14 May 2015 at 17:25:55 UTC, ponce wrote: But then we would need a standardized name (some use close, some use dispose, some use release) In .net the standardized name is dispose and IDisposable interface having the method:

Re: Deprecation

2015-05-15 Thread Manfred Nowak via Digitalmars-d-learn
Steven Schveighoffer wrote: That seems like a bug. https://issues.dlang.org/show_bug.cgi?id=14589 -manfred

Re: Feature or bug: print braces

2015-05-15 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 15 May 2015 at 08:44:41 UTC, Ivan Kazmenko wrote: Somehow reminds me of this lambda: https://github.com/Hackerpilot/Idiotmatic-D/blob/master/idiotmatic.d#L127-L128 Maybe it generally blocks for initialization of variables:

Re: SysTime object from unixtime

2015-05-15 Thread dat via Digitalmars-d-learn
thanks, that did the trick!

Re: Dynamic / resizable array type, and a crash problem

2015-05-15 Thread anonymous via Digitalmars-d-learn
On Thursday, 14 May 2015 at 20:50:05 UTC, ivoras wrote: I'm experimenting to get a feel for the language. Do you have a suggestion about this example code: https://goo.gl/F7LCAg to make it more D-like, idiomatic? Quoting from the code: for (int i = 0; i count; i++) { foreach(i; 0 ..

Re: 'const' and 'in' parameter storage classes

2015-05-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 15 May 2015 at 18:18:13 UTC, ref2401 wrote: globalPtr = ms; // is it legal? No, but the compiler check isn't implemented.

Re: 'const' and 'in' parameter storage classes

2015-05-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/15/15 12:04 PM, ref2401 wrote: What is the difference between 'const' and 'in' parameter storage classes? When should I use 'const' or 'in'? The documentation says 'in' is the same as 'const scope' but I can't write 'const scope ref' though it's legal to write 'in ref'. scope ref const

Re: CTFE enums static assert

2015-05-15 Thread Ali Çehreli via Digitalmars-d-learn
On 05/15/2015 09:45 AM, Robert M. Münch wrote: On 2015-05-04 18:22:17 +, Ali Çehreli said: TypeTuple is great because it enables compile-time foreach (unfortunately, implicitly): foreach (m; __traits(allMembers, A)) { // This body is repeated for each member at compile

Re: Clean way to tell whether a destructor is called by the GC

2015-05-15 Thread Kagamin via Digitalmars-d-learn
Another idiom from .net is Dispose(bool) method, called with argument true from Dispose and with argument false from finalizer. https://msdn.microsoft.com/en-us/library/d9yzd5cx.aspx

UFCS

2015-05-15 Thread Manfred Nowak via Digitalmars-d-learn
The following gives: Error: 'a += b' is not a scalar, it is a C although UFCS should engage. -manfred class C{} int main(){ void opOpAssign( string op)( C a, C b){ } C a, b; a+= b; }