[racket] serializable class definition inside unit body

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Jun 9 12:55:47 EDT 2014

Would this work for you: 

#lang racket

;; file 1: 
(module mixin-set.rkt racket
  (provide some-mixin)
  
  (define some-mixin
    (mixin () ()
      (init-field final-class%)
      (inspect #f)
      (super-new)
      
      (define/public (get-class)
        ;; I need particular class here, not this%
        final-class%))))

;; file 2:
(module final.rkt racket
  (require (submod ".." mixin-set.rkt))
  (provide final-class%)
  
  (define-serializable-class final-class% 
    (some-mixin object%)
    (super-new [final-class% this%])))

(require 'final.rkt)





On Jun 9, 2014, at 9:44 AM, seryojka <iamfakemail at yandex.ru> wrote:

> 
> 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.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4463 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20140609/600ffb15/attachment.p7s>

Posted on the users mailing list.