Another question, do for in loops ever iterate backwards or are they only one way?
Forward:
* s = first
* s = second
* s = third
Backward:
* s = third
* s = second
* s = first
Another question, do for in loops ever iterate backwards or are they only one way?By default, the for in loop runs in the forward order. But it can be customized.
In set theory you are right, no particular order.
In Pascal implementations the default set construct is always in order, though.
In set theory you are right, no particular order.
In Pascal implementations the default set construct is always in order, though.
No, that's plain wrong! A Pascal set is not ordered.
Arrays are ordered, sets are not.
What you probably meant to say is that the underlying type for which the set is declared has to be an ordinal type.
But the set itself has no order. It only contains some element or not.
Let's take a look at set theory - you said they are not ordered, and Pascal sets are - let's take a set of integral numbers A={1, 2, 5}.
What can we say about this set?
We can say that number 2 belongs to it, we can say that number 3 doesn't belong to it. We can notice that its elements can be compared (1<2, 1<5, 2<5), as this is a set of integral numbers, but it has nothing to do with the set itself. The set itself is not ordered, it can be written {2, 5, 1} and this is the same set.
Now, Thaddy, what is different in Pascal sets?
What's the difference between "construct" and elements within the set? I think Zoran and Thaddy are discussing two different things.
What's the difference between "construct" and elements within the set? I think Zoran and Thaddy are discussing two different things.
You mean that "construct" there stands for "elements within the set"?
I'd say that in cited context "default set construct" should be understood like "set as a standard structured type (https://www.freepascal.org/docs-html/current/ref/refse14.html#refsu16.html) in Pascal".
I wonder how it’s implemented though. ..
Has anyone experimented with adding numbers to a set in a particular order and then usingEven if they come out in the same order they were put in it might be considered undefined behavior.
for x in theSet do
No, that's plain wrong! A Pascal set is not ordered.A Pascal set is ordered. In all pascal dialects. A pascal set is ordered, and behaves as an ordinal
No, that's plain wrong! A Pascal set is not ordered.A Pascal set is ordered. In all pascal dialects. A pascal set is ordered, and behaves as an ordinal
Mathemetically a set is not ordered.
You misunderstood me.
Wrong again, in only two days..... Check your sources.....
, and behaves as an ordinal
The ordinals can be put in a unique order, as they are always comparable, (a<=b) or (b<=a) is always true, for any a and for any b.There is a thing called "partial order" and the inclusion operator (<=) defines such a partial order in a set, but that is true both for math and the FPC.
For instance, let's look at numbers 2 and 5 - one of these expressions is true: 2<=5 or 5<=2.
Lets look at the Pascal sets A=[2, 3, 5]; B=[1, 2, 3, 5, 7, 9], C = [3, 5, 9].
A and B are indeed comparable (A <= B equals True), so are B and C (C <=B), but A and C are not (both A<=C and C<=A are False).
There is a thing called "partial order" and the inclusion operator (<=) defines such a partial order in a set, but that is true both for math and the FPC.
I'm just amazed by the topic and the debate.:)
Because Pascal enumerates the set elements and selects a bit based on that enumeration, it is fair to say that sets are internally ordered, i.e, bit 0 is always the first element, bit 1 the second and so on but,
By the way, I really wanted to avoid the talk about the internal representation (because it shouldn't be relevant), but I should have known it was sooner or later unavoidable.+1
I disagree that it is fair to say. It is misleading - sets are not internally ordered.Not only it is fair to say, it is 100% accurate.
The set is not internally represented by any particular bit.read slowly, the sentence referred to set elements.
It is the members which are represented by the bits, not sets.Really ?... you're so smart.
It is the members which are represented by the bits, not sets.Really ?... you're so smart.
That is why I find it quite strange that you said that "it's fair to say that the sets are internally ordered", when it seems quite clear that you understand that only their elements are ordered... :oLooks like we're getting off track due to semantics. what's "inside" a set are its elements, my saying that sets are internally ordered means that their elements are ordered (the enumeration imposes the order.)
Looks like we're getting off track due to semantics. what's "inside" a set are its elements, my saying that sets are internally ordered means that their elements are ordered (the enumeration imposes the order.)
Strictly speaking, the total order requires relation to be reflexive, transitive, asymmetric and, what you have mentioned earlier, strongly connected (x<=y or y<=x). https://en.wikipedia.org/wiki/Total_orderThere is a thing called "partial order" and the inclusion operator (<=) defines such a partial order in a set, but that is true both for math and the FPC.
Yes, each set type in Pascal is partially ordered by operation "<=" (subset, or whatever the correct term in English is), and yes that is so in both math and fpc. So we can say that sets in Pascal are ordered just as much as the sets are ordered in math - that was what I've been trying to say from the start.
Unlike this, ordinal types in Pascal are totally ordered (each two elements are comparable).
And increasingly puzzled, we should be aware of the limitations of the sets in Pascal and ultimately use them for their intended purpose/convenience, without pointless debates. (Not a personal remark)I'm just amazed by the topic and the debate.:)
Yes, that is of course so, but...Strictly speaking, the total order requires relation to be reflexive, transitive, asymmetric and, what you have mentioned earlier, strongly connected (x<=y or y<=x). https://en.wikipedia.org/wiki/Total_orderThere is a thing called "partial order" and the inclusion operator (<=) defines such a partial order in a set, but that is true both for math and the FPC.
Yes, each set type in Pascal is partially ordered by operation "<=" (subset, or whatever the correct term in English is), and yes that is so in both math and fpc. So we can say that sets in Pascal are ordered just as much as the sets are ordered in math - that was what I've been trying to say from the start.
Unlike this, ordinal types in Pascal are totally ordered (each two elements are comparable).
As long as in the computer memory everything is represented by a whole numbers (exclude the recent quantum delirium) a secondary total order can be always defined by considering the N injection, i.e. everything is countable.
But this is just a rethought theory, where is the practical benefit in the end?;)
And increasingly puzzled, we should be aware of the limitations of the sets in Pascal and ultimately use them for their intended purpose/convenience, without pointless debates. (Not a personal remark)I'm just amazed by the topic and the debate.:)
Really a lot of pointless pages have been written lately full of nagging on topics regarding types in FPC (to mention the Boolean). Unfortunately this forum has become quite repulsive lately.
The original subject of this topic got polluted. I am sorry for taking big part in this, but I couldn't ...No need to be sorry, I also fall for this bait from time to time. Others have pointed out the usual pollutants here more than once, so I won't. :-[
No need to be sorry, I also fall for this bait from time to time. Others have pointed out the usual pollutants here more than once, so I won't. :-[
This has certainly been an interesting discussion :D
I suppose there has to be a way for the computer to store set elements behind the scenes.
I am surprised to be told that I can iterate from lowest to highest element though. Is that true? All this time I’ve thought that only for in loop can be used for sets.
would not be possible if the set wasn't internally ordered.
for x in theSet do ...
It's interesting that code like this:would not be possible if the set wasn't internally ordered.
for x in theSet do ...
It would be entirely possible, based on the ordering of the base type... as I said, and as Alpine said earlier.NO, it would not. The base type order isn't sufficient.
Thanks for the answers. It seems like there is contention About the true nature of a set. I am more concerned with actually using it as set although the inner workings of it are interesting too I don’t think it should be misused.
Thanks for the answers. It seems like there is contention About the true nature of a set. I am more concerned with actually using it as set although the inner workings of it are interesting too I don’t think it should be misused.
By and large, it's safe to assume that any Pascal implementation will permit "set of char", at least until that's broken by somebody defining char to map onto some ridiculous Unicode type rather than ansichar.
Fun fact: Current Delphi implicitly converts set of Char with Char = WideChar to set of AnsiChar together with a warning that it did this (and set of WideChar triggers an error).
but.. why would anyone care about internals ??? ... ignorance is such a bliss!... I hope I didn't hurt somebody's fragile feelings again...Which is why real programmers read and comprehend documentation. Ignorance must indeed be such a bliss. Better is ofc to waste time with those indirect insults.
Which is why real programmers read and comprehend documentation. Ignorance must indeed be such a bliss. Better is ofc to waste time with those indirect insults.It's not an insult, it's worse, it's a fact. Anyone who has read documentation knows that it very rarely covers every detail, it's up to the programmer (well... I should say, some programmers) to go beyond what is documented. Again, that's not an insult, that's a fact.
Yes, but the ordering is by virtue of the ordinal base type. It says nothing about the ordering of the storage.The ordering is mandatory for sets and documented in ISO 7185.
MarkMLl
The ordering is mandatory for sets and documented in ISO 7185.
As per my demo, the compiler is aware of that.
Yes, but the ordering is by virtue of the ordinal base type. It says nothing about the ordering of the storage.It is NOT by virtue of the ordinal base type. ONLY an ordinal type can be used because there must be a 1 to 1 correspondence between a set element and a bit that represents the set element.
MarkMLl
Is it really that hard to gather knowledge beyond what is documented ? Just for the record, a lot of programmers don't find it difficult and in addition to that, some even find it rewarding.This phenomenon is not limited to programmers :D
It's not an insult, it's worse, it's a fact.I was not referring to that and you bloody well know that.
Anyone who has read documentation knows that it very rarely covers every detail, it's up to the programmer (well... I should say, some programmers) to go beyond what is documented. Again, that's not an insult, that's a fact.In general, yes. In this particular case, no as it is documented and the compiler has provision for it to prevent the user from making that mistake. That someone chooses to ignore it is not on my account.
Just like, internally, FPC orders the elements that make up a set (can't say that sets are ordered because apparently it isn't obvious that it is their elements that are ordered) and it is at least good to be aware of that, because "for" loops absolutely need to have the elements they act on to be ordered for them to operate properly.The obsession with wanting to know how a byte is ordered in memory is a basic understanding of how computers work. Can be ignored and then blame the compiler for behaving exactly as described but I find it silly with a capital S.
Is it really that hard to gather knowledge beyond what is documented ? Just for the record, a lot of programmers don't find it difficult and in addition to that, some even find it rewarding.No idea why you would want to gain knowledge on a topic that is behaving exactly as described. Must be silly me to just accept what is documented and expect for this example of yours to fail. But you already knew that as well, which is why these exact numbers where chosen. Still that seems to not have been enough to make you understand, instead redirect to something silly as how things are internally stored while the internal storage has nothing to do with the topic.
Let's state the obvious again, by definition sets are collections of unordered elements, HOWEVER, for performance and implementation simplicity reasons, Pascal DOES order set elements. Is it really that hard to comprehend that ?And yet you seem to mistake sets for ranges. And nobody should care about internal storage whatsoever, again with the exception being a compiler developer, writing a debugger or are a reverse engineer. All of which are not of any concern for an ordinary developer.
I'm a new guy here, but how did the forum go from a sharing information for the betterment of all forum, to a "I know more than you, nah nah nah" forum?the simple answer would be because they are allowed to.. the more complicated answer would be that they have character flaws that make them feel entitled to sneer at any code that isn’t theirs. I’ve seen the same behavior as this on a dying gaming server. Small group of not so fun people looking for fights.. something really should be done about this....
... they have character flaws that make them feel entitled to sneer at any code that isn’t theirs. I’ve seen the same behavior as this on a dying gaming server. Small group of not so fun people looking for fights.. something really should be done about this....LOL... at least you don't hide where you're coming from. Good one!