[racket] serializable class definition inside unit body

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Jun 9 14:58:11 EDT 2014

So try to work with abstract methods for now (template an hook pattern) and see whether this works out. 






On Jun 9, 2014, at 1:56 PM, seryojka <iamfakemail at yandex.ru> wrote:

> Not really, because class with initialization variables couldn't be deserialized. I, actually, have came with similiar solution with abstract method:
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;;; mixin-set.rkt
> 
> #lang racket
> 
> (require racket/class)
> 
> (provide some-mixin)
> 
> (define some-mixin
>  (mixin () ()
>    (inspect #f)
>    (super-new)
>    (abstract get-class)))
> 
> 
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;;; final.rkt
> 
> #lang racket
> 
> (require "mixin-set.rkt")
> 
> (define-serializable-class final-class% (some-mixin object%)
>  (super-new)
> 
>  (define/override (get-class)
>    final-class%))
> ;;; ----
> 
> But now, I can't to remember the reason I didn't accepted it...
> Probably, I've started searching for solution without confirming actuality of problem. In that case I apologize for wasting time.
> 
> 
> On 06/09/2014 09:55 PM, Matthias Felleisen wrote:
>> 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/8792216b/attachment-0001.p7s>

Posted on the users mailing list.