Summary

define-record-printer messes with internal defines

Metadata

Description

As pointed out by russelw on IRC, the following program fails to compile (and doesn't work in the interpreter, either):

 #!scm
 (module main ()
  (import chicken)
  (import scheme)
 
  (define (h)
   (define (f)
    (g))
 
   (define-record-printer (foo x port)
    #f)
 
   (define (g)
    (f))))

This is probably similar to #1274 and #1309.

Changes and comments

[2016-05-29 16:20:42 UTC] sjamaan wrote:

The problem here is that define-record-printer isn't a true definition. This code is comparable to the following:

 #!scm
 (define (h)
   (define (f)
    (g))
 
   (display "hello\n")
 
   (define (g)
    (f)))

Other Schemes will bail out on this, complaining that the definition of g is misplaced. CHICKEN accepts it, so the code from the ticket body should probably also be accepted.

[2016-05-29 19:07:47 UTC] sjamaan wrote:

Actually, the snippet above doesn't work in CHICKEN either; the compiler bails out when wrapped in a module, and if you insert a call to (g), it will die at runtime with a "unbound variable: g".

So perhaps it simply needs better error reporting? Other Schemes complain that the define for g is invalid.

[2016-08-25 20:41:45 UTC] sjamaan set difficulty to hard

[2016-08-25 20:42:28 UTC] sjamaan changed description

[2017-01-18 21:20:38 UTC] sjamaan changed milestone from 4.12.0 to 5.0

[2017-01-18 21:20:38 UTC] sjamaan wrote:

This requires sweeping changes, so better not mess with this for the 4.x series.

[2017-04-07 19:57:42 UTC] sjamaan changed milestone from 5.0 to 5.1

[2017-04-07 19:57:42 UTC] sjamaan wrote:

The reason this does not work is that each statement after a define ensures a following set of defines will start a new "letrec" block. Of course, that means forward references in earlier letrec blocks can't "see" definitions of inner letrec blocks. I'm not sure it's worthwhile or even desirable to make this work differently.

On the other hand, I can imagine a system that works more like the toplevel, where each define simply causes the definition to be made, so that any later define can refer back to it (but, that means you could get undefined variable errors at runtime, I think)

The code that deals with this stuff is extremely hairy, though, and the benefit is marginal (and could break other code, too!). Maybe a documentation change is warranted instead of trying to fix this.

[2019-04-07 12:23:24 UTC] sjamaan changed milestone from 5.1 to 5.2

[2019-04-07 12:23:24 UTC] sjamaan wrote:

Getting ready for 5.1, moving tickets which won't make it in to 5.2.

[2019-08-25 10:41:08 UTC] felix wrote:

Remark: alexpander has a nice feature where `(define <form>)` allows an arbitrary expression <form> in any definition context to be treated as a definition, without terminating a sequence of local definitions.

[2019-11-07 17:11:36 UTC] sjamaan wrote:

As Evan remarked:

> These work fine: > > define-record > define-record-type > define-values > > These don't work, but they also don't really make sense outside the > toplevel (and most of them are documented as such) so I think they're > fine to ignore: > > define-constant > define-external > define-foreign-type > define-foreign-variable > define-inline > define-interface > define-location > > These don't work, but seem like they probably ought to: > > define-compiler-syntax > define-for-syntax > define-reader-ctor > define-record-printer > define-specialization > define-syntax > define-type

[2019-11-07 17:12:17 UTC] sjamaan changed milestone from 5.2 to 5.3

[2019-11-07 17:12:17 UTC] sjamaan wrote:

Not important enough for 5.2 IMO

[2021-04-12 13:49:34 UTC] sjamaan changed milestone from 5.3 to 5.4

[2021-04-12 13:49:34 UTC] sjamaan wrote:

Maybe we can review the things starting with `define-` for 5.4. At least in 5.2 we deprecated `define-record-printer` in favour of `set-record-printer!` which takes care of the original ticket description.

[2023-11-06 22:04:22 UTC] felix changed milestone from 5.4 to someday

[2023-11-06 23:58:19 UTC] felix changed status from new to closed

[2023-11-06 23:58:19 UTC] felix set resolution to wontfix