Re: A couple of questions about arrays and slices

2023-06-24 Thread Cecil Ward via Digitalmars-d-learn
On Saturday, 24 June 2023 at 16:42:45 UTC, Cecil Ward wrote: On Saturday, 24 June 2023 at 15:12:14 UTC, Jonathan M Davis wrote: [...] Yeah, it would take me forever to get my head around that, and I only want a crude toy partial parser for certain portions of the grammar, and the parsing cod

Re: A couple of questions about arrays and slices

2023-06-24 Thread Cecil Ward via Digitalmars-d-learn
On Saturday, 24 June 2023 at 15:12:14 UTC, Jonathan M Davis wrote: On Saturday, June 24, 2023 8:43:00 AM MDT Cecil Ward via Digitalmars-d-learn wrote: I started out looking into a number of runtime library routines, but in the end it seemed quicker to roll my own code for a crude recursive desc

Re: A couple of questions about arrays and slices

2023-06-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, June 24, 2023 8:43:00 AM MDT Cecil Ward via Digitalmars-d-learn wrote: > I started out looking into a number of runtime library routines, > but in the end it seemed quicker to roll my own code for a crude > recursive descent parser/lexer that parses part of D’s grammar > for expressio

Re: A couple of questions about arrays and slices

2023-06-24 Thread Cecil Ward via Digitalmars-d-learn
On Saturday, 24 June 2023 at 12:05:26 UTC, Jonathan M Davis wrote: On Saturday, June 24, 2023 1:43:53 AM MDT Cecil Ward via Digitalmars-d-learn wrote: On Saturday, 24 June 2023 at 07:36:26 UTC, Cecil Ward wrote: > [...] I just realised something, your point about altering the table and having

Re: A couple of questions about arrays and slices

2023-06-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, June 24, 2023 1:43:53 AM MDT Cecil Ward via Digitalmars-d-learn wrote: > On Saturday, 24 June 2023 at 07:36:26 UTC, Cecil Ward wrote: > > Jonathan, is it possible that I wanted one thing and got > > another? My description in the earlier post was of the _aim_ of > > the program. What

Re: A couple of questions about arrays and slices

2023-06-24 Thread Cecil Ward via Digitalmars-d-learn
On Saturday, 24 June 2023 at 07:36:26 UTC, Cecil Ward wrote: Jonathan, is it possible that I wanted one thing and got another? My description in the earlier post was of the _aim_ of the program. What I ended up with might be something else? I wanted an array of uints whose values are the result

Re: A couple of questions about arrays and slices

2023-06-24 Thread Cecil Ward via Digitalmars-d-learn
On Saturday, 24 June 2023 at 01:28:03 UTC, Jonathan M Davis wrote: On Friday, June 23, 2023 7:02:12 PM MDT Cecil Ward via Digitalmars-d-learn wrote: I just had a fight with LDC over the following code when I tried out reserve. I have an associative array that maps strings to ‘ordinals’ ie uints

Re: A couple of questions about arrays and slices

2023-06-24 Thread Ali Çehreli via Digitalmars-d-learn
On 6/20/23 19:09, Cecil Ward wrote: > 2.) I have a dynamic array and I wish to preinitialise its alloc cell to > be a certain large size so that I don’t need to reallocate often To be complete, 'assumeSafeAppend' must be mentioned here as well. Without it, there will be cases where the GC canno

Re: A couple of questions about arrays and slices

2023-06-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, June 23, 2023 7:02:12 PM MDT Cecil Ward via Digitalmars-d-learn wrote: > I just had a fight with LDC over the following code when I tried > out reserve. I have an associative array that maps strings to > ‘ordinals’ ie uints that are unique, and the compiler hates the > call to reserve.

Re: A couple of questions about arrays and slices

2023-06-23 Thread Cecil Ward via Digitalmars-d-learn
On Thursday, 22 June 2023 at 05:21:52 UTC, Cecil Ward wrote: On Thursday, 22 June 2023 at 01:44:22 UTC, Jonathan M Davis wrote: On Wednesday, June 21, 2023 7:05:28 PM MDT Paul Backus via Digitalmars-d-learn wrote: [...] To add to that, it _has_ to know the element type, because aside from an

Re: A couple of questions about arrays and slices

2023-06-21 Thread Cecil Ward via Digitalmars-d-learn
On Thursday, 22 June 2023 at 01:44:22 UTC, Jonathan M Davis wrote: On Wednesday, June 21, 2023 7:05:28 PM MDT Paul Backus via Digitalmars-d-learn wrote: [...] To add to that, it _has_ to know the element type, because aside from anything related to a type's size, it bit-blits the type's init

Re: A couple of questions about arrays and slices

2023-06-21 Thread Cecil Ward via Digitalmars-d-learn
On Thursday, 22 June 2023 at 01:05:28 UTC, Paul Backus wrote: On Thursday, 22 June 2023 at 00:10:19 UTC, Cecil Ward wrote: Is .reserve()’s argument scaled by the entry size after it is supplied, that is it is quoted in elements or is it in bytes? I’m not sure whether the runtime has a knowledge

Re: A couple of questions about arrays and slices

2023-06-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, June 21, 2023 7:05:28 PM MDT Paul Backus via Digitalmars-d-learn wrote: > On Thursday, 22 June 2023 at 00:10:19 UTC, Cecil Ward wrote: > > Is .reserve()’s argument scaled by the entry size after it is > > supplied, that is it is quoted in elements or is it in bytes? > > I’m not sure

Re: A couple of questions about arrays and slices

2023-06-21 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 22 June 2023 at 00:10:19 UTC, Cecil Ward wrote: Is .reserve()’s argument scaled by the entry size after it is supplied, that is it is quoted in elements or is it in bytes? I’m not sure whether the runtime has a knowledge of the element type so maybe it doesn’t know anything about s

Re: A couple of questions about arrays and slices

2023-06-21 Thread Cecil Ward via Digitalmars-d-learn
On Wednesday, 21 June 2023 at 15:48:56 UTC, H. S. Teoh wrote: On Wed, Jun 21, 2023 at 02:09:26AM +, Cecil Ward via Digitalmars-d-learn wrote: First is an easy one: 1.) I have a large array and a sub-slice which I want to set up to be pointing into a sub-range of it. What do I write if I k

Re: A couple of questions about arrays and slices

2023-06-21 Thread Cecil Ward via Digitalmars-d-learn
On Wednesday, 21 June 2023 at 04:52:06 UTC, Jonathan M Davis wrote: On Tuesday, June 20, 2023 8:09:26 PM MDT Cecil Ward via Digitalmars-d-learn wrote: [...] When slicing, the end index is exclusive. e.g. [...] Actually concerning the garbage, I was rather hoping that it _would_ be garbage

Re: A couple of questions about arrays and slices

2023-06-21 Thread Cecil Ward via Digitalmars-d-learn
On Wednesday, 21 June 2023 at 04:52:06 UTC, Jonathan M Davis wrote: On Tuesday, June 20, 2023 8:09:26 PM MDT Cecil Ward via Digitalmars-d-learn wrote: [...] When slicing, the end index is exclusive. e.g. [...] Thankyou to both posters for your exceptionally helpful and generous replies, wh

Re: A couple of questions about arrays and slices

2023-06-21 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 21, 2023 at 02:09:26AM +, Cecil Ward via Digitalmars-d-learn wrote: > First is an easy one: > > 1.) I have a large array and a sub-slice which I want to set up to be > pointing into a sub-range of it. What do I write if I know the start > and end indices ? Concerned about an off-b

Re: A couple of questions about arrays and slices

2023-06-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, June 20, 2023 8:09:26 PM MDT Cecil Ward via Digitalmars-d-learn wrote: > First is an easy one: > > 1.) I have a large array and a sub-slice which I want to set up > to be pointing into a sub-range of it. What do I write if I know > the start and end indices ? Concerned about an off-by-

A couple of questions about arrays and slices

2023-06-20 Thread Cecil Ward via Digitalmars-d-learn
First is an easy one: 1.) I have a large array and a sub-slice which I want to set up to be pointing into a sub-range of it. What do I write if I know the start and end indices ? Concerned about an off-by-one error, I have start_index and past_end_index (exclusive). 2.) I have a dynamic arra

Re: A couple of questions

2009-05-13 Thread Sam Hu
Hi All, Thank you so much! It really helps! Regards, Sam

Re: A couple of questions

2009-05-13 Thread Robert Fraser
Simen Kjaeraas wrote: Sam Huwrote: Q4.In the delegate somFnExp:front(),popFront,empty() are all not defined??Anyway it is not an interface ,so why it is allowed? Basically, is(typeof(X)) is D magic. One could interpret it as 'is X a valid type', or perhaps more correctly as 'does X compile'.

Re: A couple of questions

2009-05-13 Thread Simen Kjaeraas
Sam Huwrote: Q4.In the delegate somFnExp:front(),popFront,empty() are all not defined??Anyway it is not an interface ,so why it is allowed? Basically, is(typeof(X)) is D magic. One could interpret it as 'is X a valid type', or perhaps more correctly as 'does X compile'. So if SomeFnExp does

Re: A couple of questions

2009-05-13 Thread John C
Sam Hu Wrote: > Thanks.The construct is clear now. > > Still leaves Q1,that is ,the *if* expression after the template definition,I > want to learn more about the usage,where can I find more information? It is in the spec: http://www.digitalmars.com/d/2.0/template.html#Constraint

Re: A couple of questions

2009-05-13 Thread Sam Hu
Thanks.The construct is clear now. Still leaves Q1,that is ,the *if* expression after the template definition,I want to learn more about the usage,where can I find more information? and one more question here: Q4.In the delegate somFnExp:front(),popFront,empty() are all not defined??Anyway it i

Re: A couple of questions

2009-05-12 Thread BCS
Hello Sam, Hello, For the given example below, E1: template Chain(R...) if (allSatisfy!(isInputRange, R)) { static if (R.length > 1) alias ChainImpl!(R) Chain; else alias R[0] Chain; } Q1: What's *if* statement doing right after the template definite?I can guess what the purpose is but I can n

A couple of questions

2009-05-12 Thread Sam Hu
Hello, For the given example below, E1: template Chain(R...) if (allSatisfy!(isInputRange, R)) { static if (R.length > 1) alias ChainImpl!(R) Chain; else alias R[0] Chain; } Q1: What's *if* statement doing right after the template definite?I can guess what the purpose is