mes: Evaluate test of COND only once.

* module/mes/base-0.mes (cond): Evaluate test of COND only once.
  Fixes cond tests with side effects (Nyacc).
* tests/base.test ("cond side effect"): Test it.
This commit is contained in:
Jan Nieuwenhuizen 2018-01-05 10:01:50 +01:00
parent c60e79ae11
commit 5d68fc44ba
2 changed files with 6 additions and 2 deletions

View file

@ -63,8 +63,8 @@
(if (pair? (cdr (car clauses)))
(if (eq? (car (cdr (car clauses))) '=>)
(append2 (cdr (cdr (car clauses))) '(test))
(list (cons 'lambda (cons '() (car clauses)))))
(list (cons 'lambda (cons '() (car clauses)))))
(list (cons 'lambda (cons '() (cons 'test (cdar clauses))))))
(list (cons 'lambda (cons '() (cons 'test (cdar clauses))))))
(if (pair? (cdr clauses))
(cons 'cond (cdr clauses)))))))
(car (car clauses)))))

View file

@ -61,6 +61,10 @@ exit $?
(pass-if "cond 2" (seq? (cond (#f)) *unspecified*))
(pass-if "cond 3" (seq? (cond (#t 0)) 0))
(pass-if "cond 3" (seq? (cond (#f 1) (#t 0)) 0))
(pass-if-equal "cond side effect"
1
(let ((i 0))
(cond ((set! i (1+ i)) i))))
(pass-if-equal "cond => "
0 (let ((lst '(0 1 2)))
(define (next)