Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Andrew Edwards via Digitalmars-d-learn
On Thursday, 8 June 2017 at 04:15:12 UTC, Stanislav Blinov wrote: Earns you nothing? How about not performing an allocation and copy? Seen through the eyes of a complete beginner, this means absolutely nothing. Those are the eyes I am using as I'm reading a book and simply following the

The reason for SIGSEGV function pointer problem

2017-06-07 Thread Russel Winder via Digitalmars-d-learn
OK, so I have narrowed down my SIGSEGV problem to having no real idea how to do C function pointers in D code. So I have a callback function that will be called from C library code. It currently has signature: extern(C) int checkFrontend(void* _arguments, dvb_v5_fe_parms*

Re: The reason for SIGSEGV function pointer problem

2017-06-07 Thread Paolo Invernizzi via Digitalmars-d-learn
On Wednesday, 7 June 2017 at 16:50:26 UTC, Russel Winder wrote: In the constructor of an object to abstract the result of a call to the C library code, the parameter is: check_frontend_t* cf You should remove the pointer here... /Paolo

Re: Can assumeSafeAppend() grab more and more capacity?

2017-06-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, June 07, 2017 07:43:06 ag0aep6g via Digitalmars-d-learn wrote: > You understand the spec to say that because `foo.capacity` is 15 at one > point, you should then be able to put 15 elements into `foo` without > relocation. And what `bar` does in the meantime shouldn't matter. > > I

Re: [Solved] Confusing error message

2017-06-07 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 7 June 2017 at 14:58:26 UTC, drug wrote: 07.06.2017 16:27, Wulfklaue пишет: Some of the dmd error messages need some tweaking. import std.datetime; auto t = Clock.currStdTime; writeln(to!string(t)); Result in: Error: template core.time.to cannot deduce function from

Re: rawRead using a struct with variable leght

2017-06-07 Thread ade90036 via Digitalmars-d-learn
On Monday, 5 June 2017 at 16:30:53 UTC, Era Scarecrow wrote: On Monday, 5 June 2017 at 16:04:28 UTC, ade90036 wrote: Unfortunately the struct doesn't know at compile time what the size of the constant_pool array, or at-least was not able to specify it dynamically. It also won't know ahead

Re: The reason for SIGSEGV function pointer problem

2017-06-07 Thread Mike Wey via Digitalmars-d-learn
On 06/07/2017 06:50 PM, Russel Winder via Digitalmars-d-learn wrote: So why isn't a thing of type check_frontend_t* AFAIK, you would usually translate: typedef int (check_frontend_t*)(void *args, struct dvb_v5_fe_parms *parms); into: alias check_frontend_t = extern(C) int function (void*

Re: [Solved] Confusing error message

2017-06-07 Thread drug via Digitalmars-d-learn
07.06.2017 21:07, bachmeier пишет: On Wednesday, 7 June 2017 at 14:58:26 UTC, drug wrote: For me it's a good message. Messages like this were an annoyance when I started out. If you don't import std.stdio, you get the error message Error: 'writeln' is not defined, perhaps you need to

Re: Mutiple AliasSeq as input to template

2017-06-07 Thread David Sanders via Digitalmars-d-learn
On Thursday, 25 May 2017 at 17:56:12 UTC, jmh530 wrote: On Thursday, 25 May 2017 at 16:36:45 UTC, jmh530 wrote: [snip] I haven't played around with it fully, but it seems like the following resolves my issue in a sort of manual way: template Process1(A, B) { static if (!isIndex!B)

Re: rawRead using a struct with variable leght

2017-06-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 07, 2017 at 06:24:22PM +, ade90036 via Digitalmars-d-learn wrote: > On Monday, 5 June 2017 at 16:30:53 UTC, Era Scarecrow wrote: > > On Monday, 5 June 2017 at 16:04:28 UTC, ade90036 wrote: > > > > > Unfortunately the struct doesn't know at compile time what the > > > size of the

Re: import statement placement

2017-06-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 07, 2017 at 01:17:39PM +, Nicholas Wilson via Digitalmars-d-learn wrote: > On Wednesday, 7 June 2017 at 12:39:07 UTC, Russel Winder wrote: > > Are there any idiom rules as to where to put import statements in D? > > > > In Python they can go anywhere but PEP-8 suggests they

Re: The reason for SIGSEGV function pointer problem

2017-06-07 Thread ag0aep6g via Digitalmars-d-learn
On 06/07/2017 06:50 PM, Russel Winder via Digitalmars-d-learn wrote: So why isn't a thing of type check_frontend_t*? It's a thing of type `check_frontend_t`, which is a function pointer already. When you add an asterisk, you get a pointer to a function pointer.

Re: Can assumeSafeAppend() grab more and more capacity?

2017-06-07 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 7 June 2017 at 05:43:06 UTC, ag0aep6g wrote: [snip] It seems to me this is a topic worthy of a more in-depth article. If only I felt up to that. :p When you create a slice 'a' in D (with the current GC and druntime, at least), what happens behind the scenes is the allocator

Re: rawRead using a struct with variable leght

2017-06-07 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 7 June 2017 at 18:31:41 UTC, H. S. Teoh wrote: "Structs" with variable size fields have no direct equivalent in D's type system, so you'll probably have a hard time mapping this directly. What you *could* do, though, is to load the data into a ubyte[] buffer, then create a

Re: [Solved] Confusing error message

2017-06-07 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 7 June 2017 at 19:02:59 UTC, drug wrote: How do compiler know that you want use `std.conv.to` instead of _already imported_ `core.time.to`? In general it's impossible. There is no way for compiler to guess that you want some other symbol from out there. What if you've imported

Re: Can assumeSafeAppend() grab more and more capacity?

2017-06-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/7/17 3:56 AM, Biotronic wrote: On Wednesday, 7 June 2017 at 05:43:06 UTC, ag0aep6g wrote: [snip] It seems to me this is a topic worthy of a more in-depth article. If only I felt up to that. :p Your understanding and explanation is excellent actually! When you create a slice 'a' in D

Re: [Solved] Confusing error message

2017-06-07 Thread drug via Digitalmars-d-learn
07.06.2017 22:40, bachmeier пишет: On Wednesday, 7 June 2017 at 19:02:59 UTC, drug wrote: How do compiler know that you want use `std.conv.to` instead of _already imported_ `core.time.to`? In general it's impossible. There is no way for compiler to guess that you want some other symbol from

My DMD ~master build gives linker error and IDK why

2017-06-07 Thread Basile B. via Digitalmars-d-learn
This is my script: HOST_DMD=dmd MODEL=64 cd dmd make -fposix.mak MODEL=64 clean make -fposix.mak ENABLE_RELEASE=1 MODEL=64 DMD=../dmd/src/dmd -j 5 cd ../druntime make -fposix.mak MODEL=64 clean make -fposix.mak MODEL=64 DMD=../dmd/src/dmd -j 5 cd ../phobos make -fposix.mak MODEL=64 clean

Re: My DMD ~master build gives linker error and IDK why

2017-06-07 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 7 June 2017 at 09:50:41 UTC, Basile B. wrote: bla bla bla Actually it's this code: void main(string[] args) { import std.stdio; import std.compiler; writeln(vendor); } that gives the error. I suspect a regression.

Re: My DMD ~master build gives linker error and IDK why

2017-06-07 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 7 June 2017 at 09:55:24 UTC, Basile B. wrote: On Wednesday, 7 June 2017 at 09:50:41 UTC, Basile B. wrote: bla bla bla Actually it's this code: void main(string[] args) { import std.stdio; import std.compiler; writeln(vendor); } that gives the error. I suspect a

Re: [Solved] Confusing error message

2017-06-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 07, 2017 at 11:16:14PM +0300, drug via Digitalmars-d-learn wrote: > 07.06.2017 22:40, bachmeier пишет: [...] > > In any event, I made a second suggestion that would always work. If > > it can't find a match, it asks if you're missing an import > > statement, as a way to provide the new

import statement placement

2017-06-07 Thread Russel Winder via Digitalmars-d-learn
Are there any idiom rules as to where to put import statements in D? In Python they can go anywhere but PEP-8 suggests they should all go at the top of a file, just after the module documentation string. -- Russel. = Dr

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Mike B Johnson via Digitalmars-d-learn
On Thursday, 8 June 2017 at 01:57:47 UTC, Andrew Edwards wrote: If I hand you a chihuahua for grooming, why am I getting back a pit bull? I simply want a groomed chihuahua. Why do I need to consult a wizard to get back a groomed chihuahua? Because is like a poodle and unless you get your hair

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Andrew Edwards via Digitalmars-d-learn
On Thursday, 8 June 2017 at 02:07:07 UTC, Mike B Johnson wrote: On Thursday, 8 June 2017 at 01:57:47 UTC, Andrew Edwards wrote: If I hand you a chihuahua for grooming, why am I getting back a pit bull? I simply want a groomed chihuahua. Why do I need to consult a wizard to get back a groomed

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Andrew Edwards via Digitalmars-d-learn
On Thursday, 8 June 2017 at 02:19:15 UTC, Andrew Edwards wrote: Pretty funny. But seriously, this is something that just work. There is now to layers of indirection to achieve what I used to do quite naturally in the language. *should just work

Re: [Solved] Confusing error message

2017-06-07 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 7 June 2017 at 21:13:37 UTC, H. S. Teoh wrote: On Wed, Jun 07, 2017 at 11:16:14PM +0300, drug via Digitalmars-d-learn wrote: 07.06.2017 22:40, bachmeier пишет: [...] > In any event, I made a second suggestion that would always > work. If it can't find a match, it asks if you're

.sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Andrew Edwards via Digitalmars-d-learn
Ranges may be finite or infinite but, while the destination may be unreachable, we can definitely tell how far we've traveled. So why doesn't this work? import std.traits; import std.range; void main() { string[string] aa; // what others have referred to as // standard sort works

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Andrew Edwards via Digitalmars-d-learn
On Thursday, 8 June 2017 at 02:21:03 UTC, Stanislav Blinov wrote: aa.keys.sort() should just work as is: aa.keys returns a string[], and that's a random access range that can be sorted. What exactly is the error? It does not ... I provided the code and related error message. See the line

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 08, 2017 01:57:47 Andrew Edwards via Digitalmars-d-learn wrote: > Ranges may be finite or infinite but, while the destination may > be unreachable, we can definitely tell how far we've traveled. So > why doesn't this work? > > import std.traits; > import std.range; > > void

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 8 June 2017 at 01:57:47 UTC, Andrew Edwards wrote: Ranges may be finite or infinite but, while the destination may be unreachable, we can definitely tell how far we've traveled. So why doesn't this work? import std.traits; import std.range; void main() { string[string] aa;

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 8 June 2017 at 02:25:17 UTC, Jonathan M Davis wrote: Oh I see, the was error related to iteration, not sorting. Ranges do not support iterating with an index. The workaround if you want to have an index with ranges and foreach, then you should use lockstep:

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 08, 2017 02:31:43 Stanislav Blinov via Digitalmars-d-learn wrote: > On Thursday, 8 June 2017 at 02:25:17 UTC, Jonathan M Davis wrote: > > Oh I see, the was error related to iteration, not sorting. > > > Ranges do not support iterating with an index. The workaround > > if you

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Seb via Digitalmars-d-learn
On Thursday, 8 June 2017 at 01:57:47 UTC, Andrew Edwards wrote: Ranges may be finite or infinite but, while the destination may be unreachable, we can definitely tell how far we've traveled. So why doesn't this work? ... If I hand you a chihuahua for grooming, why am I getting back a pit

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Andrew Edwards via Digitalmars-d-learn
On Thursday, 8 June 2017 at 02:31:43 UTC, Stanislav Blinov wrote: On Thursday, 8 June 2017 at 02:25:17 UTC, Jonathan M Davis wrote: Oh I see, the was error related to iteration, not sorting. Ranges do not support iterating with an index. The workaround if you want to have an index with

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 8 June 2017 at 02:19:15 UTC, Andrew Edwards wrote: Pretty funny. But seriously, this is something that should just work. There is now to layers of indirection to achieve what I used to do quite naturally in the language. Hmmm while working on my recent sudoku solver using

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 08, 2017 03:15:11 Andrew Edwards via Digitalmars-d-learn wrote: > On Thursday, 8 June 2017 at 02:31:43 UTC, Stanislav Blinov wrote: > > On Thursday, 8 June 2017 at 02:25:17 UTC, Jonathan M Davis > > wrote: > > > > Oh I see, the was error related to iteration, not sorting. > > >

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Andrew Edwards via Digitalmars-d-learn
On Thursday, 8 June 2017 at 03:40:08 UTC, Jonathan M Davis wrote: On Thursday, June 08, 2017 03:15:11 Andrew Edwards via Digitalmars-d-learn wrote: I completely understand the differences between ranges and arrays... the thing is, I wasn't working with ranges but arrays instead. If sort

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 8 June 2017 at 04:07:22 UTC, Andrew Edwards wrote: On Thursday, 8 June 2017 at 03:40:08 UTC, Jonathan M Davis sort() returns a SortedRange so that other algorithms can know... Yes, I understand that. Again, using "std.range: release" earns me nothing more than I already get

Re: import statement placement

2017-06-07 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 7 June 2017 at 12:39:07 UTC, Russel Winder wrote: Are there any idiom rules as to where to put import statements in D? In Python they can go anywhere but PEP-8 suggests they should all go at the top of a file, just after the module documentation string. I don't know if there

Re: [Solved] Confusing error message

2017-06-07 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 7 June 2017 at 13:27:05 UTC, Wulfklaue wrote: Some of the dmd error messages need some tweaking. import std.datetime; auto t = Clock.currStdTime; writeln(to!string(t)); Result in: Error: template core.time.to cannot deduce function from argument types !(string)(long),

Re: import statement placement

2017-06-07 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 7 June 2017 at 12:39:07 UTC, Russel Winder wrote: Are there any idiom rules as to where to put import statements in D? In Python they can go anywhere but PEP-8 suggests they should all go at the top of a file, just after the module documentation string. Well for ones that

[Solved] Confusing error message

2017-06-07 Thread Wulfklaue via Digitalmars-d-learn
Some of the dmd error messages need some tweaking. import std.datetime; auto t = Clock.currStdTime; writeln(to!string(t)); Result in: Error: template core.time.to cannot deduce function from argument types !(string)(long), candidates are:

Re: Use template functions within mixin

2017-06-07 Thread Timoses via Digitalmars-d-learn
On Tuesday, 6 June 2017 at 18:08:52 UTC, Ali Çehreli wrote: Just import modules at local scopes. Here is something that works: void displayinfo(T)(T v) { import std.stdio : writefln; writefln("%08x", v); } void foo() { import std.meta : AliasSeq; enum value =

Re: [Solved] Confusing error message

2017-06-07 Thread drug via Digitalmars-d-learn
07.06.2017 16:27, Wulfklaue пишет: Some of the dmd error messages need some tweaking. import std.datetime; auto t = Clock.currStdTime; writeln(to!string(t)); Result in: Error: template core.time.to cannot deduce function from argument types !(string)(long), candidates are: