Re: D ASM. Program fails

2016-01-22 Thread anonymous via Digitalmars-d-learn
On 22.01.2016 21:34, Iakh wrote: This code returns 0 for any input v It seems to return 5 here: http://dpaste.dzfl.pl/85fb8e5c4b6b

Re: D ASM. Program fails

2016-01-22 Thread Iakh via Digitalmars-d-learn
On Friday, 22 January 2016 at 17:27:35 UTC, userABCabc123 wrote: int pmovmskb(byte16 v) { asm { naked; push RBP; mov RBP, RSP; sub RSP, 0x10; movdqa dword ptr[RBP-0x10], XMM0; movdqa XMM0, dword ptr[RBP-0x10]; pmovmskb EAX, XMM0;

Re: D ASM. Program fails

2016-01-22 Thread Iakh via Digitalmars-d-learn
On Friday, 22 January 2016 at 12:18:53 UTC, anonymous wrote: int pmovmskb(byte16 v) { int r; asm { movdqa XMM0, v; pmovmskb EAX, XMM0; mov r, EAX; } return r; } This code returns 0 for any input v Removed the `inout` because it doesn't

Re: D ASM. Program fails

2016-01-22 Thread Iakh via Digitalmars-d-learn
On Friday, 22 January 2016 at 20:41:23 UTC, anonymous wrote: On 22.01.2016 21:34, Iakh wrote: This code returns 0 for any input v It seems to return 5 here: http://dpaste.dzfl.pl/85fb8e5c4b6b Yeah. Sorry. My bad.

Re: Speed of csvReader

2016-01-22 Thread data pulverizer via Digitalmars-d-learn
On Friday, 22 January 2016 at 02:16:14 UTC, H. S. Teoh wrote: On Thu, Jan 21, 2016 at 04:50:12PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > > https://github.com/quickfur/fastcsv [...] Fixed some boundary condition crashes and reverted doubled quote handling in unquoted

Re: Is memory-safe IO possible?

2016-01-22 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 22, 2016 at 11:15:58AM -0800, Brad Roberts via Digitalmars-d-learn wrote: > On 1/22/2016 9:10 AM, Chris Wright via Digitalmars-d-learn wrote: > >On Fri, 22 Jan 2016 08:36:14 +, Kagamin wrote: > > > >>Should be possible. Why not? > > > >Because almost no IO routines in Phobos are

Re: Is memory-safe IO possible?

2016-01-22 Thread Brad Roberts via Digitalmars-d-learn
On 1/22/2016 9:10 AM, Chris Wright via Digitalmars-d-learn wrote: On Fri, 22 Jan 2016 08:36:14 +, Kagamin wrote: Should be possible. Why not? Because almost no IO routines in Phobos are marked @safe, which implies that it's difficult in practice or that people simply haven't done it. I

Re: Template specialization

2016-01-22 Thread Ali Çehreli via Digitalmars-d-learn
On 01/22/2016 07:41 AM, Darrell Gallion wrote: Defining the template [specializations] within another function, fails. Reported: https://issues.dlang.org/show_bug.cgi?id=15592 Ali

`static` symbol needs to be `immutable` for compile-time access?

2016-01-22 Thread Shriramana Sharma via Digitalmars-d-learn
Hello. This is a minimal abstraction of a part of my program: int func(string s) { static int [] i = [5, 6, 7]; return i[2]; } template temp(string s) { enum temp = func(s); } void main() { static assert(temp!"str" == 7); } With the above code I get: (4): Error: static variable i cannot

Re: `static` symbol needs to be `immutable` for compile-time access?

2016-01-22 Thread Kagamin via Digitalmars-d-learn
Why do you declare mutable constants?

Re: New forum mobile appearance feedback

2016-01-22 Thread Kagamin via Digitalmars-d-learn
On Friday, 22 January 2016 at 10:12:31 UTC, JR wrote: (This holds for the normal desktop too, to a certain subjective extent.) The feedback thread is https://forum.dlang.org/post/bmjujolcjxcabshiw...@forum.dlang.org I find padding and font size ok on desktop:

Re: How to represent struct with trailing array member

2016-01-22 Thread userABCabc123 via Digitalmars-d-learn
On Friday, 22 January 2016 at 08:39:06 UTC, Dibyendu Majumdar wrote: On Friday, 22 January 2016 at 01:53:53 UTC, Chris Wright wrote: On Thu, 21 Jan 2016 21:52:06 +, Dibyendu Majumdar wrote: Hi I have C code where the struct has a trailing array member: struct matrix { int rows;

New forum mobile appearance feedback

2016-01-22 Thread JR via Digitalmars-d-learn
Unsure where else to post this, since it feels like it would intrude on the more serious discussions in the main D forum. The new forum design is overall great, but it really doesn't work well on mobile devices. Coupled with field padding the font is simply too large. (This holds for the

Re: Grouping variadic parameter tuples on offset and stride

2016-01-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 21 January 2016 at 22:35:09 UTC, H. S. Teoh wrote: Try this: import std.meta; template Stride(size_t stride, size_t offset, Args...) if (stride > 0) { static if (offset >= Args.length) alias Stride = AliasSeq!();

Re: Speed of csvReader

2016-01-22 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Friday, 22 January 2016 at 02:16:14 UTC, H. S. Teoh wrote: On Thu, Jan 21, 2016 at 04:50:12PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > > https://github.com/quickfur/fastcsv [...] Fixed some boundary condition crashes and reverted doubled quote handling in unquoted

Re: Disabling GC in D

2016-01-22 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Friday, 22 January 2016 at 05:15:13 UTC, Mike Parker wrote: On Thursday, 21 January 2016 at 23:06:55 UTC, Dibyendu Majumdar wrote: On Thursday, 21 January 2016 at 22:44:14 UTC, H. S. Teoh wrote: Hi - I want to be sure that my code is not allocating memory via the GC allocator; but when

Re: `static` symbol needs to be `immutable` for compile-time access?

2016-01-22 Thread Mike Parker via Digitalmars-d-learn
On Friday, 22 January 2016 at 09:56:27 UTC, Shriramana Sharma wrote: In C/C++ the `static` here is used to avoid the array being created every time the function is entered; in D too it does the same thing, no? So if I have an array of constants in a function that I need to be accessible to a

Re: why the sort result is different with C#

2016-01-22 Thread mzfhhhh via Digitalmars-d-learn
i know the reason,C# have several compares methods. String.Compare , String.CompareOrdinal //now the output is same as the D code Array.Sort(arr, string.CompareOrdinal);

Re: Speed of csvReader

2016-01-22 Thread data pulverizer via Digitalmars-d-learn
On Friday, 22 January 2016 at 21:41:46 UTC, data pulverizer wrote: On Friday, 22 January 2016 at 02:16:14 UTC, H. S. Teoh wrote: [...] Hi H. S. Teoh, I have used you fastcsv on my file: import std.file; import fastcsv; import std.stdio; import std.datetime; void main(){ StopWatch sw;

Shared library question

2016-01-22 Thread Dibyendu Majumdar via Digitalmars-d-learn
Hi I am trying to create a simple shared library that exports a D function, but when I try to link to it I get errors such as: error LNK2001: unresolved external symbol _D7xxx12__ModuleInfoZ Here xxx is the module inside the shared library. I am using DMD and MS LINKER (Windows 64-bit) to

Re: Create an empty json object with std.json

2016-01-22 Thread Borislav Kosharov via Digitalmars-d-learn
On Friday, 22 January 2016 at 11:53:11 UTC, Andrea Fontana wrote: If you declare a JSONValue like this: JSONValue json; then: assert(json.type() == JSON_TYPE.NULL); Documentation at https://dlang.org/phobos/std_json.html#.JSONValue.type.2 suggests not to change type but to assign a new

Re: D ASM. Program fails

2016-01-22 Thread userABCabc123 via Digitalmars-d-learn
On Friday, 22 January 2016 at 20:54:46 UTC, Iakh wrote: On Friday, 22 January 2016 at 17:27:35 UTC, userABCabc123 wrote: [...] Thanks. It works. Buth shorter version too: asm { naked; push RBP; mov

Re: Is memory-safe IO possible?

2016-01-22 Thread Kagamin via Digitalmars-d-learn
Should be possible. Why not?

Re: How to represent struct with trailing array member

2016-01-22 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Friday, 22 January 2016 at 01:53:53 UTC, Chris Wright wrote: On Thu, 21 Jan 2016 21:52:06 +, Dibyendu Majumdar wrote: Hi I have C code where the struct has a trailing array member: struct matrix { int rows; int cols; double data[1]; }; D has bounds checking, which makes this

Re: DUB, Platform specifications and dependencies

2016-01-22 Thread Luis via Digitalmars-d-learn
On Monday, 30 November 2015 at 20:27:51 UTC, Zardoz wrote: On Monday, 30 November 2015 at 16:54:43 UTC, Sönke Ludwig wrote: Am 24.11.2015 um 19:51 schrieb Zardoz: Platform specifications are currently not supported for dependencies due to the way the dependency resolver works. However, it is

Re: why the sort result is different with C#

2016-01-22 Thread arturg via Digitalmars-d-learn
On Friday, 22 January 2016 at 06:53:29 UTC, mzf wrote: D code: auto arr = ["b1=1", "b=2","a1=1", "a=2"]; writeln(arr.sort()); output:["a1=1", "a=2", "b1=1", "b=2"] C# code: var arr = new string[]{ "b1=1", "b=2", "a1=1", "a=2" }; Array.Sort(arr); output:["a=2","a1=1","b=2","b1=1"] auto

Re: why the sort result is different with C#

2016-01-22 Thread Luis via Digitalmars-d-learn
On Friday, 22 January 2016 at 06:53:29 UTC, mzf wrote: D code: auto arr = ["b1=1", "b=2","a1=1", "a=2"]; writeln(arr.sort()); output:["a1=1", "a=2", "b1=1", "b=2"] C# code: var arr = new string[]{ "b1=1", "b=2", "a1=1", "a=2" }; Array.Sort(arr); output:["a=2","a1=1","b=2","b1=1"] I

Re: `static` symbol needs to be `immutable` for compile-time access?

2016-01-22 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 22 January 2016 at 10:15:19 UTC, Mike Parker wrote: A static variable is still a runtime variable. It's effectively the same as declaring a variable outside of the function scope at module scope, except that it's visible only in the current scope and the function name gets mangled

Collapsing n-dimensional array to linear (1 dimensional)

2016-01-22 Thread abad via Digitalmars-d-learn
Let's say I have an array like this: int[][][] array; And I want to generate a linear int[] based on its data. Is there a standard library method for achieving this, or must I iterate over the array manually? What I'm thinking of is something like this: int[] onedim =

Re: Create an empty json object with std.json

2016-01-22 Thread userABCabc123 via Digitalmars-d-learn
On Friday, 22 January 2016 at 11:53:11 UTC, Andrea Fontana wrote: If you declare a JSONValue like this: JSONValue json; then: assert(json.type() == JSON_TYPE.NULL); Documentation at https://dlang.org/phobos/std_json.html#.JSONValue.type.2 suggests not to change type but to assign a new

Create an empty json object with std.json

2016-01-22 Thread Andrea Fontana via Digitalmars-d-learn
If you declare a JSONValue like this: JSONValue json; then: assert(json.type() == JSON_TYPE.NULL); Documentation at https://dlang.org/phobos/std_json.html#.JSONValue.type.2 suggests not to change type but to assign a new value instead. My problem is: how can I assign an empty object like

Re: D ASM. Program fails

2016-01-22 Thread anonymous via Digitalmars-d-learn
On 22.01.2016 06:59, Iakh wrote: import std.stdio; import core.simd; int pmovmskb(inout byte16 v) { asm { movdqa XMM0, v; pmovmskb EAX, XMM0; ret; } } void main() { byte16 a = [-1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; auto i =

Re: writeln wipes contents of variables ?

2016-01-22 Thread W.J. via Digitalmars-d-learn
On Friday, 22 January 2016 at 01:47:19 UTC, Rikki Cattermole wrote: Contrary to what it is called in the links, this is a NewsGroup/Mailing list and not a forum. So no editing ability :) I'll keep that in mind. Thanks :)

Re: Create an empty json object with std.json

2016-01-22 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 22 January 2016 at 12:05:48 UTC, userABCabc123 wrote: when you add the first key, the value will be set to JSON_TYPE.OBJECT import std.json; void main(string[] args) { JSONValue json; json["first"] = 0; assert(json.type == JSON_TYPE.OBJECT); } That's right,

Re: Collapsing n-dimensional array to linear (1 dimensional)

2016-01-22 Thread NX via Digitalmars-d-learn
On Friday, 22 January 2016 at 12:07:11 UTC, abad wrote: Let's say I have an array like this: int[][][] array; And I want to generate a linear int[] based on its data. Is there a standard library method for achieving this, or must I iterate over the array manually? What I'm thinking of is

Re: Template specialization

2016-01-22 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 22 January 2016 at 01:33:42 UTC, Darrell Gallion wrote: void foo(A)() if (!is (A == int)) { pragma(msg, "int"); } void foo(A)() if (is (A == int[])) { pragma(msg, "int[]"); } void main() { foo!(int)(); foo!(int[])(); } === source\app.d(15):

Re: writeln wipes contents of variables ?

2016-01-22 Thread W.J. via Digitalmars-d-learn
On Friday, 22 January 2016 at 01:49:58 UTC, anonymous wrote: On 22.01.2016 01:49, W.J. wrote: How can I identify those ranges, or, how can I tell if any particular range has value semantics ? I didn't read any of this in the manual - not that I could remember anyways. Generally you

Re: `static` symbol needs to be `immutable` for compile-time access?

2016-01-22 Thread anonymous via Digitalmars-d-learn
On 22.01.2016 10:56, Shriramana Sharma wrote: Do all values which need to be readable at compile time need to be declared `immutable`? Yes, `static immutable` or `enum`. In C/C++ the `static` here is used to avoid the array being created every time the function is entered; in D too it does

Re: Template specialization

2016-01-22 Thread Darrell Gallion via Digitalmars-d-learn
On Friday, 22 January 2016 at 11:23:56 UTC, Marc Schütz wrote: On Friday, 22 January 2016 at 01:33:42 UTC, Darrell Gallion wrote: void foo(A)() if (!is (A == int)) { pragma(msg, "int"); } void foo(A)() if (is (A == int[])) { pragma(msg, "int[]"); } void main() {

Re: Shared library question

2016-01-22 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Friday, 22 January 2016 at 22:06:35 UTC, Dibyendu Majumdar wrote: Hi I am trying to create a simple shared library that exports a D function, but when I try to link to it I get errors such as: error LNK2001: unresolved external symbol _D7xxx12__ModuleInfoZ I have uploaded my small

Possible to get Class of Interface at runtime

2016-01-22 Thread Josh Phillips via Digitalmars-d-learn
If I have: interface A {} class B : A {} void printClass(A obj){ // Code here } Is there any way that I can find out what class obj is inside of printClass? I know I can cast and check if(cast(B)obj) but I want to just be able to do something along the lines of obj.class. I can think of

Re: Possible to get Class of Interface at runtime

2016-01-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 22 January 2016 at 23:38:58 UTC, Josh Phillips wrote: Is there any way that I can find out what class obj is inside of printClass? There's a .classinfo property that works on Objects. If you have an interface, cast to Object first, and check for null, then get .classinfo off that.

Re: Is memory-safe IO possible?

2016-01-22 Thread Chris Wright via Digitalmars-d-learn
On Fri, 22 Jan 2016 11:38:51 -0800, H. S. Teoh via Digitalmars-d-learn wrote: > @safe still isn't quite there yet, because it doesn't quite prevent all > of the things it ought to prevent. Well, that makes it suboptimal, certainly. But having almost no existing IO options that are @safe makes it

Re: Speed of csvReader

2016-01-22 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 22, 2016 at 10:04:58PM +, data pulverizer via Digitalmars-d-learn wrote: [...] > >$ dmd file_read_5.d fastcsv.d > >$ ./file_read_5 > >Time (s): 0.679 > > > >Fastest so far, very nice. Thanks! > I guess the next step is allowing Tuple rows with mixed types. I thought about that

Re: Template specialization

2016-01-22 Thread Darrell Gallion via Digitalmars-d-learn
On Friday, 22 January 2016 at 13:03:52 UTC, Darrell Gallion wrote: On Friday, 22 January 2016 at 11:23:56 UTC, Marc Schütz wrote: On Friday, 22 January 2016 at 01:33:42 UTC, Darrell Gallion wrote: void foo(A)() if (!is (A == int)) { pragma(msg, "int"); } void foo(A)() if

Re: Create an empty json object with std.json

2016-01-22 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 22 January 2016 at 16:45:22 UTC, userABCabc123 wrote: But soon or later you'll need to add values to your object so just imagine it's already an object, even if it will only become one when you'll start to add some values. You're wrong, I need an empty object for an API call!

Re: Is memory-safe IO possible?

2016-01-22 Thread Chris Wright via Digitalmars-d-learn
On Fri, 22 Jan 2016 08:36:14 +, Kagamin wrote: > Should be possible. Why not? Because almost no IO routines in Phobos are marked @safe, which implies that it's difficult in practice or that people simply haven't done it. I checked std.file, std.net.curl, and std.stdio; a handful of things

Re: D ASM. Program fails

2016-01-22 Thread userABCabc123 via Digitalmars-d-learn
On Friday, 22 January 2016 at 14:06:42 UTC, Adam D. Ruppe wrote: On Friday, 22 January 2016 at 12:18:53 UTC, anonymous wrote: I don't know much about these things, but it seems to be the `ret;`. Right. This is an ordinary D function so the compiler generates code to set up a stack for local

Re: function argument accepting function or delegate?

2016-01-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/17/16 1:27 AM, Jon D wrote: My underlying question is how to compose functions taking functions as arguments, while allowing the caller the flexibility to pass either a function or delegate. Simply declaring an argument as either a function or delegate seems to prohibit the other.

Re: D ASM. Program fails

2016-01-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 22 January 2016 at 12:18:53 UTC, anonymous wrote: I don't know much about these things, but it seems to be the `ret;`. Right. This is an ordinary D function so the compiler generates code to set up a stack for local variables. It looks like: push ebp; mov ebp, esp; sub EBP,

Re: Collapsing n-dimensional array to linear (1 dimensional)

2016-01-22 Thread Xinok via Digitalmars-d-learn
On Friday, 22 January 2016 at 12:07:11 UTC, abad wrote: Let's say I have an array like this: int[][][] array; And I want to generate a linear int[] based on its data. Is there a standard library method for achieving this, or must I iterate over the array manually? What I'm thinking of is

Re: Error in DUB Package Page - how to notify the Editor?

2016-01-22 Thread userABCabc123 via Digitalmars-d-learn
On Friday, 22 January 2016 at 16:07:59 UTC, Martin Tschierschke wrote: What about the idea to allow discussion entries/threads to be linked to dub package entries? So they appear in DUB and in a additional section of this forum? So vibe.d for example comes with his own forum that is good,

Re: Create an empty json object with std.json

2016-01-22 Thread userABCabc123 via Digitalmars-d-learn
On Friday, 22 January 2016 at 12:54:38 UTC, Andrea Fontana wrote: On Friday, 22 January 2016 at 12:05:48 UTC, userABCabc123 wrote: when you add the first key, the value will be set to JSON_TYPE.OBJECT import std.json; void main(string[] args) { JSONValue json; json["first"] = 0;

Re: Speed of csvReader

2016-01-22 Thread Jesse Phillips via Digitalmars-d-learn
On Friday, 22 January 2016 at 01:36:40 UTC, cym13 wrote: On Friday, 22 January 2016 at 01:27:13 UTC, H. S. Teoh wrote: And now that you mention this, RFC-4180 does not allow doubled quotes in an unquoted field. I'll take that out of the code (it improves performance :-D). Right, re-reading

Re: htod question

2016-01-22 Thread Jacob Carlborg via Digitalmars-d-learn
On 2016-01-22 01:31, Dibyendu Majumdar wrote: I tried using htod but got errors as it could not handle the std C header files (Visual C++). How do people work around this? You could try DStep [1]. Although I'm not entirely sure if it works on Windows. It uses libclang, so if Clang can handle

Re: `static` symbol needs to be `immutable` for compile-time access?

2016-01-22 Thread Shriramana Sharma via Digitalmars-d-learn
Thanks to all who replied. anonymous wrote: >> Do all values which need to >> be readable at compile time need to be declared `immutable`? > > Yes, `static immutable` or `enum`. It would seem that in the case of arrays, the former is preferable to the latter, as per the para above this header:

Re: `static` symbol needs to be `immutable` for compile-time access?

2016-01-22 Thread anonymous via Digitalmars-d-learn
On 22.01.2016 15:33, Shriramana Sharma wrote: It would seem that in the case of arrays, the former is preferable to the latter, as per the para above this header: http://ddili.org/ders/d.en/const_and_immutable.html#ix_const_and_immutable.variable, %20immutable The link doesn't work for me,

Error in DUB Package Page - how to notify the Editor?

2016-01-22 Thread Martin Tschierschke via Digitalmars-d-learn
What about the idea to allow discussion entries/threads to be linked to dub package entries? So they appear in DUB and in a additional section of this forum? So vibe.d for example comes with his own forum that is good, but a solution for all would be nicer? So coming back to my first

Re: Linking C libraries with DMD

2016-01-22 Thread jmh530 via Digitalmars-d-learn
On Friday, 22 January 2016 at 04:43:52 UTC, Mike Parker wrote: [snip] Thanks again! Will review.

Re: D ASM. Program fails

2016-01-22 Thread userABCabc123 via Digitalmars-d-learn
On Friday, 22 January 2016 at 17:12:25 UTC, userABCabc123 wrote: Note that there is maybe a DMD codegen bug because the asm generated for the non naked version copy the result to the stack and then the stack to result but after pmovmskb it's already setup in EAX. 0044C580h push

Re: Create an empty json object with std.json

2016-01-22 Thread userABCabc123 via Digitalmars-d-learn
On Friday, 22 January 2016 at 16:58:51 UTC, Andrea Fontana wrote: On Friday, 22 January 2016 at 16:45:22 UTC, userABCabc123 wrote: But soon or later you'll need to add values to your object so just imagine it's already an object, even if it will only become one when you'll start to add some

Re: Template specialization

2016-01-22 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 22 January 2016 at 13:03:52 UTC, Darrell Gallion wrote: On Friday, 22 January 2016 at 11:23:56 UTC, Marc Schütz wrote: On Friday, 22 January 2016 at 01:33:42 UTC, Darrell Gallion wrote: void foo(A)() if (!is (A == int)) { pragma(msg, "int"); } void foo(A)() if

Re: Create an empty json object with std.json

2016-01-22 Thread Chris Wright via Digitalmars-d-learn
On Fri, 22 Jan 2016 17:34:58 +, userABCabc123 wrote: > It's true that it can be problematic, for example with an input > contract, or for subtyping a JSONValue as something like struct > JSONValueThatAlwayObject{}... > > But there is only 3 ways in std.json, from a literal, using the >

Re: Collapsing n-dimensional array to linear (1 dimensional)

2016-01-22 Thread Ilya via Digitalmars-d-learn
On Friday, 22 January 2016 at 12:07:11 UTC, abad wrote: Let's say I have an array like this: int[][][] array; And I want to generate a linear int[] based on its data. Is there a standard library method for achieving this, or must I iterate over the array manually? What I'm thinking of is