update
This commit is contained in:
parent
1f1ad49427
commit
6f050a029e
2496 changed files with 37609 additions and 3031 deletions
32
Task/Deepcopy/Aime/deepcopy.aime
Normal file
32
Task/Deepcopy/Aime/deepcopy.aime
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
list L1, L2;
|
||||
|
||||
# Lists are heterogeneous:
|
||||
l_append(L1, 3);
|
||||
l_append(L1, "deep");
|
||||
|
||||
# and may contain self references.
|
||||
# A self references in the last position:
|
||||
l_link(L1, -1, L1);
|
||||
|
||||
# List may also contain mutual references.
|
||||
# Create a new list in the last position:
|
||||
l_n_list(L1, -1);
|
||||
# Add a reference to the top level list to the nested list:
|
||||
l_link(l_q_list(L1, -1), -1, L1);
|
||||
|
||||
# There are no limitations to the deep copy method:
|
||||
l_copy(L2, L1);
|
||||
|
||||
# Modify the string in the original list,
|
||||
# via the self reference in the 3rd position
|
||||
l_r_text(l_q_list(L1, 2), 1, "copy");
|
||||
|
||||
# Show the string in the two lists:
|
||||
o_text(l_query(L2, 1));
|
||||
o_text(l_query(L1, 1));
|
||||
o_byte('\n');
|
||||
|
||||
# And again, via the included self references:
|
||||
o_text(l_query(l_query(L2, 2), 1));
|
||||
o_text(l_query(l_query(L1, 2), 1));
|
||||
o_byte('\n');
|
||||
14
Task/Deepcopy/Racket/deepcopy.rkt
Normal file
14
Task/Deepcopy/Racket/deepcopy.rkt
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#lang racket
|
||||
|
||||
(define (deepcopy x)
|
||||
;; make sure that all sharings are shown
|
||||
(parameterize ([print-graph #t]) (read (open-input-string (format "~s" x)))))
|
||||
|
||||
(define (try x)
|
||||
;; use the same setting to see that it worked
|
||||
(parameterize ([print-graph #t])
|
||||
(printf "original: ~s\n" x)
|
||||
(printf "deepcopy: ~s\n" (deepcopy x))
|
||||
;; print both also, which shows that they are indeed different
|
||||
(printf "both: ~s\n" (list x (deepcopy x)))))
|
||||
(try (shared ([x (cons 1 x)]) (list x x)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue