source: project/wiki/eggref/5/srfi-45 @ 39274

Last change on this file since 39274 was 39274, checked in by gnosis, 2 months ago

Linked to source code for version 4.0.0 in SRFI-45 documentation

File size: 4.3 KB
Line 
1[[tags: egg]]
2
3== srfi-45
4
5Primitives for Expressing Iterative Lazy Algorithms
6
7[[toc:]]
8
9
10== Documentation
11
12Extends the interpretation of a promise to include ''lazy'' and ''eager''
13promises.
14
15For more information see [[http://srfi.schemers.org/srfi-45/srfi-45.html|SRFI 45]].
16
17
18=== lazy
19
20<macro>(lazy EXPRESSION) => promise</macro>
21
22Returns a promise for {{EXPRESSION}}, which must evaluate to a SRFI 45 promise.
23(See {{lazy-strict}}.}
24
25The promise will be iteratively forced, overwriting the promise at each step
26before the next iteration, so as to avoid storage leaks.
27
28=== lazy-strict
29
30<procedure>(lazy-strict [STRICT?]) => boolean</procedure>
31
32The body {{EXPRESSION}} of a {{lazy}} promise must produce a result of type
33{{promise}} according to SRFI 45. This is the default behavior of this
34implementation. To accept a more lenient interpretation call with a value of
35{{#f}} for {{STRICT?}}.
36
37The {{"improper use of `lazy'"}} error from {{force}} serves notice that a
38lazy expression was not of the correct type.
39
40=== eager
41
42<macro>(eager EXPRESSION) => promise</macro>
43
44Returns a promise but immediately evaluates {{EXPRESSION}}.
45
46=== force
47
48<procedure>(force PROMISE) => OBJECT</procedure>
49
50Returns the result of the evaluation of {{PROMISE}}. When {{PROMISE}} is an R5RS
51promise an R5RS {{force}} is performed and when {{PROMISE}} is not a promise it
52is the result.
53
54=== delay
55
56<macro>(delay EXPRESSION) => promise</macro>
57
58Returns a SRFI-45 promise, a delayed evaluation of {{EXPRESSION}}.
59
60=== lazy-promise?
61
62<procedure>(lazy-promise? OBJECT) => boolean</procedure>
63
64=== eager-promise?
65
66<procedure>(eager-promise? OBJECT) => boolean</procedure>
67
68=== recursive-promise?
69
70<procedure>(recursive-promise? OBJECT) => boolean</procedure>
71
72Is the {{OBJECT}} a recursive-promise; an eager or lazy promise?
73
74=== promise?
75
76<procedure>(promise? OBJECT) => boolean</procedure>
77
78Some kind of promise? An R5RS promise or a recursive-promise.
79
80
81== Usage
82
83<enscript language=scheme>
84(module foo (...)
85  ; Allow access to the original API and stop those annoying
86  ; redefined messages.
87  (import
88    (rename scheme (force r5rs:force) (delay r5rs:delay))
89    (rename chicken (promise? r5rs:promise?))
90    ...)
91  (use srfi-45)
92  ... code that can use R5RS and SRFI 45 promises ...
93)
94</enscript>
95
96
97== Notes
98
99* Supports multiple values for an eager promise and when {{(lazy-strict)}}
100is {{#f}} for a lazy promise.
101
102* If compiled with the feature {{srfi-45-paranoia}} defined then extra
103sanity checks are enabled.
104
105* The built-in routines are ''not'' rebound. This is purely a module
106implementation. As such the built-in {{promise?}} will not detect a
107recursive-promise as a promise. Do not allow these abstractions to
108''leak'' into unsuspecting contexts.
109
110
111== Requirements
112
113None
114
115
116== Author
117
118[[/users/kon-lovett|Kon Lovett]]
119
120Ported to Chicken 5 by Sergey Goldgaber
121
122== Version history
123
124; [[https://github.com/diamond-lizard/srfi-45/releases/tag/4.0.0|4.0.0]] - Ported to Chicken 5
125; 3.1.0 : Added {{lazy-strict}} and compile-time feature {{srfi-45-paranoia}}. Better R5RS promise support by {{lazy}}.
126; 3.0.0 : Redefines {{delay}}. Removed {{d-lay}} and {{recursive-delay}}.
127; 2.2.0 : Bug fix for ''lazy'' R5RS promise in {{force}}. [Reported by Derrell Piper]
128; 2.1.0 : Bug fix for ''too eager'' {{force}}. Removed "box" extension dependency.
129; 2.0.0 : Chicken 4 release.
130
131
132== License
133
134Copyright (C) 2009 Kon Lovett.  All rights reserved.
135
136Permission is hereby granted, free of charge, to any person obtaining a
137copy of this software and associated documentation files (the Software),
138to deal in the Software without restriction, including without limitation
139the rights to use, copy, modify, merge, publish, distribute, sublicense,
140and/or sell copies of the Software, and to permit persons to whom the
141Software is furnished to do so, subject to the following conditions:
142
143The above copyright notice and this permission notice shall be included
144in all copies or substantial portions of the Software.
145
146THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
147IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
148FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
149THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
150OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
151ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
152OTHER DEALINGS IN THE SOFTWARE.
Note: See TracBrowser for help on using the repository browser.