Is there a difference between iterable and enumerable?

Many languages seem to have structures that are very similar called iterable or enumerable. These are structures that can be iterated or enumerated over, which seem to me extremely similar things. Are these words synonymous or is there a subtle semantic difference between iterable and enumerable which justifies the choice of term?

1

IMHO this depends on the context, sometimes they are synonymous, sometimes they are not. For example, in C# you have a data type “IEnumerable”, which classifies iterators, but you have also the “enum” declaration which is for symbolic constants, not specificially for iterations. In other programming languages (or other contexts) the situation may be similar or not.

If you mean the two words just as english verbs and not specifically as programming language keywords, then

  • iterating means to “loop over all elements of a set, one by one”
  • enumerating means to “give each element of a set an ordinal number, one by one”

And since iterating is needed for enumerating, and enumerating implies some kind of iteration, those two process descriptions can typically be interchanged.

6

As others have said, the precise semantics depend on the programming language that uses the terms, so I’ll give a purely linguistic appraisal.

“Iterable” is a rather new-coined word, obviously referring to “iterating” and the “iterators” that many languages have built in. Therefore, such types almost certainly support an iterator, but not necessarily anything else, and not necessarily anything beyond the most basic iterator functionality: processing every item once. Reversing, deleting, measuring distances etc. may or may not be supported.

“Enumerable” refers to enumerating things, which can mean the same as iterating, but only if the language doesn’t already use “iterable” for that purpose. If a language has both, “enumerable” almost certainly means something else, probably something more powerful. Most likely, it will support the notion of connecting each element with a unique numeric index, and probably it will allow random access (e.g. retrieving the third element before the first and second ones).

That’s about all the meaning you can reasonably infer from just the words. In any concrete situation, refer to the standard library API docs.

I want to focus on the strict definition of both terms

Iterable is to iterate things, and get access to the element one by one.

I think that the term Enumerable was originated from the turning machine. It’s about the ability to list out the element one by one in a proper order. The things can be listed out one by one has to be countable, each one has a unique correspondence index. Given an element, you can get a unique index. Given an index, you can only find one possible element associated with that index.

In other words, Enumerable implies the ability to generate the elements . Some programming language, for example, Haskell has implemented this idea. There is a Enum type class, and Char is one the instance.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Prelude> fromEnum True
1
Prelude> fromEnum False
0
Prelude> toEnum 1 :: Bool
True
Prelude> fromEnum 'a'
97
Prelude> enumFromTo 'a' (toEnum 122 :: Char)
"abcdefghijklmnopqrstuvwxyz"
</code>
<code>Prelude> fromEnum True 1 Prelude> fromEnum False 0 Prelude> toEnum 1 :: Bool True Prelude> fromEnum 'a' 97 Prelude> enumFromTo 'a' (toEnum 122 :: Char) "abcdefghijklmnopqrstuvwxyz" </code>
Prelude> fromEnum True
1
Prelude> fromEnum False
0
Prelude> toEnum 1 :: Bool
True

Prelude> fromEnum 'a'
97
Prelude> enumFromTo 'a' (toEnum 122 :: Char)
"abcdefghijklmnopqrstuvwxyz"

enumeration is counting,
iteration is a replaying

a second enumeration will yield the same number,
an iteration may be a variation

fractals are built by iterations of a function, repeating the function on the result of the last iteration,
each iteration has a different value

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật