Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
18
Task/Polymorphic-copy/Racket/polymorphic-copy-1.rkt
Normal file
18
Task/Polymorphic-copy/Racket/polymorphic-copy-1.rkt
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#lang racket/base
|
||||
|
||||
(define (copy-prefab-struct str)
|
||||
(apply make-prefab-struct (vector->list (struct->vector str))))
|
||||
|
||||
(struct point (x y) #:prefab)
|
||||
(struct point/color point (color) #:prefab)
|
||||
|
||||
|
||||
(let* ([original (point 0 0)]
|
||||
[copied (copy-prefab-struct original)])
|
||||
(displayln copied)
|
||||
(displayln (eq? original copied)))
|
||||
|
||||
(let* ([original (point/color 0 0 'black)]
|
||||
[copied (copy-prefab-struct original)])
|
||||
(displayln copied)
|
||||
(displayln (eq? original copied)))
|
||||
19
Task/Polymorphic-copy/Racket/polymorphic-copy-2.rkt
Normal file
19
Task/Polymorphic-copy/Racket/polymorphic-copy-2.rkt
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#lang racket/base
|
||||
|
||||
(define (copy-struct str)
|
||||
(define-values (str-struct-info _) (struct-info str))
|
||||
(define str-maker (struct-type-make-constructor str-struct-info))
|
||||
(apply str-maker (cdr (vector->list (struct->vector str)))))
|
||||
|
||||
(struct point (x y) #:transparent)
|
||||
(struct point/color point (color) #:transparent)
|
||||
|
||||
(let* ([original (point 0 0)]
|
||||
[copied (copy-struct original)])
|
||||
(displayln copied)
|
||||
(displayln (eq? original copied)))
|
||||
|
||||
(let* ([original (point/color 0 0 'black)]
|
||||
[copied (copy-struct original)])
|
||||
(displayln copied)
|
||||
(displayln (eq? original copied)))
|
||||
16
Task/Polymorphic-copy/Racket/polymorphic-copy-3.rkt
Normal file
16
Task/Polymorphic-copy/Racket/polymorphic-copy-3.rkt
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
;#lang racket
|
||||
|
||||
(define point%
|
||||
(class object%
|
||||
(super-new)
|
||||
(init-field x y)
|
||||
(define/public (clone) (new this% [x x] [y y]))
|
||||
(define/public (to-list) (list this% x y))))
|
||||
|
||||
(define point/color%
|
||||
(class point%
|
||||
(super-new)
|
||||
(inherit-field x y)
|
||||
(init-field color)
|
||||
(define/override (clone) (new this% [x x] [y y] [color color]))
|
||||
(define/override (to-list) (list this% x y color))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue