source: project/chicken/trunk/tests/compiler-tests-2.scm @ 15817

Last change on this file since 15817 was 15817, checked in by felix, 10 years ago

avoid inlining map/for-each for possibly side-effecting operator

File size: 1.0 KB
Line 
1;;; compiler-tests-2.scm - tests for particular compiler optimizations
2
3
4;;; rev. 12113 - lambda-lifting breakage, because lambda-bound variables
5;                were incorrectly marked as global (analysis didn't walk
6;                "lambda" nodes correctly, due t incorrect assumption
7;                that "lambda" doesn't occur. Major stupidity.
8;                Test case by Joerg Wittenberger
9
10(define (plus1 a)
11 (define (plus b)
12   (+ a b))
13 (plus 1))
14
15(assert (= 2 (plus1 1)))
16
17(define (len lst)
18 (define (len n)
19   (if (pair? lst)
20       (begin
21         (set! lst (cdr lst))
22         (len (+ n 1)))
23       n))
24 (len 0))
25
26(assert (= 3 (len '(1 2 3))))
27
28
29;;; compiler-syntax for map/for-each must be careful when the
30;   operator may have side-effects (currently only lambda exprs and symbols
31;   are allowed)
32
33(let ((x #f))
34  (define (f1 x) (print* x " "))
35  (map f1 '(1 2 3))
36  (newline)
37  (map (begin (assert (not x)) 
38              (set! x #t)
39              f1)
40       '(1 2 3))
41  (map (lambda (x) (print* ":" x)) '(1 2 3))
42  (newline))
Note: See TracBrowser for help on using the repository browser.