Add three more tests, one of which fails.
Chris Pressey
4 years ago
302 | 302 | evensump(6,3,1) |
303 | 303 | ===> true |
304 | 304 | |
305 | `letrec` works on functions which use different argument names. | |
306 | ||
307 | letrec | |
308 | oddsump = fun(x,y,z) -> if eq(add(x, add(y, z)), add(y, z)) then false else evensump(sub(x, 1), y, z) | |
309 | evensump = fun(p,q,r) -> if eq(add(p, add(q, r)), add(q, r)) then true else oddsump(sub(p, 1), q, r) | |
310 | in | |
311 | evensump(5,3,1) | |
312 | ===> false | |
313 | ||
314 | letrec | |
315 | oddsump = fun(x,y,z) -> if eq(add(x, add(y, z)), add(y, z)) then false else evensump(sub(x, 1), y, z) | |
316 | evensump = fun(p,q,r) -> if eq(add(p, add(q, r)), add(q, r)) then true else oddsump(sub(p, 1), q, r) | |
317 | in | |
318 | evensump(6,3,1) | |
319 | ===> true | |
320 | ||
321 | `letrec` works on functions that have differing numbers of arguments. | |
322 | ||
323 | letrec | |
324 | oddsump = fun(x,y,z) -> if eq(add(x, add(y, z)), add(y, z)) then false else evensump(sub(x, 1), add(y, z)) | |
325 | evensump = fun(p,q) -> if eq(add(x, q), q) then true else oddsump(sub(x, 1), 1, sub(q, 1)) | |
326 | in | |
327 | oddsump(5,3,1) | |
328 | ===> true | |
329 | ||
305 | 330 | -> Tests for functionality "Desugar Lanthorn Program" |
306 | 331 | |
307 | Let's see how that gets desugared. The innermost `let`s bind the plain | |
308 | names to functions with the same arity as the original functions. | |
332 | ### Properties of the `letrec` transformation | |
333 | ||
334 | When a `letrec` is desugared, the generated functions have argument | |
335 | names that are based on the original argument names. Also, the | |
336 | innermost `let`s bind the plain names to functions with the same arity | |
337 | as the original functions. | |
309 | 338 | |
310 | 339 | letrec |
311 | 340 | oddsump = fun(x,y,z) -> if eq(add(x, add(y, z)), add(y, z)) then false else evensump(sub(x, 1), y, z) |