Sigrid Solveig Haflínudóttir*print-circle*0b343aa1 year agoHistory
47 lines · 1.2 KB · Text
RawDownload
(def (maplist f l)  (and l (cons (f l) (maplist f (cdr l))))) ; produce a beautiful, toroidal cons structure; make m copies of a CDR-circular list of length n, and connect corresponding; conses in CAR-circular loops; replace maplist 'identity' with 'copy-tree' for rapdily exploding memory use(def (torus m n)  (let* ((l (map-int identity n))         (g l)         (prev g))    (dotimes (i (- m 1))      (set! prev g)      (set! g (maplist identity g))      (set-cdr! (last-pair prev) prev))    (set-cdr! (last-pair g) g)    (let ((a l)          (b g))      (dotimes (i n)        (set-car! a b)        (set! a (cdr a))        (set! b (cdr b))))    l)) (def (cyl m n)  (let* ((l (map-int identity n))         (g l))    (dotimes (i (- m 1))      (set! g (maplist identity g)))    (let ((a l)          (b g))      (dotimes (i n)        (set-car! a b)        (set! a (cdr a))        (set! b (cdr b))))    l)) (time (with-bindings ((*print-circle* T))        (print (torus 100 100))));(time (dotimes (i 1) (load "100x100.sl"))); with ltable; printing time: 0.415sec; reading time: 0.165sec ; with ptrhash; printing time: 0.081sec; reading time: 0.0264sec

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t