March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
|
|
@ -1,5 +1,4 @@
|
|||
@interface T : NSObject
|
||||
{ }
|
||||
- (void)identify;
|
||||
@end
|
||||
|
||||
|
|
@ -17,7 +16,6 @@
|
|||
@end
|
||||
|
||||
@interface S : T
|
||||
{ }
|
||||
@end
|
||||
|
||||
@implementation S
|
||||
|
|
@ -29,11 +27,12 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
T *original = [[S alloc] init];
|
||||
T *another = [original copy];
|
||||
[another identify]; // logs "I am an S"
|
||||
@autoreleasepool {
|
||||
|
||||
[another release]; // like "alloc", the object returned by "copy" is "owned" by the caller, so we are responsible for releasing it
|
||||
[original release];
|
||||
T *original = [[S alloc] init];
|
||||
T *another = [original copy];
|
||||
[another identify]; // logs "I am an S"
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,19 @@
|
|||
;#lang racket
|
||||
#lang racket/base
|
||||
|
||||
(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 (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)))))
|
||||
|
||||
(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))))
|
||||
(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