August 06, 2022
On Friday, 5 August 2022 at 04:05:08 UTC, Salih Dincer wrote:
> On Thursday, 4 August 2022 at 22:54:42 UTC, pascal111 wrote:
>>
>> I didn't notice that all what we needs to pop a range forward is just a slice, yes, we don't need variable here.
>
> Ranges and Slices are not the same thing. Slicing an array is easy. This is a language possibility. For example, you need an incrementing variable for the Fibonacci Series.
>
> SDB@79

What!!! so where's ranges?! I thought slices of any array are ranges, and understood it like that, and also there's no data type called ranges, it's like if you are talking about Ghostly data type!
August 06, 2022
On Sat, Aug 06, 2022 at 03:37:32PM +0000, pascal111 via Digitalmars-d-learn wrote:
> On Friday, 5 August 2022 at 04:05:08 UTC, Salih Dincer wrote:
> > On Thursday, 4 August 2022 at 22:54:42 UTC, pascal111 wrote:
> > > 
> > > I didn't notice that all what we needs to pop a range forward is just a slice, yes, we don't need variable here.
> > 
> > Ranges and Slices are not the same thing. Slicing an array is easy. This is a language possibility. For example, you need an incrementing variable for the Fibonacci Series.
> > 
> > SDB@79
> 
> What!!! so where's ranges?! I thought slices of any array are ranges, and understood it like that, and also there's no data type called ranges, it's like if you are talking about Ghostly data type!

A range is any type that supports the Range API defined in std.range (i.e., .empty, .front, .popFront). For more explanations, read:

	http://www.informit.com/articles/printerfriendly.aspx?p=1407357&rll=1
	http://ddili.org/ders/d.en/ranges.html
	http://dconf.org/2015/talks/davis.html
	http://tour.dlang.org/tour/en/basics/ranges
	http://wiki.dlang.org/Component_programming_with_ranges


T

-- 
No! I'm not in denial!
August 06, 2022

On Saturday, 6 August 2022 at 15:37:32 UTC, pascal111 wrote:

>

On Friday, 5 August 2022 at 04:05:08 UTC, Salih Dincer wrote:

>

On Thursday, 4 August 2022 at 22:54:42 UTC, pascal111 wrote:

>

I didn't notice that all what we needs to pop a range forward is just a slice, yes, we don't need variable here.

Ranges and Slices are not the same thing. Slicing an array is easy. This is a language possibility. For example, you need an incrementing variable for the Fibonacci Series.

SDB@79

What!!! so where's ranges?! I thought slices of any array are ranges, and understood it like that, and also there's no data type called ranges, it's like if you are talking about Ghostly data type!

Well, that's very normal. Because as you work with ranges, you will understand better. Indeed, the slices (we can call it a dynamic array) feel like slice, don't they?

SDB@79

August 06, 2022

On Saturday, 6 August 2022 at 16:30:55 UTC, Salih Dincer wrote:

>

Indeed, the slices (we can call it a dynamic array) feel like slice, don't they?

Edit: Indeed, the slices feel like ranges, don't they?

Sorry...

SDB@79

August 06, 2022
On 8/6/22 09:33, Salih Dincer wrote:

> the slices feel like ranges, don't they?

Yes because they are ranges. :) (Maybe you meant they don't have range member functions, which is true.)

D's slices happen to be the most capable range kind: RandonAccessRange. All of the following operations are supported on them as long as one imports std.array (or std.range, which publicly does so):

- empty
- front
- popFront
- save
- back
- popBack
- indexed element access

Slices have the optional length property as well (i.e. hasLength).

Those operations are not supported by member functions but by free-standing functions.

Ali

August 06, 2022
On Saturday, 6 August 2022 at 15:54:57 UTC, H. S. Teoh wrote:
> On Sat, Aug 06, 2022 at 03:37:32PM +0000, pascal111 via Digitalmars-d-learn wrote:
>> On Friday, 5 August 2022 at 04:05:08 UTC, Salih Dincer wrote:
>> > On Thursday, 4 August 2022 at 22:54:42 UTC, pascal111 wrote:
>> > > [...]
>> > 
>> > Ranges and Slices are not the same thing. Slicing an array is easy. This is a language possibility. For example, you need an incrementing variable for the Fibonacci Series.
>> > 
>> > SDB@79
>> 
>> What!!! so where's ranges?! I thought slices of any array are ranges, and understood it like that, and also there's no data type called ranges, it's like if you are talking about Ghostly data type!
>
> A range is any type that supports the Range API defined in std.range (i.e., .empty, .front, .popFront). For more explanations, read:
>
> 	http://www.informit.com/articles/printerfriendly.aspx?p=1407357&rll=1
> 	http://ddili.org/ders/d.en/ranges.html
> 	http://dconf.org/2015/talks/davis.html
> 	http://tour.dlang.org/tour/en/basics/ranges
> 	http://wiki.dlang.org/Component_programming_with_ranges
>
>
> T

You know, the problem is that ranges in D lack the usage of pointers as an essential tool to make all of ranges functions they need. If ranges exist in C, they would use pointers, and this is a powerful point in the account of C.
August 06, 2022
On 8/6/22 14:10, pascal111 wrote:

> the problem is that ranges in D lack the usage of pointers as
> an essential tool to make all of ranges functions they need. If ranges
> exist in C, they would use pointers, and this is

There are a few cases where pointers provide functionality that ranges cannot:

1) Some algorithms don't make much sense with ranges. For example, most of the time find() can return just the element that we seek. In D, find() returns a range so that we can chain it with other algorithms.

2) Some algorithms like partition() better use three pointers.

Other than that, ranges are superior to pointers in every aspect. (I resent the fact that some C++ "experts" used those two points to decide ranges are inferior and helped deprive the C++ community of ranges for a very long time. The same "experts" did the same with 'static if'.)

> a powerful point in the account of C.

I missed how you made that connection.

Ali

August 07, 2022
On Saturday, 6 August 2022 at 17:29:30 UTC, Ali Çehreli wrote:
> On 8/6/22 09:33, Salih Dincer wrote:
>
> > the slices feel like ranges, don't they?
>
> Yes because they are ranges. :) (Maybe you meant they don't have range member functions, which is true.)

Slices use pointers.  Do I need to tell you what the pointers do!  Each of them points to a data.  Ranges are not like that, all they do is generate.  Ok, you use a slice just as if it were a range.  But they are not ranges.

SDB@79
August 07, 2022
On Sunday, 7 August 2022 at 05:12:38 UTC, Ali Çehreli wrote:
> On 8/6/22 14:10, pascal111 wrote:
>

> > a powerful point in the account of C.
>
> I missed how you made that connection.
>
Everyone knows that slices are not pointers that pointers are real work, but slices are like a simple un-deep technique that is appropriate for beginners, but after that in advanced level in programming, we should use pointers to do same tasks we were doing with slices (the easy way of beginners).


August 07, 2022

On Sunday, 7 August 2022 at 15:34:19 UTC, pascal111 wrote:

>

Everyone knows that slices are not pointers that pointers are real work, but slices are like a simple un-deep technique that is appropriate for beginners, but after that in advanced level in programming, we should use pointers to do same tasks we were doing with slices (the easy way of beginners).

The following information about slices may be helpful:

>

Slices are objects from type T[] for any given type T. Slices provide a view on a subset of an array of T values - or just point to the whole array. Slices and dynamic arrays are the same.

A slice consists of two members - a pointer to the starting element and the length of the slice:

T* ptr;
size_t length; // unsigned 32 bit on 32bit, unsigned 64 bit on 64bit

[...]
Source: https://tour.dlang.org/tour/en/basics/slices

SDB@79