diff --git a/src/org/rascalmpl/library/Set.rsc b/src/org/rascalmpl/library/Set.rsc index fa5d90897b3..10e0f819cdd 100644 --- a/src/org/rascalmpl/library/Set.rsc +++ b/src/org/rascalmpl/library/Set.rsc @@ -310,7 +310,7 @@ public java &T getOneFrom(set[&T] st); @synopsis{Get "first" element from a set.} @description{ Get "first" element of a set. Of course, sets are unordered and do not have a first element. -However, we may assume that sets are internally ordered in some way and this ordering is reproducible. +However, we could assume that sets are internally ordered in some way and this ordering is reproducible (it's deterministic up to hashing collisions). Applying `getFirstFrom` on the same set will always returns the same element. :::warning @@ -323,6 +323,7 @@ analysis algorithm (arbitrary data is not considered). This function helps to make set-based code more deterministic, for instance, for testing purposes. } @pitfalls{ +* The deterministic order is _undefined_. This means it may be stable between runs, but not between releases of Rascal. * There are much better ways to iterate over the elements of a set: * Use the `<-` enumerator operator in a `for` loop or a comprehension. * Use list matching @@ -337,14 +338,14 @@ public java &T getFirstFrom(set[&T] st); Get the only element of a singleton set. This fails with a ((CallFailed)) exception when the set is not a singleton. } @benefits{ -* getSingleFrom fails _fast_ if the assumption (parameter `st` is a singleton) is not met. +* ((getSingleFrom)) fails _fast_ if the assumption (parameter `st` is a singleton) is not met. * If a binary relation `r` is injective (i.e. it models a function where each key only has one value) then all projections `r[key]` should produce singleton values: `{v}`. Using ((getSingleFrom)) to get the element out makes sure we fail fast in case our assumptions were wrong, or they have changed. * Never use ((getFirstFrom)) or ((takeOneFrom)) if you can use ((getSingleFrom)). } @pitfalls{ * ((CallFailed)) exceptions are sometimes hard to diagnose. Look at the stack trace to see that it was ((getSingleFrom)) -that caused it, and then look at the paramete of ((CallFailed)) to see that the set was not a singleton. +that caused it, and then look at the parameter of ((CallFailed)) to see that the set was not a singleton. } public &T getSingleFrom(set[&T] st) = getFirstFrom(st) when size(st) == 1;