Skip to content

Commit ec3a156

Browse files
committed
WLS: Added description of element-of comparator.
The element of operator tests for containment of one element in another element of collection type.
1 parent bd5ae91 commit ec3a156

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
Binary file not shown.

WhileyLanguageSpecification/src/expressions.tex

+14-1
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,29 @@ \section{Subset Expressions}
222222

223223
This function compares two integer sets and returns the ``sign'' of their comparison. The non-strict inequality comparators are used so the cases where \lstinline{xs == ys} and \lstinline{xs != ys} can be distinguished.
224224

225+
\paragraph{Notes.} At the time of writing there is no keyword or non-unicode operator for expressing these comparators.
226+
225227
\section{Element-Of Expression}
226228
\label{c_expr_relational}
227-
An element-of expression determines whether one value is contained within another values of collection type (\S\ref{c_types_collection}) and produces a value of \lstinline{bool} type.
229+
An element-of expression determines whether one value is contained within another value of collection type (\S\ref{c_types_collection}) and produces a value of \lstinline{bool} type. Specifically, if the element is contained then the result is \lstinline{true}, otherwise it is \lstinline{false}.
228230

229231
\begin{syntax}
230232
\verb+ConditionExpr+ & $::=$ &\\
231233
& $|$ & \verb+AppendExpr+ \token{in} \verb+AppendExpr+\\
232234
& $|$ & \verb+AppendExpr+ \token{$\in$} \verb+AppendExpr+\\
233235
\end{syntax}
234236

237+
\paragraph{Example.} The following illustrates the element-of operator.
238+
239+
\begin{lstlisting}
240+
function containsOne({int} xs, {int} ys):
241+
for x in xs:
242+
if x in ys:
243+
return true
244+
return false
245+
\end{lstlisting}
246+
This function accepts two integer sets and checks whether any element of the first parameter is in the second.
247+
235248
% =======================================================================
236249
% Append Expressions
237250
% =======================================================================

0 commit comments

Comments
 (0)