git @ Cat's Eye Technologies Lanthorn / 7fd9ff6
Failing test cases for `letrec` nested inside plain `let`. Chris Pressey 3 years ago
1 changed file(s) with 36 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
190190 let r = fun(x) -> let x = 3 in x in r(10)
191191 ???> Already defined: x
192192
193 `letrec`.
193 #### `letrec`
194
195 Basic usage of `letrec`.
194196
195197 letrec
196198 oddp = fun(x) -> if eq(x, 0) then false else evenp(sub(x, 1))
206208 evenp(5)
207209 ===> false
208210
209 Nested `letrec`. Nested inside an `if` inside a function definition in an arm.
211 `letrec` nested inside an `if` inside a function definition in an arm of
212 another `letrec`.
210213
211214 letrec
212215 facto = fun(n) -> if eq(n, 1) then 1 else
222225 facto(8)
223226 ===> 105
224227
225 Nested `letrec`, nested in the body.
228 `letrec` nested in the body of another `letrec`.
226229
227230 letrec
228231 oddp = fun(x) -> if eq(x, 0) then false else evenp(sub(x, 1))
257260 in
258261 facto(8)
259262 ???> Not in scope: facto
263
264 `letrec` nested inside a function definition inside an arm of a plain `let`.
265
266 let
267 factoo = fun(f,n) ->
268 letrec
269 oddp = fun(x) -> if eq(x, 0) then false else evenp(sub(x, 1))
270 evenp = fun(x) -> if eq(x, 0) then true else oddp(sub(x, 1))
271 in
272 if eq(n, 1) then 1 else
273 if oddp(n) then
274 mul(n, f(f, sub(n, 1)))
275 else
276 f(f, sub(n, 1))
277 in
278 factoo(factoo, 7)
279 ===> 105
280
281 `letrec` nested inside body of a plain `let`.
282
283 let
284 factopen = fun(f,n) -> if eq(n, 1) then 1 else f(f, sub(n, 1))
285 target = 7
286 in
287 letrec
288 oddp = fun(x) -> if eq(x, 0) then false else evenp(sub(x, 1))
289 evenp = fun(x) -> if eq(x, 0) then true else oddp(sub(x, 1))
290 in
291 if oddp(target) then factopen(factopen, target) else 0
292 ===> 105