Re: Implicit conversion in constructor

2015-07-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 18 July 2015 at 02:28:09 UTC, tcak wrote: I even am not sure how in the world it allows implicit conversion from class to struct in "fine" at all. Given: struct Foo { T x; alias x this; } Any time you do Foo foo; foo.something = whatever; // or foo = whatever; // or what

Re: Implicit conversion in constructor

2015-07-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 18 July 2015 at 02:23:26 UTC, rcorre wrote: Is there any reason why implicit conversion from Foo to Thing is permitted in a regular method but not in a constructor? In the constructor, you are supposed to be constructing things, so the first "assignment" of structs is actually a c

Re: Are Lua tables possible to do with D?

2015-07-17 Thread rcorre via Digitalmars-d-learn
On Thursday, 16 July 2015 at 07:20:16 UTC, Fusxfaranto wrote: An associative array of Variant[string] ought to do the job well enough. http://dlang.org/phobos/std_variant.html For extra fun, you can implement the '.' style syntax pretty easily: --- import std.variant; struct LuaTable {

Re: Implicit conversion in constructor

2015-07-17 Thread rcorre via Digitalmars-d-learn
On Saturday, 18 July 2015 at 02:28:09 UTC, tcak wrote: I even am not sure how in the world it allows implicit conversion from class to struct in "fine" at all. The 'alias this' in the struct permits implicit conversion. I _think_ that is intended behavior, though I admit I'm not actually sur

Re: Implicit conversion in constructor

2015-07-17 Thread tcak via Digitalmars-d-learn
On Saturday, 18 July 2015 at 02:23:26 UTC, rcorre wrote: Is there any reason why implicit conversion from Foo to Thing is permitted in a regular method but not in a constructor? Trying to figure out whether this is a bug or some sort of constructor-specific safety precaution. struct Thing {

Implicit conversion in constructor

2015-07-17 Thread rcorre via Digitalmars-d-learn
Is there any reason why implicit conversion from Foo to Thing is permitted in a regular method but not in a constructor? Trying to figure out whether this is a bug or some sort of constructor-specific safety precaution. struct Thing { Foo foo; alias foo this; } class Foo { } class Bar {

Re: Virtual value types during compile-time for static type safety, static optimizations and function overloading.

2015-07-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 17 July 2015 at 23:44:25 UTC, Tamas wrote: I used DMD, BTW. what compile flags?

Re: Using executeShell in multiple thread causes access violation error

2015-07-17 Thread ZombineDev via Digitalmars-d-learn
On Monday, 13 July 2015 at 09:46:26 UTC, Minas Mina wrote: I have written a script that visits all directories in the current directory and executes a command. In my case, "git pull". When running the script serially, everything is fine. All git repositories are pulled. But I'd like to pull

Re: Getting Nth Row and Column from MatrixView, Scid library

2015-07-17 Thread bachmeier via Digitalmars-d-learn
On Friday, 17 July 2015 at 22:05:45 UTC, kerdemdemir wrote: Sad times with linear algebra libraries for me, Since I can't get rows and columns easily with Scid, It seems not flexible for me. And also there are other issues for example I can't set matrix to row or column major. I begin to ch

Re: Virtual value types during compile-time for static type safety, static optimizations and function overloading.

2015-07-17 Thread Baz via Digitalmars-d-learn
On Friday, 17 July 2015 at 21:20:41 UTC, Tamas wrote: Although this code is fully operational, presents nice api and compile-time optimizations, the extra Struct wrapper is not without runtime penalty. Is there a solution that results the same static optimizations, but has no runtime penalty,

Re: Virtual value types during compile-time for static type safety, static optimizations and function overloading.

2015-07-17 Thread Tamas via Digitalmars-d-learn
On Friday, 17 July 2015 at 23:16:51 UTC, ZombineDev wrote: On Friday, 17 July 2015 at 23:15:31 UTC, ZombineDev wrote: On Friday, 17 July 2015 at 21:20:41 UTC, Tamas wrote: Is there a solution that results the same static optimizations, but has no runtime penalty, i.e. the functions just operat

Re: Virtual value types during compile-time for static type safety, static optimizations and function overloading.

2015-07-17 Thread ZombineDev via Digitalmars-d-learn
On Friday, 17 July 2015 at 23:15:31 UTC, ZombineDev wrote: On Friday, 17 July 2015 at 21:20:41 UTC, Tamas wrote: Is there a solution that results the same static optimizations, but has no runtime penalty, i.e. the functions just operates with ints? (At least when compiled) Did you try looking

Re: Virtual value types during compile-time for static type safety, static optimizations and function overloading.

2015-07-17 Thread ZombineDev via Digitalmars-d-learn
On Friday, 17 July 2015 at 21:20:41 UTC, Tamas wrote: Is there a solution that results the same static optimizations, but has no runtime penalty, i.e. the functions just operates with ints? (At least when compiled) Did you try looking at assembly generated by GDC or LDC with full optimization

Re: Using executeShell in multiple thread causes access violation error

2015-07-17 Thread Minas Mina via Digitalmars-d-learn
bump

Re: Getting Nth Row and Column from MatrixView, Scid library

2015-07-17 Thread kerdemdemir via Digitalmars-d-learn
Sad times with linear algebra libraries for me, Since I can't get rows and columns easily with Scid, It seems not flexible for me. And also there are other issues for example I can't set matrix to row or column major. I begin to check alternatives first I begin to investigate Dlib. D lib ma

Re: Working functionally with third party libraries

2015-07-17 Thread ZombineDev via Digitalmars-d-learn
On Friday, 17 July 2015 at 17:56:51 UTC, sigod wrote: On Friday, 17 July 2015 at 15:41:22 UTC, ZombineDev wrote: eager approach, since it's more straightforward. What makes you think it's always more straightforward? Sometimes (like in this case with MongoDB) you cannot write eager approach

Virtual value types during compile-time for static type safety, static optimizations and function overloading.

2015-07-17 Thread Tamas via Digitalmars-d-learn
I got inspired by Andrei's "Generic Programming Must Go" talk: https://www.youtube.com/watch?v=mCrVYYlFTrA I.e. writing functions with static if-s, based on what we know about the input. So the question is how to annotate the input variables? Adam showed an excellent solution for this, by wrap

Can you add a remote repository to DUB?

2015-07-17 Thread Zekereth via Digitalmars-d-learn
All I can find is add-local. Thanks!

Re: How to convert byte array to float

2015-07-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, July 17, 2015 18:43:26 DLangLearner via Digitalmars-d-learn wrote: > Excuse me for my trivial question, but I'd like to know how to > convert byte array to float? What I could think of are > cast(float)(byte[]) and to!float(byte[]) but they do not work for > me. Thanks! You could use st

Re: How to convert byte array to float

2015-07-17 Thread DLangLearner via Digitalmars-d-learn
On Friday, 17 July 2015 at 18:58:33 UTC, byron wrote: On Friday, 17 July 2015 at 18:53:24 UTC, byron wrote: On Friday, 17 July 2015 at 18:43:27 UTC, DLangLearner wrote: Excuse me for my trivial question, but I'd like to know how to convert byte array to float? What I could think of are cast(fl

Re: How to convert byte array to float

2015-07-17 Thread byron via Digitalmars-d-learn
On Friday, 17 July 2015 at 19:03:46 UTC, Jacob Carlborg wrote: On 2015-07-17 20:58, byron wrote: Ah I miss read, if you want as a float, not a float array you can do: byte[] b = [1, 2, 3, 4]; float f = *cast(float*)b.ptr; not sure if there is a better way I think a union can be used as wel

Re: Template function that accept strings and array of strings

2015-07-17 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-07-17 19:25, badlink wrote: My fault, I didn't test the variadic function enough and jumped to conclusion. It actually works well http://pastebin.com/R4EHuBLh Cool :) Sometimes D developers think templates will be needed to solve everything. -- /Jacob Carlborg

Re: Environment variable for application storage under OSX ?

2015-07-17 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-07-17 15:27, anonymous wrote: Ok so my sample can be rewritten static this() { version(Win32) p = environment.get("APPDATA"); version(linux) p = "/home/" ~ environment.get("USER"); version(OSX) p = environment.get("HOME") ~ /Library/Application Support/; } --- I

Re: How to convert byte array to float

2015-07-17 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-07-17 20:58, byron wrote: Ah I miss read, if you want as a float, not a float array you can do: byte[] b = [1, 2, 3, 4]; float f = *cast(float*)b.ptr; not sure if there is a better way I think a union can be used as well, not sure if it's better though. -- /Jacob Carlborg

Re: How to convert byte array to float

2015-07-17 Thread byron via Digitalmars-d-learn
On Friday, 17 July 2015 at 18:53:24 UTC, byron wrote: On Friday, 17 July 2015 at 18:43:27 UTC, DLangLearner wrote: Excuse me for my trivial question, but I'd like to know how to convert byte array to float? What I could think of are cast(float)(byte[]) and to!float(byte[]) but they do not work

Re: LNK2019 error from using a function pointer to core.bitop functions?

2015-07-17 Thread Matthew Gamble via Digitalmars-d-learn
On Friday, 17 July 2015 at 15:49:46 UTC, Roland Hadinger wrote: On Friday, 17 July 2015 at 15:47:39 UTC, Roland Hadinger wrote: Otherwise, I'd use templates and an alias. Maybe this will result in faster code: bool opIndexAssign(bool value, size_t[2] inds) { void impl(bool b)(s

Re: How to convert byte array to float

2015-07-17 Thread byron via Digitalmars-d-learn
On Friday, 17 July 2015 at 18:43:27 UTC, DLangLearner wrote: Excuse me for my trivial question, but I'd like to know how to convert byte array to float? What I could think of are cast(float)(byte[]) and to!float(byte[]) but they do not work for me. Thanks! You want to include [] in the cast s

How to convert byte array to float

2015-07-17 Thread DLangLearner via Digitalmars-d-learn
Excuse me for my trivial question, but I'd like to know how to convert byte array to float? What I could think of are cast(float)(byte[]) and to!float(byte[]) but they do not work for me. Thanks!

Re: Comparison of struct with Nullable member

2015-07-17 Thread anonymous via Digitalmars-d-learn
On Friday, 17 July 2015 at 12:18:56 UTC, TC wrote: Hello, I came around a strange behavior and I'm not sure if it is a bug or feature. import std.typecons : Nullable; struct Foo { string bar; Nullable!int baz; } auto a = Foo("bb"); auto b = Foo("bb"); assert(a == b); This end

Re: Working functionally with third party libraries

2015-07-17 Thread sigod via Digitalmars-d-learn
On Friday, 17 July 2015 at 15:41:22 UTC, ZombineDev wrote: eager approach, since it's more straightforward. What makes you think it's always more straightforward? Sometimes (like in this case with MongoDB) you cannot write eager approach without first writing lazy one.

Re: Template function that accept strings and array of strings

2015-07-17 Thread badlink via Digitalmars-d-learn
On Friday, 17 July 2015 at 12:58:58 UTC, Jacob Carlborg wrote: I don't think I really understand how you want to use/call the function. Could you give an example with all the different types you want to call the function? My fault, I didn't test the variadic function enough and jumped to conc

Re: How to use core.thread.Thread

2015-07-17 Thread aki via Digitalmars-d-learn
On Friday, 17 July 2015 at 14:14:41 UTC, byron wrote: Since I have yet to use or see anyone use shared in a useful way I avoid it. It's one way to avoid it. So, you mean you always use send/receive when you need threading? I did small test to know the memory layout. import core.atomic; int foo

Re: Comparison of struct with Nullable member

2015-07-17 Thread Meta via Digitalmars-d-learn
On Friday, 17 July 2015 at 15:52:45 UTC, TC wrote: On Friday, 17 July 2015 at 15:30:42 UTC, Meta wrote: https://issues.dlang.org/show_bug.cgi?id=14804 I'll probably be able to submit a PR for this sometime in the next few days. Thanks. What I don't get is why this one works ok? import std.t

Re: LNK2019 error from using a function pointer to core.bitop functions?

2015-07-17 Thread Roland Hadinger via Digitalmars-d-learn
On Thursday, 16 July 2015 at 03:24:54 UTC, Matthew Gamble wrote: This member function of my struct uses a function pointer btx. When the line declaring the function pointer is present I get a LNK2019 error: unresolved external symbol. Just guessing, probably because bts and btr are intrinsics?

Re: Comparison of struct with Nullable member

2015-07-17 Thread TC via Digitalmars-d-learn
On Friday, 17 July 2015 at 15:30:42 UTC, Meta wrote: https://issues.dlang.org/show_bug.cgi?id=14804 I'll probably be able to submit a PR for this sometime in the next few days. Thanks. What I don't get is why this one works ok? import std.typecons : Nullable; struct Foo { int bar;

Re: Working functionally with third party libraries

2015-07-17 Thread ZombineDev via Digitalmars-d-learn
On Friday, 17 July 2015 at 15:41:22 UTC, ZombineDev wrote: I'm almost certain that the D database driver returns eagerly all the results that you've requested. The lazy stuff should happen when you start doing range operations after the results are returned from the database. It's not impossibl

Re: LNK2019 error from using a function pointer to core.bitop functions?

2015-07-17 Thread Roland Hadinger via Digitalmars-d-learn
On Friday, 17 July 2015 at 15:47:39 UTC, Roland Hadinger wrote: Otherwise, I'd use templates and an alias. Maybe this will result in faster code: bool opIndexAssign(bool value, size_t[2] inds) { void impl(bool b)(size_t[2] inds) { static if(b)

Re: Working functionally with third party libraries

2015-07-17 Thread ZombineDev via Digitalmars-d-learn
On Friday, 17 July 2015 at 09:07:29 UTC, Jarl André Hübenthal wrote: Thanks. Its a lot more cleaner and syntactically readable having .array at the end. But about laziness the same applies to clojure and scala. In clojure you must force evaluate the list, in scala you must to mostly the same as

Re: Comparison of struct with Nullable member

2015-07-17 Thread Meta via Digitalmars-d-learn
On Friday, 17 July 2015 at 12:18:56 UTC, TC wrote: Hello, I came around a strange behavior and I'm not sure if it is a bug or feature. import std.typecons : Nullable; struct Foo { string bar; Nullable!int baz; } auto a = Foo("bb"); auto b = Foo("bb"); assert(a == b); This end

Re: How to use core.thread.Thread

2015-07-17 Thread byron via Digitalmars-d-learn
On Friday, 17 July 2015 at 07:56:48 UTC, aki wrote: On Thursday, 16 July 2015 at 09:17:47 UTC, Daniel Kozák wrote: class DerivedThread : Thread { shared int count = 0; } I thought shared is only for whole of the object. auto thr = new DerivedThread(); Here, "thr" is not shared but it's

Re: Infinite range of nullable elements

2015-07-17 Thread Roland Hadinger via Digitalmars-d-learn
On Friday, 17 July 2015 at 12:44:57 UTC, anonymous wrote: The building blocks are there. You're `map`ping the original range to `Nullable`, and then you're `chain`ing an infinite range (`cycle`) of nulls behind. import std.range: isInputRange; auto cushion(R)(R r) if (isInputRange!R)

Re: Comparison of struct with Nullable member

2015-07-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 17 July 2015 at 12:18:56 UTC, TC wrote: Hello, I came around a strange behavior and I'm not sure if it is a bug or feature. import std.typecons : Nullable; struct Foo { string bar; Nullable!int baz; } auto a = Foo("bb"); auto b = Foo("bb"); assert(a == b); This end

Re: Environment variable for application storage under OSX ?

2015-07-17 Thread anonymous via Digitalmars-d-learn
On Friday, 17 July 2015 at 07:54:43 UTC, FreeSlave wrote: On Friday, 17 July 2015 at 07:33:43 UTC, Anonymous wrote: On Friday, 17 July 2015 at 07:14:24 UTC, FreeSlave wrote: On Thursday, 16 July 2015 at 21:12:05 UTC, anonymous wrote: I have the following code, working under Win and Linux: ---

Re: Infinite range of nullable elements

2015-07-17 Thread Roland Hadinger via Digitalmars-d-learn
On Friday, 17 July 2015 at 10:19:22 UTC, Márcio Martins wrote: On Friday, 17 July 2015 at 07:42:09 UTC, Roland Hadinger wrote: At this moment I'm tempted to implement a function taking a range of elements E and returning an infinite range of Nullable!E. [...] Wouldn't it still require the a

Re: Environment variable for application storage under OSX ?

2015-07-17 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-07-17 09:14, FreeSlave wrote: Hello. You may take a look at this library https://github.com/MyLittleRobo/standardpaths OSX version uses Carbon though. You may want to use Cocoa API (which is newer), but it's Objective-C. DMD master now has some initial support for Objective-C. -- /Jac

Re: Template function that accept strings and array of strings

2015-07-17 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-07-16 18:49, badlink wrote: The method with the variadic function works, but I would have to use only one parameter because this doesn't work: fun(const(char[])[] a, const(char[])[] b ...) and is a bit ugly in my use case ... I don't think I really understand how you want to use/call t

Re: Working functionally with third party libraries

2015-07-17 Thread Kagamin via Digitalmars-d-learn
On Friday, 17 July 2015 at 09:07:29 UTC, Jarl André Hübenthal wrote: Or loop it. But its pretty nice to know that there is laziness in D, but when I query mongo I expect all docs to be retrieved, since there are no paging in the underlying queries? Thus, having a lazy functionality on top of no

Re: Environment variable for application storage under OSX ?

2015-07-17 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-07-16 23:12, anonymous wrote: I have the following code, working under Win and Linux: --- import std.process: environment; immutable string p; static this() { version(Win32) p = environment.get("APPDATA"); version(linux) p = "/home/" ~ environment.get("USER"); version(OS

Re: Environment variable for application storage under OSX ?

2015-07-17 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-07-17 09:33, Anonymous wrote: So for a software named 'SuperDownloader2015' it would be $HOME/Library/Application Support/SuperDownloader2015 right ? so it's not user-specific and it's writable for the current user ? sorry but it looks a bit strange, anyone can confirm ? Yes, that'

Re: Working functionally with third party libraries

2015-07-17 Thread via Digitalmars-d-learn
On Friday, 17 July 2015 at 11:47:30 UTC, sigod wrote: On Friday, 17 July 2015 at 09:07:29 UTC, Jarl André Hübenthal wrote: But its pretty nice to know that there is laziness in D, but when I query mongo I expect all docs to be retrieved, since there are no paging in the underlying queries? Thus

Re: Infinite range of nullable elements

2015-07-17 Thread anonymous via Digitalmars-d-learn
On Friday, 17 July 2015 at 07:42:09 UTC, Roland Hadinger wrote: Here's how I would implement the basic behaviour (could be extended to also forward bidirectional and random access functions): --- auto cushion(R)(R r) if (isInputRange!R) { static if (isInfinite!R) { retu

Comparison of struct with Nullable member

2015-07-17 Thread TC via Digitalmars-d-learn
Hello, I came around a strange behavior and I'm not sure if it is a bug or feature. import std.typecons : Nullable; struct Foo { string bar; Nullable!int baz; } auto a = Foo("bb"); auto b = Foo("bb"); assert(a == b); This ends up with: Called `get' on null Nullable!int But if

Re: Working functionally with third party libraries

2015-07-17 Thread sigod via Digitalmars-d-learn
On Friday, 17 July 2015 at 09:07:29 UTC, Jarl André Hübenthal wrote: But its pretty nice to know that there is laziness in D, but when I query mongo I expect all docs to be retrieved, since there are no paging in the underlying queries? Thus, having a lazy functionality on top of non lazy db qu

Re: Infinite range of nullable elements

2015-07-17 Thread via Digitalmars-d-learn
On Friday, 17 July 2015 at 07:42:09 UTC, Roland Hadinger wrote: At this moment I'm tempted to implement a function taking a range of elements E and returning an infinite range of Nullable!E. [...] Wouldn't it still require the algorithms to check if an element isNull()? Calling get() on a n

Re: Working functionally with third party libraries

2015-07-17 Thread via Digitalmars-d-learn
On Thursday, 16 July 2015 at 20:41:21 UTC, ZombineDev wrote: On Thursday, 16 July 2015 at 20:17:54 UTC, Jarl André Hübenthal wrote: On Thursday, 16 July 2015 at 20:00:38 UTC, Ali Çehreli wrote: On 07/16/2015 12:35 PM, "Jarl =?UTF-8?B?QW5kcsOpIEjDvGJlbnRoYWwi?= " wrote: Hi using mongo with vi

Getting Nth Row and Column from MatrixView, Scid library

2015-07-17 Thread kerdemdemir via Digitalmars-d-learn
Hi, I want to use Scid matrixes for implementing GMM algorithm. I will start by writing Naive Bayes with linear and quadratic decision boundaries . I reliaze Scid does not provides any functions for getting spesific row or coloumn. Matrixwview class only supplies opIndex function. Is the

Re: How to use core.thread.Thread

2015-07-17 Thread aki via Digitalmars-d-learn
On Thursday, 16 July 2015 at 09:17:47 UTC, Daniel Kozák wrote: class DerivedThread : Thread { shared int count = 0; } I thought shared is only for whole of the object. auto thr = new DerivedThread(); Here, "thr" is not shared but it's member thr.count is shared? But if it's not shared,

Re: Environment variable for application storage under OSX ?

2015-07-17 Thread FreeSlave via Digitalmars-d-learn
On Friday, 17 July 2015 at 07:33:43 UTC, Anonymous wrote: On Friday, 17 July 2015 at 07:14:24 UTC, FreeSlave wrote: On Thursday, 16 July 2015 at 21:12:05 UTC, anonymous wrote: I have the following code, working under Win and Linux: --- import std.process: environment; immutable string p; sta

Infinite range of nullable elements

2015-07-17 Thread Roland Hadinger via Digitalmars-d-learn
At this moment I'm tempted to implement a function taking a range of elements E and returning an infinite range of Nullable!E. With this function ("cushion" for a lack of better name) I could do: auto a = [0,1,2,3,4,5,6,7,8,9]; foreach (e ; a.cushion.take(20)) writeln(e); //

Re: Environment variable for application storage under OSX ?

2015-07-17 Thread Anonymous via Digitalmars-d-learn
On Friday, 17 July 2015 at 07:14:24 UTC, FreeSlave wrote: On Thursday, 16 July 2015 at 21:12:05 UTC, anonymous wrote: I have the following code, working under Win and Linux: --- import std.process: environment; immutable string p; static this() { version(Win32) p = environment.get("APPDAT

Re: Environment variable for application storage under OSX ?

2015-07-17 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 16 July 2015 at 21:12:05 UTC, anonymous wrote: I have the following code, working under Win and Linux: --- import std.process: environment; immutable string p; static this() { version(Win32) p = environment.get("APPDATA"); version(linux) p = "/home/" ~ environment.get("USE