Incomplet and/or inkorrect implementation of SRFI-9
Marc: You have defined in _nonstd.scm:
(define-runtime-macro (define-record-type name constructor predicate . fields) `(define-type ,name constructor: ,constructor predicate: ,predicate ,@fields))
which I presume is meant to implement SRFI-9. However, SRFI-9 has the inconvenient passage:
<type name> is bound to a representation of the record type itself. Operations on record types, such as defining print methods, reflection, etc. are left to other SRFIs.
and your implementation of define-record-type doesn't do this:
(define-record-type :pare (kons x y) pare? (x kar set-kar!) (y kdr)) :pare *** ERROR IN (console)@13.1 -- Unbound variable: :pare
Do you have any quick suggestions about how to fix this? Brad
Afficher les réponses par date
Brad, On 11/30/06, Bradley Lucier <lucier@math.purdue.edu> wrote:
Do you have any quick suggestions about how to fix this?
Here's a hack I came up with: (define-macro (define-record-type name constructor predicate . fields) (let* ((te (string->symbol (string-append "type-exhibitor-" (symbol->string name))))) `(begin (define-type ,name constructor: ,constructor predicate: ,predicate type-exhibitor: ,te ,@fields) (define ,name (,te))))) Now:
(define-record-type :pare (kons x y) pare? (x kar set-kar!) (y kdr)) :pare #<type #2 :pare>
Hope that helps. --Jeff
On Dec 1, 2006, at 3:49 PM, Jeff Read wrote:
Here's a hack I came up with:
(define-macro (define-record-type name constructor predicate . fields) (let* ((te (string->symbol (string-append "type-exhibitor-" (symbol->string name))))) `(begin (define-type ,name constructor: ,constructor predicate: ,predicate type-exhibitor: ,te ,@fields) (define ,name (,te)))))
Thanks, I changed define-macro to define-runtime-macro and put this right into _nonstd.scm as
[brad:~/programs/gambc-4.0b20/lib] lucier% rcsdiff -u _nonstd.scm =================================================================== RCS file: RCS/_nonstd.scm,v retrieving revision 1.1 diff -u -r1.1 _nonstd.scm --- _nonstd.scm 2006/12/01 22:58:04 1.1 +++ _nonstd.scm 2006/12/01 23:20:38 @@ -998,10 +998,17 @@ (##define-type-expand 'define-structure #f #f args)) (define-runtime-macro (define-record-type name constructor predicate . fields) - `(define-type ,name - constructor: ,constructor - predicate: ,predicate - ,@fields)) + (let* ((te (string->symbol (string-append "type-exhibitor-" + (symbol->string name))))) + `(begin + (define-type ,name + constructor: ,constructor + predicate: ,predicate + type-exhibitor: ,te + ,@fields) + (define ,name (,te))))) + + ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
participants (2)
-
Bradley Lucier -
Jeff Read