define-record, define-record-type and define-record-printer do not take the module namespace into account, so records that are defined in different modules--but have the same base name--may conflict, giving strange results or crashing your program. The attached patch qualifies the structure name with the current module name, which seems to work.
I also provided some REPL output (record-repl.scm) and a compilable program (record.scm) which will demonstrate the before and after. If this approach looks good, there are a few eggs which should be examined because they create structures directly: records: can be changed to use define-record unix-sockets: same datatype: should qualify symbols itself, if desired easyffi: not sure numbers: "compnum" unlikely to conflict, but could be qualified Jim
Index: chicken-syntax.scm
===================================================================
--- chicken-syntax.scm (revision 13204)
+++ chicken-syntax.scm (working copy)
@@ -46,8 +46,11 @@
(lambda (x r c)
(##sys#check-syntax 'define-record x '(_ symbol . #(symbol 0)))
(let* ((name (cadr x))
+ (prefix (symbol->string name))
+ (name (if (##sys#current-module)
+ (##sys#module-rename name (##sys#module-name
(##sys#current-module)))
+ name))
(slots (cddr x))
- (prefix (symbol->string name))
(setters (memq #:record-setters ##sys#features))
(%begin (r 'begin))
(%define (r 'define))
@@ -807,11 +810,21 @@
'define-record-printer (cons head body)
'((symbol symbol symbol) . #(_ 1)))
`(##sys#register-record-printer
- ',(##sys#slot head 0)
+ ',(if (##sys#current-module)
+ (##sys#module-rename (##sys#slot head 0)
+ (##sys#module-name
+ (##sys#current-module)))
+ (##sys#slot head 0))
(,(r 'lambda) ,(##sys#slot head 1) ,@body)) ]
[else
(##sys#check-syntax 'define-record-printer (cons head body)
'(symbol _))
- `(##sys#register-record-printer ',head ,@body) ] ) ))))
+ `(##sys#register-record-printer
+ ',(if (##sys#current-module)
+ (##sys#module-rename head
+ (##sys#module-name
+ (##sys#current-module)))
+ head)
+ ,@body) ] ) ))))
;;; Exceptions:
@@ -874,7 +887,11 @@
(##sys#er-transformer
(lambda (form r c)
(##sys#check-syntax 'define-record-type form '(_ variable #(variable 1)
variable . _))
- (let* ((t (cadr form))
+ (let* ((t (if (##sys#current-module)
+ (##sys#module-rename (cadr form)
+ (##sys#module-name
+ (##sys#current-module)))
+ (cadr form)))
(conser (caddr form))
(pred (cadddr form))
(slots (cddddr form))
record-repl.scm
Description: Binary data
record.scm
Description: Binary data
_______________________________________________ Chicken-hackers mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/chicken-hackers
