Fix `define-inlinable' in SRFI-9 so that arguments are evaluated only once.

* module/srfi/srfi-9.scm (define-inlinable): When inlining, evaluate the
  arguments only once.  Reported by Andreas Rottmann; thanks to Andy
  Wingo for the elegant solution.

* test-suite/tests/srfi-9.test ("side-effecting arguments"): New test
  prefix.
This commit is contained in:
Ludovic Courtès 2011-03-11 21:01:35 +01:00
commit b075a6d766
2 changed files with 14 additions and 4 deletions

View file

@ -80,15 +80,18 @@
(syntax-case x ()
((_ (name formals ...) body ...)
(identifier? #'name)
(with-syntax ((proc-name (make-procedure-name #'name)))
(with-syntax ((proc-name (make-procedure-name #'name))
((args ...) (generate-temporaries #'(formals ...))))
#`(begin
(define (proc-name formals ...)
body ...)
(define-syntax name
(lambda (x)
(syntax-case x ()
((_ formals ...)
#'(begin body ...))
((_ args ...)
#'((lambda (formals ...)
body ...)
args ...))
(_
(identifier? x)
#'proc-name))))))))))

View file

@ -94,8 +94,15 @@
(pass-if-exception "set-y! on bar" exception:wrong-type-arg
(set-y! b 99)))
(with-test-prefix "side-effecting arguments"
(pass-if "predicate"
(let ((x 0))
(and (foo? (begin (set! x (+ x 1)) f))
(= x 1)))))
(with-test-prefix "non-toplevel"
(define-record-type :frotz (make-frotz a b) frotz?
(a frotz-a) (b frotz-b set-frotz-b!))