1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 20:00:19 +02:00

Several fixes to R6RS libraries

* module/rnrs/arithmetic/fixnums.scm (fixnum-width): Make this return an
  an exact integer instead of an inexact number.

* module/rnrs/base.scm (assertion-violation): Implement.

* module/rnrs/conditions.scm (simple-conditions): Allow also simple
  conditions as argument.

* module/rnrs/enums.scm (define-enumeration): Properly construct empty
  enumeration sets.

* module/rnrs/exceptions.scm (guard): Don't restrict the body to a
  single expression.

* module/rnrs/records/syntactic.scm (define-record-type0): Expand into a
  series of definitions only.
This commit is contained in:
Andreas Rottmann 2010-08-28 10:16:30 -07:00 committed by Andy Wingo
parent 7d0e17389c
commit 23988e8c50
6 changed files with 45 additions and 13 deletions

View file

@ -93,7 +93,7 @@
(rnrs lists (6))) (rnrs lists (6)))
(define fixnum-width (define fixnum-width
(let ((w (round (/ (log (+ most-positive-fixnum 1)) (log 2))))) (let ((w (inexact->exact (round (/ (log (+ most-positive-fixnum 1)) (log 2))))))
(lambda () w))) (lambda () w)))
(define (greatest-fixnum) most-positive-fixnum) (define (greatest-fixnum) most-positive-fixnum)

View file

@ -94,4 +94,24 @@
((negative? y) (values (- q 1) (+ r y))) ((negative? y) (values (- q 1) (+ r y)))
(else (values (+ q 1) (+ r y))))))) (else (values (+ q 1) (+ r y)))))))
(define raise
(@ (rnrs exceptions) raise))
(define condition
(@ (rnrs conditions) condition))
(define make-assertion-violation
(@ (rnrs conditions) make-assertion-violation))
(define make-who-condition
(@ (rnrs conditions) make-who-condition))
(define make-message-condition
(@ (rnrs conditions) make-message-condition))
(define make-irritants-condition
(@ (rnrs conditions) make-irritants-condition))
(define (assertion-violation who message . irritants)
(raise (condition
(make-assertion-violation)
(make-who-condition who)
(make-message-condition message)
(make-irritants-condition irritants))))
) )

View file

@ -95,7 +95,17 @@
(define make-compound-condition (define make-compound-condition
(record-constructor (make-record-constructor-descriptor (record-constructor (make-record-constructor-descriptor
&compound-condition #f #f))) &compound-condition #f #f)))
(define simple-conditions (record-accessor &compound-condition 0)) (define simple-conditions
(let ((compound-ref (record-accessor &compound-condition 0)))
(lambda (condition)
(cond ((compound-condition? condition)
(compound-ref condition))
((condition-internal? condition)
(list condition))
(else
(assertion-violation 'simple-conditions
"not a condition"
condition))))))
(define (condition? obj) (define (condition? obj)
(or (compound-condition? obj) (condition-internal? obj))) (or (compound-condition? obj) (condition-internal? obj)))

View file

@ -137,7 +137,6 @@
(define-syntax constructor-syntax (define-syntax constructor-syntax
(lambda (s) (lambda (s)
(syntax-case s () (syntax-case s ()
((_) (syntax #f))
((_ sym (... ...)) ((_ sym (... ...))
(let* ((universe '(symbol ...)) (let* ((universe '(symbol ...))
(syms (syntax->datum #'(sym (... ...)))) (syms (syntax->datum #'(sym (... ...))))

View file

@ -51,17 +51,17 @@
(define-syntax guard0 (define-syntax guard0
(syntax-rules () (syntax-rules ()
((_ (variable cond-clause ...) body) ((_ (variable cond-clause ...) . body)
(call/cc (lambda (continuation) (call/cc (lambda (continuation)
(with-exception-handler (with-exception-handler
(lambda (variable) (lambda (variable)
(continuation (cond cond-clause ...))) (continuation (cond cond-clause ...)))
(lambda () body))))))) (lambda () . body)))))))
(define-syntax guard (define-syntax guard
(syntax-rules (else) (syntax-rules (else)
((_ (variable cond-clause ... . ((else else-clause ...))) body) ((_ (variable cond-clause ... . ((else else-clause ...))) . body)
(guard0 (variable cond-clause ... (else else-clause ...)) body)) (guard0 (variable cond-clause ... (else else-clause ...)) . body))
((_ (variable cond-clause ...) body) ((_ (variable cond-clause ...) . body)
(guard0 (variable cond-clause ... (else (raise variable))) body)))) (guard0 (variable cond-clause ... (else (raise variable))) . body))))
) )

View file

@ -177,10 +177,13 @@
(record-constructor (record-constructor
(make-record-constructor-descriptor (make-record-constructor-descriptor
record-name #,parent-cd #,protocol))) record-name #,parent-cd #,protocol)))
(define dummy
(let ()
(register-record-type (register-record-type
#,record-name-sym #,record-name-sym
record-name (make-record-constructor-descriptor record-name (make-record-constructor-descriptor
record-name #,parent-cd #,protocol)) record-name #,parent-cd #,protocol))
'dummy))
(define predicate-name (record-predicate record-name)) (define predicate-name (record-predicate record-name))
#,@field-accessors #,@field-accessors
#,@field-mutators)) #,@field-mutators))