Skip to content

Commit 1739fd6

Browse files
committed
Documenting expression wrappers fixes #53
1 parent 2f11c1f commit 1739fd6

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

Doc/Reference/Constants-and-logging.md

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
*Sources: Status.cs, Raw.cs - Last Updated: 2020.11.15*
1+
*Sources: Status.cs, Raw.cs - Last Updated: 2020.12.04*
22

3-
# Status keywords and logging calls
3+
# Status keywords, logging calls and expression wrappers
44

5-
Since 2020.11.15 statically importing `Active.Core.status` is discouraged; keywords (or logging calls) are made available via statically importing either `Active.Raw` or `Active.Status`.
5+
Keywords and logging calls are made available via statically importing `Active.Raw` or `Active.Status`.
66

77
`Active.Raw` is recommended for best performance or if you are not using the logging API.
88
With regard to performance logging overheads are small and the tradeoff is only meaningful when optimising critical sections.
99

10-
`Active.Status` enables concise logging calls, as described in the [logging API documentation](Logging.md).
10+
`Active.Status` enables logging calls, as described in the [logging API documentation](Logging.md).
1111

12-
Using `Active.Raw` does not disable logging. It only provides alternative semantics. The gist of it is you can't really have `done` and `done()` in the same namespace. Even with `Active.Raw` you can still issue a logging call via `status.done(..)`.
12+
Using `Active.Raw` does not disable logging. It only provides alternative semantics. Even when using `Active.Raw` you may still issue a logging call via `status.done(..)`.
1313

1414
Importing `static Active.Raw` in one file and `static Active.Status` in another is also not a problem.
1515

16-
## Statuses and certainties via `Active.Raw`
16+
## Active.Raw
1717

18-
If you statically import `Active.Raw`, status constants do not emit logging information and the following keywords are available:
18+
If you statically import `Active.Raw`, status constants do not emit logging information; keywords:
1919

2020
```
2121
done, cont, fail, @void, @false, forever, pending_cont, pending_done,
2222
impending_cont, impending_fail
2323
```
2424

25-
## Statuses and certainties via `Active.Status`
25+
## Active.Status
2626

27-
If you statically import `Active.Status`, status constants always emit logging information and the following calls are available:
27+
If you statically import `Active.Status`, status constants always emit logging information; keywords:
2828

2929
```
3030
done(..), cont(..), fail(..), @void(..), @false(..), forever(..),
@@ -42,3 +42,27 @@ status.done(log && "reason")
4242
loop.cont()
4343
impending.done() // will not compile since 'impending' never succeeds
4444
```
45+
46+
## Expression wrappers
47+
48+
Via `Active.Raw` or `Active.Status`, use a wrapper to include any expression within a status expression, then return an arbitrary status constant; here is an example:
49+
50+
```cs
51+
// Without an expression wrapper
52+
status Collect(string label){
53+
target = FindNearest(label);
54+
return DoCollect(target);
55+
}
56+
57+
// With an expression wrapper
58+
status Collect(string label)
59+
=> Do(target = FindNearest(label)) && DoCollect(target);
60+
```
61+
62+
All expression wrappers:
63+
64+
`static action Do(object arg)` - returns `@void`.
65+
66+
`static loop Cont(object arg)` - returns `forever`.
67+
68+
`static failure Fail(object arg)` - returns `@false`.

0 commit comments

Comments
 (0)