Re: How to determine if a function is implemented

2013-07-04 Thread Kenji Hara
On Friday, 5 July 2013 at 01:27:06 UTC, JS wrote: the code http://dpaste.dzfl.pl/25bfeeb7 attempts to implement an interface. The current issue is that I need to determine if the user has added the member of the interface to the class or if the mixin needs to add it. so the lines class B

Re: Struct with opDispatch doesn't dispatch. Is this a bug?

2013-07-04 Thread Kenji Hara
On Friday, 5 July 2013 at 03:12:44 UTC, Meta wrote: I wasn't 100% sure the following is a bug, so I figured I'd ask. struct Fail { void opDispatch(string s)() { static assert(false, "Tried to call a method on Fail"); } } void main() { auto fail =

Re: Struct with opDispatch doesn't dispatch. Is this a bug?

2013-07-04 Thread cal
On Friday, 5 July 2013 at 03:12:44 UTC, Meta wrote: I wasn't 100% sure the following is a bug, so I figured I'd ask. struct Fail { void opDispatch(string s)() { static assert(false, "Tried to call a method on Fail"); } } void main() { auto fail =

Struct with opDispatch doesn't dispatch. Is this a bug?

2013-07-04 Thread Meta
I wasn't 100% sure the following is a bug, so I figured I'd ask. struct Fail { void opDispatch(string s)() { static assert(false, "Tried to call a method on Fail"); } } void main() { auto fail = Fail(); fail.s(); //Error: no property 's' fo

Re: Get body of a function as string

2013-07-04 Thread JS
On Saturday, 29 June 2013 at 10:38:57 UTC, bearophile wrote: Jacob Carlborg: I remember someone someone modified DMD and added a .codeof property or similar. It was fairly easy. If there are enough use cases for it, then perhaps it's worth putting both the enhancement request for ".codeof" a

Re: Multidimensional array

2013-07-04 Thread Ali Çehreli
On 07/04/2013 06:43 PM, bearophile wrote: > Ali Çehreli: > >> However, that is a confusing syntax because the right-hand side is not >> the same type as the elements, which is dchar[3]. Perhaps D supports >> it for C compatibility? >> >> It doesn't match the following. Here, the right-hand side i

Re: Multidimensional array

2013-07-04 Thread bearophile
Ali Çehreli: However, that is a confusing syntax because the right-hand side is not the same type as the elements, which is dchar[3]. Perhaps D supports it for C compatibility? It doesn't match the following. Here, the right-hand side is the same as the element type: int[2] arr2 = 42;

Re: Multidimensional array

2013-07-04 Thread Ali Çehreli
On 07/04/2013 03:39 PM, Oleksiy wrote: > 1. What is the rationale behind "prefix declaration" of an array? Using > right-to-left order to declare an array and left-to-right order to > access elements seems confusing. It seems to be confusing to people who are used to C and C++'s inside-out defi

How to determine if a function is implemented

2013-07-04 Thread JS
the code http://dpaste.dzfl.pl/25bfeeb7 attempts to implement an interface. The current issue is that I need to determine if the user has added the member of the interface to the class or if the mixin needs to add it. so the lines class B : A { A a; //void myfunc(f

Re: How to unittest nested functions

2013-07-04 Thread bearophile
Andrej Mitrovic: You don't even need to convert it all to a struct. Since having function-nested unittests is just a parser issue, you can do this: That's nice. If it's just a parser issue, then the right thing seems to fix such issue. Bye, bearophile

Re: How to unittest nested functions

2013-07-04 Thread Andrej Mitrovic
On Wednesday, 9 May 2012 at 21:37:13 UTC, Era Scarecrow wrote: An idea is coming to mind to change it all to a struct You don't even need to convert it all to a struct. Since having function-nested unittests is just a parser issue, you can do this: - int foo() { static int bar()

Re: Multidimensional array

2013-07-04 Thread bearophile
Oleksiy: 1. What is the rationale behind "prefix declaration" of an array? Using right-to-left order to declare an array and left-to-right order to access elements seems confusing. I think the way Go language declares arrays and pointers is a bit better. But for the rationale of this part of

Re: Multidimensional array

2013-07-04 Thread Jonathan M Davis
On Friday, July 05, 2013 00:39:47 Oleksiy wrote: > Hi, > > I'm new to the language and would appreciate if anybody could > clarify the following: > > 1. What is the rationale behind "prefix declaration" of an array? > Using right-to-left order to declare an array and left-to-right > order to acce

Multidimensional array

2013-07-04 Thread Oleksiy
Hi, I'm new to the language and would appreciate if anybody could clarify the following: 1. What is the rationale behind "prefix declaration" of an array? Using right-to-left order to declare an array and left-to-right order to access elements seems confusing. 2. Consider this code: dc

Re: reading a structure (eg header info) from file

2013-07-04 Thread bearophile
captaindet: as for the endianness, as i can oversee it now all potential users will sit on little-endian machines. the group of users is small, just our workgroup. If you are able to put a tag in your file that specifies the endianess, using Phobos it's not hard to convert the data to the ri

Re: reading a structure (eg header info) from file

2013-07-04 Thread captaindet
thanks everyone for your help! i should have mentioned that i did play with std.stdio.File.readf and rawRead but was too thick to figure out a working solution. o i could not figure out how to make readf work with my self defined struct o same with rawRead. but here i understand my mistake now:

Re: interface default implementation mixin

2013-07-04 Thread JS
On Thursday, 4 July 2013 at 19:58:11 UTC, JS wrote: On Thursday, 4 July 2013 at 11:32:25 UTC, Dicebot wrote: On Thursday, 4 July 2013 at 11:13:54 UTC, JS wrote: I'm trying to create a default interface mixin tempate. Some prototype code I've come up with generates the members property but I ge

Re: Variable declaration programming style and the auto keyword

2013-07-04 Thread Jonathan M Davis
On Thursday, July 04, 2013 21:54:22 Jeremy DeHaan wrote: > I've seen a lot of code lately that uses the auto keyword when > declaring variables, but for some reason I don't really care much > for it. > > I'd like to make tutorials for a library I am working on, but I > want to use "D style." Does

Re: interface default implementation mixin

2013-07-04 Thread JS
On Thursday, 4 July 2013 at 11:32:25 UTC, Dicebot wrote: On Thursday, 4 July 2013 at 11:13:54 UTC, JS wrote: I'm trying to create a default interface mixin tempate. Some prototype code I've come up with generates the members property but I get an error I don't understand: http://dpaste.dzfl.p

Re: Variable declaration programming style and the auto keyword

2013-07-04 Thread Namespace
On Thursday, 4 July 2013 at 20:00:18 UTC, Jeremy DeHaan wrote: I've seen a lot of code lately that uses the auto keyword when declaring variables, but for some reason I don't really care much for it. I'd like to make tutorials for a library I am working on, but I want to use "D style." Does s

Variable declaration programming style and the auto keyword

2013-07-04 Thread Jeremy DeHaan
I've seen a lot of code lately that uses the auto keyword when declaring variables, but for some reason I don't really care much for it. I'd like to make tutorials for a library I am working on, but I want to use "D style." Does such a style exist? Is auto generally preferred when declaring v

Re: Finalize GC memory

2013-07-04 Thread Namespace
I must ask again: http://dlang.org/phobos/core_memory.html#.GC.free -> The block will not be finalized regardless of whether the FINALIZE attribute is set. If finalization is desired, use delete instead. In knowledge of this: How can I *finalize* GC memory? delete is or will be deprecated so

Re: std.conv.to vs. casting

2013-07-04 Thread monarch_dodra
On Thursday, 4 July 2013 at 16:16:08 UTC, Ali Çehreli wrote: On 07/04/2013 03:15 AM, Joseph Rushton Wakeling wrote: > The cast should be safe, as it's a size_t to a double. I am commenting without fully understanding the context: Both size_t and double are 64 bit types on a 64-bit system. dou

Re: std.conv.to vs. casting

2013-07-04 Thread H. S. Teoh
On Thu, Jul 04, 2013 at 06:43:16PM +0200, Joseph Rushton Wakeling wrote: > On 07/04/2013 06:16 PM, Ali Çehreli wrote: > > I am commenting without fully understanding the context: Both size_t > > and double are 64 bit types on a 64-bit system. double.mant_dig > > being 53, converting from size_t to

Re: std.conv.to vs. casting

2013-07-04 Thread Ali Çehreli
On 07/04/2013 09:43 AM, Joseph Rushton Wakeling wrote: > On 07/04/2013 06:16 PM, Ali Çehreli wrote: >> I am commenting without fully understanding the context: Both size_t and double >> are 64 bit types on a 64-bit system. double.mant_dig being 53, converting from >> size_t to double loses inf

Re: std.conv.to vs. casting

2013-07-04 Thread Joseph Rushton Wakeling
On 07/04/2013 06:16 PM, Ali Çehreli wrote: > I am commenting without fully understanding the context: Both size_t and > double > are 64 bit types on a 64-bit system. double.mant_dig being 53, converting from > size_t to double loses information for many values. Oh, bugger. You mean that because

Re: Allocating a slice object

2013-07-04 Thread Jonathan M Davis
On Thursday, July 04, 2013 09:37:57 Steven Schveighoffer wrote: > On Thu, 04 Jul 2013 08:02:13 -0400, monarch_dodra > > wrote: > > This is a pretty stupid question, but how would you allocate an "int[]" > > on the heap? I'm not talking about the array, but the actual slice > > object. EG: > > >

Simple test suite for std.random

2013-07-04 Thread Joseph Rushton Wakeling
Hi all, I'm preparing a few very simplistic test functions for std.random. These are not so suitable for unittests as they are basically to check that random values are being generated in the correct proportions, etc.: https://github.com/WebDrake/std.random.test Actually, right now the ONLY test

Re: std.conv.to vs. casting

2013-07-04 Thread Ali Çehreli
On 07/04/2013 03:15 AM, Joseph Rushton Wakeling wrote: > The cast should be safe, as it's a size_t to a double. I am commenting without fully understanding the context: Both size_t and double are 64 bit types on a 64-bit system. double.mant_dig being 53, converting from size_t to double loses

Re: delegates, functions, and literals confusion

2013-07-04 Thread Mike Parker
On Thursday, 4 July 2013 at 13:23:23 UTC, CJS wrote: Thanks for the detailed answer! Just to clarify: So if f is an inner function then &f will be a delegate even if it doesn't reference anything in the environment in which it was defined? (i.e. even if it could have been typed as a function?

Re: Print out the name of a type

2013-07-04 Thread Joseph Rushton Wakeling
On 07/04/2013 04:51 PM, Artur Skawina wrote: > writeln("Today, Michael, I'm going to be a "~T.stringof~"!") > > artur I used to know that, too. Thanks very much! :-)

Re: if(false) vs if(isNaN) benchmark

2013-07-04 Thread Joseph Rushton Wakeling
On 07/04/2013 04:05 PM, monarch_dodra wrote: > Holly crap, I didn't see that. Don't do that. The problem if you do that is > that > on a lot of machines, the time it takes to do 1 iteration is shorter than the > granularity of the clock. For example, on windows, it is typically 15 ms, > which > i

Re: stdout in binary mode

2013-07-04 Thread bearophile
Mike Parker: setmode() should be in unistd.h, but I can't import core.stdc.unistd (and I don't find it in std.c.windows.windows). core.sys.posix.unistd I have tried this on Windows32, and it doesn't find much: import core.sys.posix.unistd: setmode; import core.sys.posix.stdio: fileno; impo

Re: Print out the name of a type

2013-07-04 Thread monarch_dodra
On Thursday, 4 July 2013 at 14:51:21 UTC, Artur Skawina wrote: On 07/04/13 16:46, Joseph Rushton Wakeling wrote: Suppose I've got a function that is conditional on a type: void foo(T)(/* input vars */) { ... } How could I print out using writeln the name of that type? So that if I call

Re: Print out the name of a type

2013-07-04 Thread Dicebot
On Thursday, 4 July 2013 at 14:46:36 UTC, Joseph Rushton Wakeling wrote: ... Each has own disadvantages, chose one ;) T.stringof // simple & reliable, won't work for function aliases __traits(identifier, T) // only symbols std.traits.fullyQualifiedName!T // issues with templated types, includ

Re: Print out the name of a type

2013-07-04 Thread Artur Skawina
On 07/04/13 16:46, Joseph Rushton Wakeling wrote: > Suppose I've got a function that is conditional on a type: > > void foo(T)(/* input vars */) { ... } > > How could I print out using writeln the name of that type? So that if I call > > foo!double(...); > > ... I would see: > > T

Print out the name of a type

2013-07-04 Thread Joseph Rushton Wakeling
Suppose I've got a function that is conditional on a type: void foo(T)(/* input vars */) { ... } How could I print out using writeln the name of that type? So that if I call foo!double(...); ... I would see: Today, Michael, I'm going to be a double! ... whereas if I give it,

Re: if(false) vs if(isNaN) benchmark

2013-07-04 Thread monarch_dodra
On Thursday, 4 July 2013 at 13:43:13 UTC, Joseph Rushton Wakeling wrote: On 07/04/2013 03:05 PM, monarch_dodra wrote: Me thinks the test is biased with answering true to isNan. You should first initialize your arrays with random [true/false] | [nan/nonan] value. In particular, it is more import

Re: Allocating a slice object

2013-07-04 Thread monarch_dodra
On Thursday, 4 July 2013 at 13:37:52 UTC, Steven Schveighoffer wrote: On Thu, 04 Jul 2013 08:02:13 -0400, monarch_dodra wrote: This is a pretty stupid question, but how would you allocate an "int[]" on the heap? I'm not talking about the array, but the actual slice object. EG: int[]* pSlic

Re: Address of overloaded functions

2013-07-04 Thread John Colvin
On Thursday, 4 July 2013 at 09:15:30 UTC, Dicebot wrote: On Wednesday, 3 July 2013 at 15:17:49 UTC, John Colvin wrote: It's a pity that only work within an aggregate (the documentation actually says only classes) http://dpaste.dzfl.pl/6866e094 Surprise! :P Hooray :) I've submitted a pull re

Re: if(false) vs if(isNaN) benchmark

2013-07-04 Thread Joseph Rushton Wakeling
On 07/04/2013 03:05 PM, monarch_dodra wrote: > Me thinks the test is biased with answering true to isNan. You should first > initialize your arrays with random [true/false] | [nan/nonan] value. In > particular, it is more important for isNan to answer "No" as fast as possible, > rather than actuall

Re: Allocating a slice object

2013-07-04 Thread Steven Schveighoffer
On Thu, 04 Jul 2013 08:02:13 -0400, monarch_dodra wrote: This is a pretty stupid question, but how would you allocate an "int[]" on the heap? I'm not talking about the array, but the actual slice object. EG: int[]* pSlice = new int[]; //Error: new can only create structs, //dynamic array

Re: Allocating a slice object

2013-07-04 Thread Maxim Fomin
On Thursday, 4 July 2013 at 12:02:16 UTC, monarch_dodra wrote: This is a pretty stupid question, but how would you allocate an "int[]" on the heap? I'm not talking about the array, but the actual slice object. EG: int[]* pSlice = new int[]; //Error: new can only create structs, //dynamic array

Re: stdout in binary mode

2013-07-04 Thread Mike Parker
On Thursday, 4 July 2013 at 12:28:07 UTC, bearophile wrote: Steven Schveighoffer: setmode() should be in unistd.h, but I can't import core.stdc.unistd (and I don't find it in std.c.windows.windows). core.sys.posix.unistd setmode isn't actually standard C nor of the Posix standard. It's

Re: delegates, functions, and literals confusion

2013-07-04 Thread CJS
Thanks for the detailed answer! Just to clarify: So if f is an inner function then &f will be a delegate even if it doesn't reference anything in the environment in which it was defined? (i.e. even if it could have been typed as a function?)

Re: std.conv.to vs. casting

2013-07-04 Thread CJS
By the way, CJS -- sorry to have hijacked your query. But I think you had your answer already :-) Yes. It was a very helpful answer. I'm just glad the question I asked was apparently relevant to other users as well.

Re: if(false) vs if(isNaN) benchmark

2013-07-04 Thread monarch_dodra
On Thursday, 4 July 2013 at 12:53:48 UTC, Joseph Rushton Wakeling wrote: Hi all, A trivial little benchmark for comparing the performance of a function using if(!booleanValue) as a conditional, versus one using if(isNan(x)). Run with dmd -O -release -inline -noboundscheck on my system, I fi

if(false) vs if(isNaN) benchmark

2013-07-04 Thread Joseph Rushton Wakeling
Hi all, A trivial little benchmark for comparing the performance of a function using if(!booleanValue) as a conditional, versus one using if(isNan(x)). Run with dmd -O -release -inline -noboundscheck on my system, I find the two are virtually equivalent, with it taking about 30ms for 1 million if

Re: stdout in binary mode

2013-07-04 Thread bearophile
Steven Schveighoffer: In C++ you use something like: setmode(fileno(stdout), O_BINARY); (I don't even know where to find O_BINARY in core.stdc). It may not be present, but it's just a number. Look it up. Adding a hardcoded magic number in my code isn't very good. setmode() should be in u

Allocating a slice object

2013-07-04 Thread monarch_dodra
This is a pretty stupid question, but how would you allocate an "int[]" on the heap? I'm not talking about the array, but the actual slice object. EG: int[]* pSlice = new int[]; //Error: new can only create structs, //dynamic arrays or class objects, not int[]'s Is there a simple "idiomatic" w

Re: stdout in binary mode

2013-07-04 Thread Steven Schveighoffer
On Wed, 03 Jul 2013 20:20:17 -0400, bearophile wrote: How do you open stdout in binary mode with D/Phobos? Same way you would do it in C. D uses C's FILE * as it's implementation. In C++ you use something like: setmode(fileno(stdout), O_BINARY); (I don't even know where to find O_BINAR

Re: interface default implementation mixin

2013-07-04 Thread Dicebot
On Thursday, 4 July 2013 at 11:13:54 UTC, JS wrote: I'm trying to create a default interface mixin tempate. Some prototype code I've come up with generates the members property but I get an error I don't understand: http://dpaste.dzfl.pl/58c0392d void myfunc(float a, int b, string c) { a.myfu

Re: Address of overloaded functions

2013-07-04 Thread Artur Skawina
On 07/04/13 01:31, Tyro[17] wrote: > On 7/3/13 12:52 PM, Artur Skawina wrote: >> import std.stdio; >> >> void foo(int a){ writeln("overload int"); } >> void foo(long b){ writeln("overload long"); } >> >> auto pickOverload(alias FP, A...)() @property { typeof(FP(A.init)) >> function(A)

interface default implementation mixin

2013-07-04 Thread JS
I'm trying to create a default interface mixin tempate. Some prototype code I've come up with generates the members property but I get an error I don't understand: http://dpaste.dzfl.pl/58c0392d void myfunc(float a, int b, string c) { a.myfunc(a, b, c); } /d650/f247.d(70): Error: no property

Re: std.conv.to vs. casting

2013-07-04 Thread Joseph Rushton Wakeling
On Thursday, 4 July 2013 at 10:23:22 UTC, monarch_dodra wrote: I'm trying to read the bug entry, but I don't get it. Maybe a reduced case to explain? Point is, the skip() function in std.random.RandomSample can be called with the floating-point variable _Vprime equal to nan, _if_ popFront() o

Re: std.conv.to vs. casting

2013-07-04 Thread Joseph Rushton Wakeling
On Thursday, 4 July 2013 at 10:32:26 UTC, Joseph Rushton Wakeling wrote: I can prepare a reduced example but it's probably simpler for me to just prepare a bugfix and do some benchmarks. By the way, CJS -- sorry to have hijacked your query. But I think you had your answer already :-)

Re: std.conv.to vs. casting

2013-07-04 Thread monarch_dodra
On Thursday, 4 July 2013 at 10:15:22 UTC, Joseph Rushton Wakeling wrote: On 07/04/2013 12:08 PM, monarch_dodra wrote: I didn't go into the details, but in your bug report, it seems like it is more of an implementation error ? In that case, an ERROR would be better. The cast should be safe, as

Re: std.conv.to vs. casting

2013-07-04 Thread Joseph Rushton Wakeling
On 07/04/2013 12:08 PM, monarch_dodra wrote: > I didn't go into the details, but in your bug report, it seems like it is more > of an implementation error ? In that case, an ERROR would be better. The cast should be safe, as it's a size_t to a double. It's just that having to!double() would have

Re: zip vs. lockstep -- problem when setting values

2013-07-04 Thread Joseph Rushton Wakeling
On 06/30/2013 02:16 AM, Ali Çehreli wrote: > Looks like a bug and I can't find it in bugzilla. Thanks for checking, Ali :-) I've added it: http://d.puremagic.com/issues/show_bug.cgi?id=10541

Re: std.conv.to vs. casting

2013-07-04 Thread monarch_dodra
On Thursday, 4 July 2013 at 09:31:42 UTC, Joseph Rushton Wakeling wrote: On 07/04/2013 10:14 AM, monarch_dodra wrote: Casting merely changes the "observed type", whereas "to" does a deep conversion. What are the speed implications of to compared to cast? I ask because I see various casts in P

Re: std.conv.to vs. casting

2013-07-04 Thread Joseph Rushton Wakeling
On 07/04/2013 10:14 AM, monarch_dodra wrote: > Casting merely changes the "observed type", whereas "to" does a deep > conversion. What are the speed implications of to compared to cast? I ask because I see various casts in Phobos, and wonder if there isn't improved safety in preferring instead t

Re: Address of overloaded functions

2013-07-04 Thread Dicebot
On Wednesday, 3 July 2013 at 15:17:49 UTC, John Colvin wrote: It's a pity that only work within an aggregate (the documentation actually says only classes) http://dpaste.dzfl.pl/6866e094 Surprise! :P

Re: Strange error

2013-07-04 Thread monarch_dodra
On Thursday, 4 July 2013 at 08:34:24 UTC, Temtaime wrote: Hello guys ! I'm found strange error when compiling following code: http://dpaste.1azy.net/b40ce9a4 The error is: src\phobos\std\stdio.d(1872): Error: variable _param_1 used before set Problem exists only when using following options:

Re: delegates, functions, and literals confusion

2013-07-04 Thread Mike Parker
On Thursday, 4 July 2013 at 06:43:12 UTC, CJS wrote: In my case I'm trying to figure out the best way to pass functions to other fundtions. So I wrote the following toy code to see what the compiler would do. I'm trying to understand why the compiler emitted errors on the code below (shown w/

Strange error

2013-07-04 Thread Temtaime
Hello guys ! I'm found strange error when compiling following code: http://dpaste.1azy.net/b40ce9a4 The error is: src\phobos\std\stdio.d(1872): Error: variable _param_1 used before set Problem exists only when using following options: -inline -O I'm using DMD 2.063.2 on Windows. Can anybody

Re: std.conv.to vs. casting

2013-07-04 Thread monarch_dodra
On Thursday, 4 July 2013 at 06:18:21 UTC, CJS wrote: I'm having trouble understanding the difference between casting and std.conv.to. Any help? Casting merely changes the "observed type", whereas "to" does a deep conversion. Observe: import std.stdio; import std.conv; void main() {