unbound identifier with define-record-type run as file but not in REPL

Bug #180455 reported by leppie
2
Affects Status Importance Assigned to Milestone
Ikarus Scheme
Fix Released
Low
Abdulaziz Ghuloum
r6rs-libraries
New
Undecided
Unassigned

Bug Description

Sorry for the arb description :p I am trying to get define-record in psyntax to use define-record-type, and ran into this.

The following runs fine in REPL, but fails when run as file.

$ cat wip.ss
(import
        (rnrs))

(define-syntax define-record
  (lambda (x)
        (syntax-case x ()
      [(_ name (field* ...) printer)
       #'(define-record name (field* ...))]
      [(_ name (field* ...))
       #`(define-record-type name
           (sealed #t) ; for better performance
           (opaque #t) ; for security
           (nongenerative) ; for sanity
           (fields #,@(map
                       (lambda (field)
                         #`(mutable
                            #,(syntax->datum field)
                            #,(string->symbol
                               (string-append
                                (symbol->string
                                 (syntax->datum #'name))
                                "-"
                                (symbol->string
                                 (syntax->datum field))))
                            #,(string->symbol
                               (string-append
                                "set-"
                                (symbol->string
                                 (syntax->datum #'name))
                                "-"
                                (symbol->string
                                 (syntax->datum field))
                                "!")) ))
                       #'(field* ...))))])))

(define-record testr (id name version))

(define tt (make-testr 1 2 3))
(testr-id tt)

$ ikarus --r6rs-script wip.ss
Unhandled exception:
 Condition components:
   1. &who: testr-id
   2. &message: "unbound identifier"
   3. &undefined
   4. &source-information:
       file-name: "wip.ss"
       character: 1429

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

It's a bug in your macro. You're missing a bunch of datum->syntax calls for all the identifiers that you're generating. The bug in the expander is that it's not signaling an error in these cases.

Revision history for this message
leppie (leppie) wrote :

Ok working with the added (datum->syntax). Thanks.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Added assertion in revision 1328. Now, you get the following for that macro:
Unhandled exception
 Condition components:
   1. &who: define-record
   2. &message: "raw symbol encountered in output of macro"
   3. &syntax:
       form: (define-record testr (id name version))
       subform: id

Changed in ikarus:
assignee: nobody → aghuloum
importance: Undecided → Low
status: New → Fix Committed
Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

BTW: your macro is way too complicated. Here's how *I* would do it.

(define-syntax define-record
  (lambda (x)
    (define gen
      (lambda (id fmt)
        (lambda (fld)
          (datum->syntax id
            (string->symbol
              (format fmt (syntax->datum id) (syntax->datum fld)))))))
    (syntax-case x ()
      [(_ name (field* ...) printer)
       #'(define-record name (field* ...))]
      [(_ name (field* ...))
       (with-syntax ([(getter* ...)
                      (map (gen #'name "~s-~s") #'(field* ...))]
                     [(setter* ...)
                      (map (gen #'name "set-~s-~s!") #'(field* ...))])
         #`(define-record-type name
             (sealed #t) ; for better performance
             (opaque #t) ; for security
             (nongenerative) ; for sanity
             (fields (mutable field* getter* setter*) ...)))])))

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Sorry, I couldn't resist :-)

Revision history for this message
leppie (leppie) wrote :

Hehe, thanks. All those ellipsis makes my head spin.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote : Re: [Bug 180455] Re: unbound identifier with define-record-type run as file but not in REPL

On Jan 5, 2008, at 3:06 AM, leppie wrote:

> Hehe, thanks. All those ellipsis makes my head spin.

Come on. I didn't even use (... ...) or ((... ...) (... ...)) in
that code!

Revision history for this message
leppie (leppie) wrote :

> Come on. I didn't even use (... ...) or ((... ...) (... ...)) in that code!

I'll get there!

I am running into a another stumbling block now, not sure if this is related.

My buildscript is based on the psyntax one. Now when running it, I can see it is using the new definition, but during the expansion process I get this:

...
expanding psyntax/compat.ss
expanding psyntax/internal.ss
expanding psyntax/config.ss
expanding psyntax/library-manager.ss
&who: define-record
&message: raw symbol encountered in output of macro
&syntax: (define-record library (id name version imp* vis* inv* subst env visit-state invoke-state visible?)) id

Any suggestions?

Note: I am still using my 'ugly' macro as I dont have 'format' (yet).

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

> Any suggestions?

Not really. Could it be that you were still expanding with your
faulty define-record macro while the expander is rejecting it? I
don't know how you're bootstrapping your system but I would revert
back to the old and correct define-record macro (one that uses
vectors IIRC), bootstrap once or twice or whatever your system needs
to propagate changes, then try changing define-record and see if it
works.

I really can't help you much there.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

On Jan 5, 2008, at 4:16 AM, leppie wrote:

> Note: I am still using my 'ugly' macro as I dont have 'format' (yet).

Invest in format. Even a simple format (20 lines?) is better than
the manual formatting that you're doing. You'll thank me for it.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

On Jan 5, 2008, at 4:16 AM, leppie wrote:

> &syntax: (define-record library (id name version imp* vis*
> inv* subst env visit-state invoke-state visible?)) id

There's a clue maybe at the last 2 chars of that line. Did you
remove your syntax->datum around "field" here:
                       (lambda (field)
                          #`(mutable
                             #,(syntax->datum field) <======
                             #,(string->symbol
                                (string-append
                                 (symbol->string

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Or maybe I should stop and go to bed :-)

Revision history for this message
leppie (leppie) wrote :

OK, I rewrote using with-syntax and it works :)

And thanks for that clue, I think that is exactly where the problem is, but I'll stick to the new one for now.

Cheers

leppie

Revision history for this message
leppie (leppie) wrote :

BTW: nice performance boost for the bootstrapping using native records (30 seconds down to 25 seconds for 'macro expansion' in debug mode).

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

This bug report is about to be closed as the fix comitted
previously will be incorporated in the next 0.0.3 release of
Ikarus Scheme, scheduled for January 31, 2008. A release
candidate tarball is available for download from:
http://www.cs.indiana.edu/~aghuloum/ikarus/ikarus-0.0.3-rc1.tar.gz
Please do test it if you have the time and report any issues
you might encounter. Thank you very much for your support.
(Sorry for the duplicates; I'm updating every open bug.)

Changed in ikarus:
milestone: none → 0.0.3
Changed in ikarus:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.