[racket] serializable class definition inside unit body

From: seryojka (iamfakemail at yandex.ru)
Date: Mon Jun 9 09:44:42 EDT 2014

On 06/09/2014 03:35 PM, Matthias Felleisen wrote:
>
> Can you lift the class to the #lang module level? If not, why not?
>

I can't.

I have two modules, which I would like to keep separate. They look like this

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; mixin-set.rkt

#lang racket

(require "final.rkt")

(define some-mixin
   (mixin () ()
     (inspect #f)
     (super-new)

     (define/public (get-class)
       ;; I need particular class here, not this%
       final-class%)

     ;; more  methods here
     ))


;; many other mixins, closely related to some-mixin


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; final.rkt

#lang racket

(require "mixin-set.rkt"
          ;; another modules with sets of mixins
          )

(define-serializable-class final-class% (some-mixin ;; more mixins here
                                          object%)
   (super-new))

;; more classes here

;;; end



This will produce "standard-module-name-resolver: cycle in loading" 
error, which I could handle for nonserializable classes using units:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; mixin-set-sig.rkt

#lang racket/signature

some-mixin

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; mixin-set-unit.rkt

#lang racket/unit

(require racket/class

          "final-sig.rkt"
          "mixin-set-sig.rkt")

(import final^)
(export mixin-set^)


(define some-mixin
   (mixin () ()
     (inspect #f)
     (super-new)

     (define/public (get-class)
       final-class%)))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; final-sig.rkt

#lang racket/signature

final-class%

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; final-unit.rkt

#lang racket/unit

(require racket/class

          "mixin-set-sig.rkt"
          "final-sig.rkt")

(import mixin-set^)
(export final^)

(define final-class%
   (class (some-mixin object%)
     (super-new)))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; linked.rkt

#lang racket

(require "final-sig.rkt"
          "final-unit.rkt"
          "mixin-set-unit.rkt")

(define-compound-unit/infer linked@
   (import )
   (export final^)
   (link mixin-set@ final@))


(define-values/invoke-unit/infer linked@)

(send (new final-class%) get-class)

;;; end

But this will not work with serializable class.













Posted on the users mailing list.