Skip to content

Commit 21592fa

Browse files
author
alexrp
committed
---
yaml --- r: 31729 b: refs/heads/dist-snap c: 81aef34 h: refs/heads/master i: 31727: 9901c02 v: v3
1 parent 72ca96e commit 21592fa

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
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: 52c517383ef57f96ce1a97babc627d03329ac5e6
10+
refs/heads/dist-snap: 81aef34a5acd8c546992e100defb6f769b46d9d7
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/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)