Re: Map one tuple to another Tuple of different type

2014-07-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 22, 2014 at 02:47:51AM +, Vlad Levenfeld via Digitalmars-d-learn wrote: > On Monday, 21 July 2014 at 19:02:59 UTC, H. S. Teoh via Digitalmars-d-learn > wrote: > >functionality is desirable. Maybe we should rouse a racket on the > >main D forum to either make staticIota public, or i

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread Vlad Levenfeld via Digitalmars-d-learn
On Monday, 21 July 2014 at 19:02:59 UTC, H. S. Teoh via Digitalmars-d-learn wrote: functionality is desirable. Maybe we should rouse a racket on the main D forum to either make staticIota public, or implement static foreach. ;-) static switch would be so sick. I frequently find myself doing s

Re: Code spliting in module and packages

2014-07-21 Thread Dicebot via Digitalmars-d-learn
On Monday, 21 July 2014 at 18:02:33 UTC, bearophile wrote: Dicebot: Probably most idiomatic D way is to use files _instead_ of classes :) It is a bit idealistic though and is not yet 100% feasible in practice. What's stopping it from being feasible? Bye, bearophile Stuff like this : http

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread John Colvin via Digitalmars-d-learn
On Monday, 21 July 2014 at 18:10:14 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Mon, Jul 21, 2014 at 12:55:34AM +0200, Daniel Gibson via Digitalmars-d-learn wrote: Hi, I have a variadic templated function and want to call a C varargs function. I want to be able to pass static arrays, whic

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 21, 2014 at 06:48:45PM +, bearophile via Digitalmars-d-learn wrote: > H. S. Teoh: > > >It's already in std.typecons. > > But it is not online yet? [...] Hmph. Apparently it is undocumented. :-/ It has been in Phobos since last April, but was private until November when it becam

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread Daniel Gibson via Digitalmars-d-learn
Am 21.07.2014 20:09, schrieb H. S. Teoh via Digitalmars-d-learn: On Mon, Jul 21, 2014 at 06:36:04PM +0200, Daniel Gibson via Digitalmars-d-learn wrote: [...] However, having something like staticIota in the stdlib would probably make sense. [...] It's already in std.typecons. (Admittedly, th

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread bearophile via Digitalmars-d-learn
H. S. Teoh: It's already in std.typecons. But it is not online yet? Bye, bearophile

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 21, 2014 at 06:36:04PM +0200, Daniel Gibson via Digitalmars-d-learn wrote: [...] > However, having something like staticIota in the stdlib would probably > make sense. [...] It's already in std.typecons. (Admittedly, that's not exactly the most obvious place to look for it...) T -

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 21, 2014 at 12:55:34AM +0200, Daniel Gibson via Digitalmars-d-learn wrote: > Hi, > I have a variadic templated function and want to call a C varargs function. > I want to be able to pass static arrays, which D2 passes by value and C by > reference, so I'd like to automagically translat

Re: Code spliting in module and packages

2014-07-21 Thread bearophile via Digitalmars-d-learn
Dicebot: Probably most idiomatic D way is to use files _instead_ of classes :) It is a bit idealistic though and is not yet 100% feasible in practice. What's stopping it from being feasible? Bye, bearophile

Re: Code spliting in module and packages

2014-07-21 Thread Matthieu via Digitalmars-d-learn
Hi, Thanks for your answers. I'll continue to code as I ussed to do, and try to improve my style to have a better usage of the modules (today i'm most one class per file, so I don't use the modules at all). Bye, Matthieu

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread Daniel Gibson via Digitalmars-d-learn
Am 21.07.2014 17:04, schrieb TheFlyingFiddle: On Monday, 21 July 2014 at 01:42:58 UTC, Daniel Gibson wrote: Am 21.07.2014 03:34, schrieb Vlad Levenfeld: To get a foreach to run at compile-time, you have to give it something whose value is known to the compiler (so, T and typeof(argTuple) would

Re: Code spliting in module and packages

2014-07-21 Thread Dicebot via Digitalmars-d-learn
Probably most idiomatic D way is to use files _instead_ of classes :) It is a bit idealistic though and is not yet 100% feasible in practice.

Re: Code spliting in module and packages

2014-07-21 Thread bearophile via Digitalmars-d-learn
Matthieu: Thanks for your answers. I'll continue to code as I ussed to do, and try to improve my style to have a better usage of the modules (today i'm most one class per file, so I don't use the modules at all). Also, try to use less classes and more free (pure) functions :-) This means a

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread TheFlyingFiddle via Digitalmars-d-learn
On Monday, 21 July 2014 at 01:42:58 UTC, Daniel Gibson wrote: Am 21.07.2014 03:34, schrieb Vlad Levenfeld: To get a foreach to run at compile-time, you have to give it something whose value is known to the compiler (so, T and typeof(argTuple) would suffice, and 0..T.length really should as wel

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread TheFlyingFiddle via Digitalmars-d-learn
On Monday, 21 July 2014 at 15:04:14 UTC, TheFlyingFiddle wrote: //Outputs 1 to 10 at compile-time. Edit: 0 to 9

Re: Really nooB question - @property

2014-07-21 Thread Danyal Zia via Digitalmars-d-learn
On Sunday, 20 July 2014 at 16:35:52 UTC, Eric wrote: There are a lot of discussions in the forums about how @property should or could be implemented. But I can't seem to find anything that explains why or when I should use @property with the current compiler. Can anyone explain why and when I

Re: Really nooB question - @property

2014-07-21 Thread Kagamin via Digitalmars-d-learn
On Sunday, 20 July 2014 at 18:14:29 UTC, Eric wrote: Use @property when you want a pseudo-variable or something that might be conceptually considered a "property" of the object, i.e. to do this: auto blah = thing.someProperty; thing.someProperty = blahblah; This is basically what I suspec

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread TheFlyingFiddle via Digitalmars-d-learn
On Monday, 21 July 2014 at 15:04:14 UTC, TheFlyingFiddle wrote: template staticIota(size_t s, size_t e, size_t step = 1) { import std.typetuple : TypeTuple; static if(s < e) alias staticIota = TypeTuple!(s, staticIota!(s + step, e, step)); else alias staticIota = TypeTuple!

Re: Really nooB question - @property

2014-07-21 Thread John Colvin via Digitalmars-d-learn
On Sunday, 20 July 2014 at 18:14:29 UTC, Eric wrote: Use @property when you want a pseudo-variable or something that might be conceptually considered a "property" of the object, i.e. to do this: auto blah = thing.someProperty; thing.someProperty = blahblah; This is basically what I suspec

Re: mixin assembler does not work?

2014-07-21 Thread Foo via Digitalmars-d-learn
On Sunday, 20 July 2014 at 17:50:10 UTC, Nicolas Sicard wrote: On Sunday, 20 July 2014 at 15:02:58 UTC, Foo wrote: On Sunday, 20 July 2014 at 14:55:00 UTC, Foo wrote: For clarification: how would that work without mixin + string? I tried this: mixin template Vala2(uint count, alias arr) {

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread Daniel Gibson via Digitalmars-d-learn
Am 21.07.2014 03:05, schrieb Vlad Levenfeld: Thats real weird that it would reject your "i" variable, given that T.length is known at compile time. I think this is a bug. I can get your code to compile if I change your foreach loop to this: foreach(i, U; T) modTuple[i] = transTupleElem(argTu

Re: Really nooB question - @property

2014-07-21 Thread Mike Parker via Digitalmars-d-learn
On 7/21/2014 3:14 AM, Eric wrote: Use @property when you want a pseudo-variable or something that might be conceptually considered a "property" of the object, i.e. to do this: auto blah = thing.someProperty; thing.someProperty = blahblah; This is basically what I suspected. But why write:

Re: Code spliting in module and packages

2014-07-21 Thread Mike Parker via Digitalmars-d-learn
On 7/21/2014 7:13 AM, Matthieu wrote: Hi! I can't find any good tutorial about how to split my source code in modules and packages. I don't want to use a Java splitting style (one class per file) or something like that, I want to use the D way, but it's so hard to find it! Can someone explain to

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread Daniel Gibson via Digitalmars-d-learn
Am 21.07.2014 03:34, schrieb Vlad Levenfeld: You're very welcome. The reason foreach(int i, x; argTuple) failed is because argTuple is a value (of type T), and so known only at run-time. Hmm but the only thing the compiler would need to know at compile-time is still i, which only depends on a

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread Vlad Levenfeld via Digitalmars-d-learn
On Monday, 21 July 2014 at 01:29:40 UTC, Daniel Gibson wrote: Am 21.07.2014 03:05, schrieb Vlad Levenfeld: Thats real weird that it would reject your "i" variable, given that T.length is known at compile time. I think this is a bug. I can get your code to compile if I change your foreach loop

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread Vlad Levenfeld via Digitalmars-d-learn
Thats real weird that it would reject your "i" variable, given that T.length is known at compile time. I think this is a bug. I can get your code to compile if I change your foreach loop to this: foreach(i, U; T) modTuple[i] = transTupleElem(argTuple[i]); // ok

Re: Compile-Time Interfaces (Concepts)

2014-07-21 Thread Vlad Levenfeld via Digitalmars-d-learn
On Sunday, 20 July 2014 at 15:45:37 UTC, Atila Neves wrote: On Thursday, 17 July 2014 at 22:52:37 UTC, Justin Whear wrote: On Thu, 17 Jul 2014 22:49:30 +, Nordlöw wrote: AFAIK there is no compile-time variant of interfaces right? Why is that? Wouldn't it be nice to say something like

Map one tuple to another Tuple of different type

2014-07-21 Thread Daniel Gibson via Digitalmars-d-learn
Hi, I have a variadic templated function and want to call a C varargs function. I want to be able to pass static arrays, which D2 passes by value and C by reference, so I'd like to automagically translate those arguments. My idea was something like this: extern (C) origFun(int x, ...);

Re: Code spliting in module and packages

2014-07-21 Thread bearophile via Digitalmars-d-learn
Matthieu: Can someone explain to me how to do it well, please? Put related stuff in a module, and unrelated stuff in other modules. If the module grows too much, split it up in two or more. It's about the same as in Python. Just remember that classes can see each other private members only

Code spliting in module and packages

2014-07-21 Thread Matthieu via Digitalmars-d-learn
Hi! I can't find any good tutorial about how to split my source code in modules and packages. I don't want to use a Java splitting style (one class per file) or something like that, I want to use the D way, but it's so hard to find it! Can someone explain to me how to do it well, please? In the

Re: Question about iteger literals

2014-07-21 Thread Uranuz via Digitalmars-d-learn
I see these rules but when I compile following code and it fails with error it looks VERY stupid. import std.stdio; void main() { ubyte a = 15; ubyte b = 10; ubyte c = a + b; //What is happening there?! ARGH! Are you joking?! } Compilation output: /d837

Re: Really nooB question - @property

2014-07-21 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 20 July 2014 at 16:35:52 UTC, Eric wrote: There are a lot of discussions in the forums about how @property should or could be implemented. But I can't seem to find anything that explains why or when I should use @property with the current compiler. Can anyone explain why and when

Re: Learning to use ranges instead of arrays

2014-07-21 Thread Ivan Kazmenko via Digitalmars-d-learn
Also, there is std.array.array for the ranges you want to convert to arrays. For example, if "a" is an array, "a.map!(x => x * 2).array" produces an new array of doubled values (as opposed to a lazy range produced by std.algorithm.map).

Re: Really nooB question - @property

2014-07-21 Thread Ali Çehreli via Digitalmars-d-learn
On 07/20/2014 11:14 AM, Eric wrote: > >> Use @property when you want a pseudo-variable or something that might >> be conceptually considered a "property" of the object, i.e. to do this: >> >> auto blah = thing.someProperty; >> thing.someProperty = blahblah; > > This is basically what I suspected.

Re: mixin assembler does not work?

2014-07-21 Thread sigod via Digitalmars-d-learn
On Sunday, 20 July 2014 at 15:54:15 UTC, bearophile wrote: mixin template Vala2(uint count, alias arr) { What about disallowing "mixin templatename" unless you add "mixin" before the "template" keyword? Bye, bearophile I thought it's disallowed.

Re: mixin assembler does not work?

2014-07-21 Thread Nicolas Sicard via Digitalmars-d-learn
On Sunday, 20 July 2014 at 15:02:58 UTC, Foo wrote: On Sunday, 20 July 2014 at 14:55:00 UTC, Foo wrote: For clarification: how would that work without mixin + string? I tried this: mixin template Vala2(uint count, alias arr) { asm { sub ESP, count; mov

Re: Question about iteger literals

2014-07-21 Thread bearophile via Digitalmars-d-learn
Uranuz: ubyte a = 15; ubyte b = 10; ubyte c = a + b; //What is happening there?! ARGH! Are you joking?! In C/C++/D if you sum a types that are smaller than int, you obtain an int. D has copied C for backwards compatibility with C code. Bye, bearophile

Re: Really nooB question - @property

2014-07-21 Thread John Colvin via Digitalmars-d-learn
On Sunday, 20 July 2014 at 16:35:52 UTC, Eric wrote: There are a lot of discussions in the forums about how @property should or could be implemented. But I can't seem to find anything that explains why or when I should use @property with the current compiler. Can anyone explain why and when

Re: Question about iteger literals

2014-07-21 Thread Uranuz via Digitalmars-d-learn
In C/C++/D if you sum a types that are smaller than int, you obtain an int. D has copied C for backwards compatibility with C code. Bye, bearophile Is there any reasoning why this should remain unchainged? How could it break interface between languages? And also this code succesfully comp

Re: How to say to compiler that I want to inherit final template bethod of base interface into derived class

2014-07-21 Thread anonymous via Digitalmars-d-learn
On Sunday, 20 July 2014 at 16:47:30 UTC, Uranuz wrote: Where did you get it? Or you compiled it yourself? I'm building it myself. It's not difficult, when you know basic git. And it doesn't take long. You can find instructions here: http://wiki.dlang.org/Building_DMD Because I tried beta4 and

Re: Really nooB question - @property

2014-07-21 Thread John Colvin via Digitalmars-d-learn
On Sunday, 20 July 2014 at 17:59:07 UTC, John Colvin wrote: On Sunday, 20 July 2014 at 16:35:52 UTC, Eric wrote: There are a lot of discussions in the forums about how @property should or could be implemented. But I can't seem to find anything that explains why or when I should use @property

Re: Really nooB question - @property

2014-07-21 Thread Eric via Digitalmars-d-learn
Use @property when you want a pseudo-variable or something that might be conceptually considered a "property" of the object, i.e. to do this: auto blah = thing.someProperty; thing.someProperty = blahblah; This is basically what I suspected. But why write: @property int getValue() { retur

Re: Question about iteger literals

2014-07-21 Thread Uranuz via Digitalmars-d-learn
On Monday, 23 June 2014 at 18:32:38 UTC, Steven Schveighoffer wrote: On Sun, 22 Jun 2014 08:23:45 -0400, Uranuz wrote: If these rules are not so clear and have some exceptions (but I don't understand why they are needed) then some documentation needed about this. See integer promotion rule

Re: mixin assembler does not work?

2014-07-21 Thread bearophile via Digitalmars-d-learn
Foo: I do not understand? Sorry, mine was a language design question (to catch your bug). Bye, bearophile

Really nooB question - @property

2014-07-21 Thread Eric via Digitalmars-d-learn
There are a lot of discussions in the forums about how @property should or could be implemented. But I can't seem to find anything that explains why or when I should use @property with the current compiler. Can anyone explain why and when I should use the @property tag? Thx. Eric

Re: How to say to compiler that I want to inherit final template bethod of base interface into derived class

2014-07-21 Thread Uranuz via Digitalmars-d-learn
On Sunday, 20 July 2014 at 16:12:20 UTC, anonymous wrote: On Sunday, 20 July 2014 at 15:48:19 UTC, Uranuz wrote: Sorry, but this example doesn't work too. Ugh, 2.065 doesn't like it, but it works for me with git head (v2.066-devel-82b031c). Where did you get it? Or you compiled it yourself?

Learning to use ranges instead of arrays

2014-07-21 Thread Bob Tolbert via Digitalmars-d-learn
I find myself writing this code too much and i'm curious what D idiom I am missing. given a list of files (or any strings) and then maybe I want to sort them and maybe I don't. string [] fileList; ... fill list if (sort) { string [] tempList; foreach(filename;

Re: How to say to compiler that I want to inherit final template bethod of base interface into derived class

2014-07-21 Thread anonymous via Digitalmars-d-learn
On Sunday, 20 July 2014 at 15:48:19 UTC, Uranuz wrote: Sorry, but this example doesn't work too. Ugh, 2.065 doesn't like it, but it works for me with git head (v2.066-devel-82b031c).

Re: Learning to use ranges instead of arrays

2014-07-21 Thread Bob Tolbert via Digitalmars-d-learn
Sorry, somehow this submitted in the middle, even without the captcha. Please see the later version.

Re: Learning to use ranges instead of arrays

2014-07-21 Thread Bob Tolbert via Digitalmars-d-learn
On Sunday, 20 July 2014 at 16:11:03 UTC, John Colvin wrote: Even without ranges, you can do this: string [] fileList; ... fill list if (sort) sort(fileList); foreach(filename, fileList) { ... do something; } because sort works in-place. Oh

Re: mixin assembler does not work?

2014-07-21 Thread Foo via Digitalmars-d-learn
On Sunday, 20 July 2014 at 15:54:15 UTC, bearophile wrote: mixin template Vala2(uint count, alias arr) { What about disallowing "mixin templatename" unless you add "mixin" before the "template" keyword? Bye, bearophile I do not understand?

Re: Learning to use ranges instead of arrays

2014-07-21 Thread John Colvin via Digitalmars-d-learn
On Sunday, 20 July 2014 at 16:02:05 UTC, Bob Tolbert wrote: I find myself writing this code too much and i'm curious what D idiom I am missing. given a list of files (or any strings) and then maybe I want to sort them and maybe I don't. string [] fileList; ... fill list if (sor

Re: How to say to compiler that I want to inherit final template bethod of base interface into derived class

2014-07-21 Thread Uranuz via Digitalmars-d-learn
On Sunday, 20 July 2014 at 12:48:09 UTC, anonymous wrote: import std.stdio; interface IBase { template getStr(string fieldName) { final string getStr() { return "George"; } }

Learning to use ranges instead of arrays

2014-07-21 Thread Bob Tolbert via Digitalmars-d-learn
I find myself writing this code too much and i'm curious what D idiom I am missing. given a list of files (or any string) and then maybe I want to sort them and maybe I don't. string [] fileList; ... fill list if (sort) {

Re: mixin assembler does not work?

2014-07-21 Thread bearophile via Digitalmars-d-learn
mixin template Vala2(uint count, alias arr) { What about disallowing "mixin templatename" unless you add "mixin" before the "template" keyword? Bye, bearophile

Re: Compile-Time Interfaces (Concepts)

2014-07-21 Thread Atila Neves via Digitalmars-d-learn
On Thursday, 17 July 2014 at 22:52:37 UTC, Justin Whear wrote: On Thu, 17 Jul 2014 22:49:30 +, Nordlöw wrote: AFAIK there is no compile-time variant of interfaces right? Why is that? Wouldn't it be nice to say something like struct SomeRange realize InputRange { /* implemen

Re: mixin assembler does not work?

2014-07-21 Thread bearophile via Digitalmars-d-learn
Foo: Hey guys. Can someone explain me, why this code does only works with the inline assembler version but not with the mixin? You need mixin(), it's unfortunate this gives no error messages: import std.string: format; enum Vala(uint count, alias arr) = format(" asm { sub ESP, %

Re: mixin assembler does not work?

2014-07-21 Thread bearophile via Digitalmars-d-learn
Foo: It seems that your code doesn't work with 2.065. Right. For 2.065 you have to replace the enum expression with a template. If you can I suggest to update your compiler to the latest beta. There are tons of bugfixes and changes. Bye, bearophile

Re: mixin assembler does not work?

2014-07-21 Thread sigod via Digitalmars-d-learn
On Sunday, 20 July 2014 at 14:18:58 UTC, Foo wrote: template Vala(uint count, alias arr) { immutable string c = to!string(count); enum Vala = "asm { sub ESP, " ~ c ~ "; mov " ~ arr.stringof ~ ", " ~ c ~ "; mov " ~ arr.stringof ~ " + 4, ESP; }"; } ... mixin Vala!(1000,

Re: mixin assembler does not work?

2014-07-21 Thread Foo via Digitalmars-d-learn
On Sunday, 20 July 2014 at 14:55:00 UTC, Foo wrote: For clarification: how would that work without mixin + string? I tried this: mixin template Vala2(uint count, alias arr) { asm { sub ESP, count; mov arr, count; mov arr + 4, ESP;

Re: mixin assembler does not work?

2014-07-21 Thread Foo via Digitalmars-d-learn
On Sunday, 20 July 2014 at 14:46:32 UTC, bearophile wrote: enum Vala(uint count, alias arr) = format(" asm { sub ESP, %d; // Reserve 'count' bytes mov %s, %d; // Set a.length = 'count' mov %s + 4, ESP; // Set &a[0] to reserved bytes }", count, arr.stringof, cou

Re: mixin assembler does not work?

2014-07-21 Thread Foo via Digitalmars-d-learn
On Sunday, 20 July 2014 at 14:44:07 UTC, sigod wrote: On Sunday, 20 July 2014 at 14:18:58 UTC, Foo wrote: template Vala(uint count, alias arr) { immutable string c = to!string(count); enum Vala = "asm { sub ESP, " ~ c ~ "; mov " ~ arr.stringof ~ ", " ~ c ~ "; mov " ~ arr.stringof ~ "

Re: mixin assembler does not work?

2014-07-21 Thread bearophile via Digitalmars-d-learn
sigod: , but I see few mistakes in your code: What's unfortunate is the silence of the compiler about that programmer mistake :-) Bye, bearophile

Re: mixin assembler does not work?

2014-07-21 Thread bearophile via Digitalmars-d-learn
enum Vala(uint count, alias arr) = format(" asm { sub ESP, %d; // Reserve 'count' bytes mov %s, %d; // Set a.length = 'count' mov %s + 4, ESP; // Set &a[0] to reserved bytes }", count, arr.stringof, count, arr.stringof); I'd like to write that more like t

Re: mixin assembler does not work?

2014-07-21 Thread Foo via Digitalmars-d-learn
For clarification: how would that work without mixin + string?

mixin assembler does not work?

2014-07-21 Thread Foo via Digitalmars-d-learn
Hey guys. Can someone explain me, why this code does only works with the inline assembler version but not with the mixin? Thanks in advance! Code: import std.stdio : writeln; import std.conv : to; template Vala(uint count, alias arr) { immutable string c = to!string(count); enum