Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
24
Task/Polymorphic-copy/EchoLisp/polymorphic-copy.echolisp
Normal file
24
Task/Polymorphic-copy/EchoLisp/polymorphic-copy.echolisp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
(lib 'types)
|
||||
(lib 'struct)
|
||||
|
||||
(struct T (integer:x)) ;; super class
|
||||
(struct S T (integer:y)) ;; sub class
|
||||
(struct K (T:box)) ;; container class, box must be of type T, or derived
|
||||
|
||||
(define k-source (K (S 33 42)))
|
||||
(define k-copy (copy k-source))
|
||||
|
||||
k-source
|
||||
→ #<K> (#<S> (33 42)) ;; new container, with a S in box
|
||||
k-copy
|
||||
→ #<K> (#<S> (33 42)) ;; copied S type
|
||||
|
||||
(set-S-y! (K-box k-source) 666) ;; modify k-source.box.y
|
||||
|
||||
k-source
|
||||
→ #<K> (#<S> (33 666)) ;; modified
|
||||
k-copy
|
||||
→ #<K> (#<S> (33 42)) ;; unmodified
|
||||
|
||||
(K "string-inside") ;; trying to put a string in the container box
|
||||
😡 error: T : type-check failure : string-inside → 'K:box'
|
||||
Loading…
Add table
Add a link
Reference in a new issue