mildc055ee
2021-9-26 15:56:30

hi, I want to know how to change the output rules of pretty-print . I’ve read the documentation for pretty-print, but I couldn’t figure out how to use the procedures at all. input: (define input '(module (import "" "add" (func $add ...)) (import "" "sub" (func $sub ...)) (import "" "mul" (func $mul ...)) ...)) actual: (pretty-print input) > '(module (import "" "add" (func $add ...)) (import "" "sub" (func $sub ...)) (import "" "mul" (func $mul ...)) ...) expected: (pretty-print input) > '(module (import "" "add" (func $add ...)) (import "" "sub" (func $sub ...)) (import "" "mul" (func $mul ...)) ...)


soegaard2
2021-9-26 16:09:52

@mildc055ee Something like: #lang racket (require racket/pretty) (define input '(module (import "" "add" (func $add ...)) (import "" "sub" (func $sub ...)) (import "" "mul" (func $mul ...)) ...)) (define my-style (pretty-print-extend-style-table (pretty-print-current-style-table) '(module) '(begin))) (pretty-print-current-style-table my-style) (pretty-print-columns 80) (pretty-print input)


soegaard2
2021-9-26 16:10:12

Here we make your custom module form print like a normal Racket begin form.


sorawee
2021-9-26 22:21:27

Advertisement time: with https://github.com/sorawee/fmt, you can also pretty print the above code with more extensibility and prettiness:

#lang racket (require fmt) (define input '(module (import "" "add" (func $add ...)) (import "" "sub" (func $sub ...)) (import "" "mul" (func $mul ...)) (let ([x 1]) (set! x (add1 x)) (set! x (add1 x))))) (define (my-format name) (case name [("module") (format-node-uniform-body 0)] [("import") format-node-#%app] [else (standard-format name)])) (pretty-print* input #:format my-format) outputs:

'(module (import "" "add" (func $add ...)) (import "" "sub" (func $sub ...)) (import "" "mul" (func $mul ...)) (let ([x 1]) (set! x (add1 x)) (set! x (add1 x)))) whereas with the racket/pretty library, it outputs:

'(module (import "" "add" (func $add ...)) (import "" "sub" (func $sub ...)) (import "" "mul" (func $mul ...)) (let ((x 1)) (set! x (add1 x)) (set! x (add1 x))))


capfredf
2021-9-27 02:47:25

@mflatt On Linux, package maintainers have to manually add .LOCKpkgs.rktd in order for Drracket to work. Is this a recommended approach? https://github.com/racket/racket/issues/3851#issuecomment-927457199


soegaard2
2021-9-27 05:49:32

Great initiative!