cs: fix display and print when print-vector-length is enabled

Don't use print-vector-length in `display`.

Use print-vector-length in `print` for fxvectors and flvectors.
This commit is contained in:
Gustavo Massaccesi 2019-07-26 23:58:15 -03:00
parent 63173a32be
commit ecaff3dc96
2 changed files with 44 additions and 26 deletions

View File

@ -16,6 +16,7 @@
"char.rkt"
"list.rkt"
"mlist.rkt"
"vector.rkt"
"hash.rkt"
"named.rkt"
"parameter.rkt"
@ -236,34 +237,11 @@
[(pair? v)
(print-list p who v mode o max-length graph config #f #f)]
[(vector? v)
(cond
[(and (not (eq? mode PRINT-MODE/UNQUOTED))
(config-get config print-vector-length))
(define len (vector-length v))
(define same-n
(cond
[(zero? len) 0]
[else
(let loop ([i (sub1 len)] [accum 0])
(cond
[(zero? i) accum]
[(eq? (vector-ref v (sub1 i)) (vector-ref v i))
(loop (sub1 i) (add1 accum))]
[else accum]))]))
(define lst (if (zero? same-n)
(vector->list v)
(for/list ([e (in-vector v 0 (- len same-n))])
e)))
(define lbl (string-append "#" (number->string len) "("))
(print-list p who lst mode o max-length graph config lbl "(vector")]
[else
(print-list p who (vector->list v) mode o max-length graph config "#(" "(vector")])]
(print-vector p who v mode o max-length graph config "" vector-length vector-ref eq?)]
[(flvector? v)
(define l (for/list ([e (in-flvector v)]) e))
(print-list p who l mode o max-length graph config "#fl(" "(flvector")]
(print-vector p who v mode o max-length graph config "fl" flvector-length flvector-ref equal?)]
[(fxvector? v)
(define l (for/list ([e (in-fxvector v)]) e))
(print-list p who l mode o max-length graph config "#fx(" "(fxvector")]
(print-vector p who v mode o max-length graph config "fx" fxvector-length fxvector-ref eq?)]
[(box? v)
(cond
[(config-get config print-box)

View File

@ -0,0 +1,40 @@
#lang racket/base
(require "list.rkt"
"mode.rkt"
"config.rkt"
"parameter.rkt")
(provide print-vector)
(define (print-vector p who v mode o max-length graph config fx/l-prefix v-length v-ref equ?)
(define (v->list v len)
(cond
[(zero? len) '()]
[else (let loop ([i (sub1 len)] [accum '()])
(define val (v-ref v i))
(cond
[(zero? i) (cons val accum)]
[else (loop (sub1 i) (cons val accum))]))]))
(define cns (string-append "(" fx/l-prefix "vector"))
(cond
[(and (not (eq? mode PRINT-MODE/UNQUOTED))
(not (eq? mode DISPLAY-MODE))
(config-get config print-vector-length))
(define len (v-length v))
(define same-n
(cond
[(<= len 1) 0]
[else
(define last (v-ref v (sub1 len)))
(let loop ([i (- len 2)] [accum 0])
(cond
[(< i 0) accum]
[(equ? (v-ref v i) last)
(loop (sub1 i) (add1 accum))]
[else accum]))]))
(define lst (v->list v (- len same-n)))
(define lbl (string-append "#" fx/l-prefix (number->string len) "("))
(print-list p who lst mode o max-length graph config lbl cns)]
[else
(define lbl (string-append "#" fx/l-prefix "("))
(print-list p who (v->list v (v-length v)) mode o max-length graph config lbl cns)]))