Skip to content

Commit

Permalink
typos
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Feb 6, 2024
1 parent 85ebcc1 commit 3ec7ad8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/org/rascalmpl/library/Set.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;

Expand Down

0 comments on commit 3ec7ad8

Please sign in to comment.