Skip to content

Commit a8f2574

Browse files
author
alexrp
committed
---
yaml --- r: 23067 b: refs/heads/master c: 81aef34 h: refs/heads/master i: 23065: 48fcb08 23063: 6e6b4ad v: v3
1 parent 6882e1f commit a8f2574

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 52c517383ef57f96ce1a97babc627d03329ac5e6
2+
refs/heads/master: 81aef34a5acd8c546992e100defb6f769b46d9d7
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/doc/rust.md

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -899,58 +899,51 @@ express that `f` requires no explicit `return`, as if it returns
899899
control to the caller, it returns a value (true because it never returns
900900
control).
901901

902-
#### Predicate functions
902+
#### Pure functions
903903

904-
Any pure boolean function is called a *predicate function*, and may be used in
905-
a [constraint](#constraints), as part of the static [typestate
906-
system](#typestate-system). A predicate declaration is identical to a function
907-
declaration, except that it is declared with the additional keyword `pure`. In
908-
addition, the typechecker checks the body of a predicate with a restricted set
909-
of typechecking rules. A predicate
904+
A pure function declaration is identical to a function declaration, except that
905+
it is declared with the additional keyword `pure`. In addition, the typechecker
906+
checks the body of a pure function with a restricted set of typechecking rules.
907+
A pure function
910908

911909
* may not contain an assignment or self-call expression; and
912-
* may only call other predicates, not general functions.
910+
* may only call other pure functions, not general functions.
913911

914-
An example of a predicate:
912+
An example of a pure function:
915913

916914
~~~~
917915
pure fn lt_42(x: int) -> bool {
918916
return (x < 42);
919917
}
920918
~~~~
921919

922-
A non-boolean function may also be declared with `pure fn`. This allows
923-
predicates to call non-boolean functions as long as they are pure. For example:
920+
Pure functions may call other pure functions:
924921

925922
~~~~{.xfail-test}
926923
pure fn pure_length<T>(ls: list<T>) -> uint { /* ... */ }
927924
928925
pure fn nonempty_list<T>(ls: list<T>) -> bool { pure_length(ls) > 0u }
929926
~~~~
930927

931-
In this example, `nonempty_list` is a predicate---it can be used in a
932-
typestate constraint---but the auxiliary function `pure_length` is
933-
not.
934-
935928
*TODO:* should actually define referential transparency.
936929

937930
The effect checking rules previously enumerated are a restricted set of
938931
typechecking rules meant to approximate the universe of observably
939932
referentially transparent Rust procedures conservatively. Sometimes, these
940933
rules are *too* restrictive. Rust allows programmers to violate these rules by
941-
writing predicates that the compiler cannot prove to be referentially
934+
writing pure functions that the compiler cannot prove to be referentially
942935
transparent, using an escape-hatch feature called "unchecked blocks". When
943936
writing code that uses unchecked blocks, programmers should always be aware
944937
that they have an obligation to show that the code *behaves* referentially
945938
transparently at all times, even if the compiler cannot *prove* automatically
946939
that the code is referentially transparent. In the presence of unchecked
947940
blocks, the compiler provides no static guarantee that the code will behave as
948941
expected at runtime. Rather, the programmer has an independent obligation to
949-
verify the semantics of the predicates they write.
942+
verify the semantics of the pure functions they write.
950943

951944
*TODO:* last two sentences are vague.
952945

953-
An example of a predicate that uses an unchecked block:
946+
An example of a pure function that uses an unchecked block:
954947

955948
~~~~
956949
# import std::list::*;
@@ -972,7 +965,7 @@ pure fn pure_length<T>(ls: list<T>) -> uint {
972965

973966
Despite its name, `pure_foldl` is a `fn`, not a `pure fn`, because there is no
974967
way in Rust to specify that the higher-order function argument `f` is a pure
975-
function. So, to use `foldl` in a pure list length function that a predicate
968+
function. So, to use `foldl` in a pure list length function that a pure function
976969
could then use, we must use an `unchecked` block wrapped around the call to
977970
`pure_foldl` in the definition of `pure_length`.
978971

0 commit comments

Comments
 (0)