From b79830c4b182fa04dd3e84870c04fb1e51cefd49 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Sat, 4 Jul 2009 11:13:24 +0200 Subject: [PATCH] Doc: Updating language definition to mirror the new and refined static analysis. --- doc/parts/syntax/bracket.sxml | 2 +- doc/parts/syntax/functions.sxml | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/doc/parts/syntax/bracket.sxml b/doc/parts/syntax/bracket.sxml index 3b231744..3791f76e 100644 --- a/doc/parts/syntax/bracket.sxml +++ b/doc/parts/syntax/bracket.sxml @@ -29,7 +29,7 @@ | -

The top level semantics of the code brackets is defined by two phases. In the first phase, all items in the bracket that can be evaluated at any time and without evaluation of sub-expressions, are evaluated. This includes variable definitions whose right hand side can be delayed using a thunk. Any items related to states are excluded from this phase.

+

The top level semantics of the code brackets is defined by two phases. In the first phase, all items in the bracket that can be evaluated at any time and without evaluation of sub-expressions, are evaluated. This includes variable definitions whose right hand side can be delayed due to absence of free states. (Any items with free states are excluded from this phase.)

In the second phase, the remaining items are evaluated in order of appearance. The value of the last item is used as the value of the whole code bracket.

diff --git a/doc/parts/syntax/functions.sxml b/doc/parts/syntax/functions.sxml index 1560f797..53a6d9ec 100644 --- a/doc/parts/syntax/functions.sxml +++ b/doc/parts/syntax/functions.sxml @@ -52,7 +52,31 @@

The semantics for passing states is analogous to that of passing arguments.

-

The evaluation of argument expressions is typically delayed by passing a thunk instead of a value unless the argument is immediate or the corresponding formal parameter requires the argument to be forced. (Most elementary functions in the kernel will require all their arguments to be forced, while user-defined functions only take thunks by default.)

+

The evaluation of argument expressions is typically delayed by passing a thunk instead of a value unless one of the following conditions hold: +

+ (Most elementary functions in the kernel will require all their arguments to be forced, while user-defined functions only take thunks by default.)

+

If a state is passed as a state to a non-pure function, it may not be free in a non-immediate argument expression of the same call — it must be clear from the call expression that the argument expression where the state is free will be evaluated before the function is called.

+ +

Delaying the evaluation of argument expressions with free states could lead to some very strange behavior if the same state is also passed as a state argument; consider the following example: +

+
+
+Here, looking at the definition of f, you would expect that the program produce one two shifted copies of (•dst) and one copy of img. However, the accessing of img would change the result of (•dst) if the expression for img would not have been evaluated before the application of f. +

+

On the other hand, delaying the evaluation of argument expressions with free states is exactly what one would expect in other situations. For instance, +

+
+
+Here, one would certainly not expect both the circle and the rectangle to appear on the page. +

+

Clearly, both problems would be avoided by implicitly making immediate any argument expression with a free state that is also passed as state. However, it is thought to add valuable clarity to programs to require that the mark for immediate evaluation is written out explicitly.

+
-- 2.11.4.GIT