c4834f91d0e7 — Linus Bj√∂rnstam 1 year, 3 months ago
Added (ice-9 threads) to the used modules, since it was removed from (guile).

Added a custom printer.
1 files changed, 20 insertions(+), 0 deletions(-)

M fector.scm
M fector.scm +20 -0
@@ 27,6 27,11 @@ 
 ;; since a fiber may be re-scheduled on a different thread. If anyone has a low-cost fix
 ;; for this i'd love to hear about it.
+;; TODO: Evaluate using RRB-trees for the fectors. This would allow efficient appends and splices
+;;       at very little cost for guile 3 (which can generate fast code paths). RRB-trees are a
+;;       strict superset of the data structure used here, but with relaxed rules about how many
+;;       elements in a node. What this means for fectors is: more expensive lookups AFTER a splices
+;;       or append has been made.
 ;; TODO: why is fector-ref so much slower than vlist-ref?
 ;;       have a look at immer pvectors to see if there is anything they are doing except being
 ;;       c++.

@@ 34,10 39,15 @@ 
 ;; TODO: Rewrite (cond ... (else (cond ...)).
 ;; TODO: Should we allow for regular fectors in transient procedures with implicit conversion?
 ;;       It is comfortable, but just mixing it is bad style.
+;; TODO: Make a fector-generator that will provide a nice way to iterate through the fector
+;;       that also has a configurable start and end. This could be usable when writing
+;;       procedures like fector-copy that allows for subfectors to be copied.
 (define-module (fector)
   #:use-module (srfi srfi-9)
+  #:use-module ((srfi srfi-9 gnu) #:select (set-record-type-printer!))
   #:use-module (ice-9 atomic)
   #:use-module (ice-9 match)
+  #:use-module (ice-9 threads)
   #:export (fector?

@@ 685,3 695,13 @@ 
     (if (= -1 index)
         (loop (1- index) (+ sum (fector-ref fec index))))))
+(define (display-fector f port)
+  (if (transient-fector? f)
+      (display "#transient-fector")
+      (display "#fector"))
+  (display (fector->list f) port))
+(set-record-type-printer! <fector> display-fector)
+(set-record-type-printer! <transient-fector> display-fector)