chansey97
2021-4-17 19:39:28

A question about dotted list: '(1 2 . 3) ;; => '(1 2 . 3) That’s OK. However '(1 . 2 . 3) ;; => '(2 1 3) produced a list. Why?

I hope '(1 . 2 . 3) ; => '(1 2 . 3) which == (cons 1 (cons 2 3))


soegaard2
2021-4-17 19:40:26

That’s a Racket only extension. The idea is that (1 . < . x) turns into (< 1 x).


chansey97
2021-4-17 19:41:48

but I have a quotation



chansey97
2021-4-17 19:42:11

It should not be seen as an application imo.


soegaard2
2021-4-17 19:43:01

It’s done on the reader level, so it works for everything that looks like a list.


soegaard2
2021-4-17 19:43:16

It’s the last paragraph of the link above.


chansey97
2021-4-17 19:43:56

> (1 . 2 . 3) reads equal to (list 2 1 3)


chansey97
2021-4-17 19:43:59

Thanks.


chansey97
2021-4-17 23:00:25

I need to pretty print a two-dimensional list. I did not find it on the internet, so I had to write it by myself. (define (print-2-dim-list lol) (define (transpose xss) (apply map list xss)) (define t (transpose lol)) (define list-of-max-len (map (λ (l) (foldr (λ (x v) (max (string-length (format "~a" x)) v)) 0 l)) t)) (printf "(\n") (for ([row lol]) (printf "(") (for ([x row] [max-len list-of-max-len]) (printf "~a" x) (for ([n (+ 1 (- max-len (string-length (format "~a" x))))]) (printf "~a" #\space))) (printf ")\n") ) (printf ")\n")) (print-2-dim-list '((xxx xx xxx) (xx xxxxxxxxxxx xxxxxxxxx) (xxx xxx xxxxx) (xxx xxxxxxxxxxxxx xxxxxxxxxxxx) (xxxxxxxxxxxxx xxx xxxxxxxxxx))) ;; ( ;; (xxx xx xxx ) ;; (xx xxxxxxxxxxx xxxxxxxxx ) ;; (xxx xxx xxxxx ) ;; (xxx xxxxxxxxxxxxx xxxxxxxxxxxx ) ;; (xxxxxxxxxxxxx xxx xxxxxxxxxx ) ;; ) I think my code may be a bit verbose. Any suggestion?


sorawee
2021-4-18 00:27:29

chansey97
2021-4-18 00:37:31

(displayln (table-&gt;string '((xxx xx xxx) (xx xxxxxxxxxxx xxxxxxxxx) (xxx xxx xxxxx) (xxx xxxxxxxxxxxxx xxxxxxxxxxxx) (xxxxxxxxxxxxx xxx xxxxxxxxxx)) #:border-style 'space #:framed? #t #:row-sep? #f #:align '(left))) ;; xxx xx xxx ;; xx xxxxxxxxxxx xxxxxxxxx ;; xxx xxx xxxxx ;; xxx xxxxxxxxxxxxx xxxxxxxxxxxx ;; xxxxxxxxxxxxx xxx xxxxxxxxxx Nice! @sorawee Thank you for telling me this information.


chansey97
2021-4-18 00:38:40

Anyway it can’t preserve the parentheses. I think my procedure may still useful:smile:.


sorawee
2021-4-18 00:38:43

Well, thanks @laurent.orseau for creating the package!