Use of range sequence set in D language

Source: Internet
Author: User

The D language Standard library explains the range in the following way:

Ranges generalize the concept of arrays,lists, or anything that involves sequential access

Meaning that the range summarizes the array, the list, or any concept that involves sequential access, let's call it a sequence set to differentiate between aggregate (iteration set) and sets (key-value set).

Package file RANGE.D

First, chain function

Concatenate several sequence sets into a sequence set.

ImportStd.stdio;ImportStd.range;intMain (string[] argv) {int[] A = [A.]; int[] B = [4,5,6]; Auto C=Chain (A, b); Writeln ("C Len:", c.length); Writeln ("C:", c); Writeln ("C type is:", typeID (c)); Writeln ("C[0]:", c[0]); Writeln ("C[3]:", c[3]); Writeln ("Items List:");    foreach (i;c) {writeln (i);    } readln (); return0;}

From the running results, chain is to concatenate two arrays into an object of type Std.range.chain (int[],int[]). Chain. The result type.

This single object can be handled using a foreach operation. You can also use the index to access, very good things, it looks like more than the IEnumerable function in C #, but the IEnumerable of the abstraction is higher, there is no requirement for sequential access and number of elements, only requires the ability to iterate, perhaps aggregate refers to the concept.

IEnumerable only requires the ability to enumerate elements, which is important, because many times, it is not necessary to require data to be in memory, such as access to database records, the data is probably not in memory, if there is a number of requirements, then the range is not very good processing database data access problems.

Therefore, range can only be called a sequence set, not an enumeration set, or an iteration set. The sequence set should also be a part of the iteration set, since range is one of the iteration sets, so how does he implement the foreach access? A question of value research.

Use of range sequence set in D language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.