@@ -682,6 +682,7 @@ The keywords are:
682
682
@tab @code {thread }
683
683
@item @code {auth }
684
684
@tab @code {unsafe }
685
+ @tab @code {as }
685
686
@tab @code {self }
686
687
@tab @code {log }
687
688
@item @code {bind }
@@ -711,8 +712,8 @@ The keywords are:
711
712
@tab @code {str }
712
713
@item @code {fn }
713
714
@tab @code {iter }
715
+ @tab @code {pred }
714
716
@tab @code {obj }
715
- @tab @code {as }
716
717
@tab @code {drop }
717
718
@item @code {task }
718
719
@tab @code {port }
@@ -1785,8 +1786,6 @@ fn main() @{
1785
1786
@c * Ref.Item.Fn:: Items defining functions.
1786
1787
@cindex Functions
1787
1788
@cindex Slots , function input and output
1788
- @cindex Predicate
1789
-
1790
1789
1791
1790
A @dfn {function item } defines a sequence of statements associated with a name
1792
1791
and a set of parameters. Functions are declared with the keyword
@@ -1805,16 +1804,37 @@ expression. If a control path lacks a @code{ret} expression in source code, an
1805
1804
implicit @code {ret } expression is appended to the end of the control path
1806
1805
during compilation, returning the implicit @code {() } value.
1807
1806
1808
- Any pure boolean function is also called a @emph {predicate }, and may be used
1809
- as part of the static typestate system. @xref {Ref.Typestate.Constr }.
1810
-
1811
1807
An example of a function:
1812
1808
@example
1813
1809
fn add(int x, int y) -> int @{
1814
1810
ret x + y;
1815
1811
@}
1816
1812
@end example
1817
1813
1814
+ @node Ref.Item.Pred
1815
+ @subsection Ref.Item.Pred
1816
+ @c * Ref.Item.Pred:: Items defining predicates.
1817
+ @cindex Predicate
1818
+
1819
+ Any pure boolean function is called a @emph {predicate }, and may be used
1820
+ as part of the static typestate system. @xref {Ref.Typestate.Constr }. A
1821
+ predicate declaration is identical to a function declaration, except that it
1822
+ is declared with the keyword @code {pred } instead of @code {fn }. In addition,
1823
+ the typechecker checks the body of a predicate with a restricted set of
1824
+ typechecking rules. A predicate
1825
+ @itemize
1826
+ @item may not contain a @code {put }, @code {send }, @code {recv }, assignment, or
1827
+ self-call expression; and
1828
+ @item may only call other predicates, not general functions.
1829
+ @end itemize
1830
+
1831
+ An example of a predicate:
1832
+ @example
1833
+ pred lt_42(int x) -> bool @{
1834
+ ret (x < 42);
1835
+ @}
1836
+ @end example
1837
+
1818
1838
@node Ref.Item.Iter
1819
1839
@subsection Ref.Item.Iter
1820
1840
@c * Ref.Item.Iter:: Items defining iterators.
@@ -2631,14 +2651,14 @@ This implicit graph is called the @dfn{control-flow graph}, or @dfn{CFG}.
2631
2651
@cindex Predicate
2632
2652
@cindex Constraint
2633
2653
2634
- A @dfn {predicate } is any pure boolean function. @xref {Ref.Item.Fn }.
2654
+ A @dfn {predicate } is a pure boolean function declared with the keyword @code { pred } . @xref {Ref.Item.Pred }.
2635
2655
2636
2656
A @dfn {constraint } is a predicate applied to specific slots.
2637
2657
2638
2658
For example, consider the following code:
2639
2659
2640
2660
@example
2641
- fn is_less_than(int a, int b) -> bool @{
2661
+ pred is_less_than(int a, int b) -> bool @{
2642
2662
ret a < b;
2643
2663
@}
2644
2664
@@ -3543,7 +3563,7 @@ and statically comparing implied states and their
3543
3563
specifications. @xref {Ref.Typestate }.
3544
3564
3545
3565
@example
3546
- fn even(&int x) -> bool @{
3566
+ pred even(&int x) -> bool @{
3547
3567
ret x & 1 == 0;
3548
3568
@}
3549
3569
0 commit comments