Arc Forumnew | comments | leaders | submitlogin
Another ppr improvement (fixed ppr-call)
2 points by fallintothis 5417 days ago | discuss

  $ diff -u old-pprint.arc new-pprint.arc

  --- old-pprint.arc      2010-02-20 19:30:53.000000000 -0800
  +++ new-pprint.arc      2010-02-21 12:25:02.000000000 -0800
  @@ -46,16 +46,18 @@

   (def ppr-call (expr col noindent)
     (lpar)
  -  (let carstr (tostring (write (car expr)))
  +  (withs (carbroke nil
  +          carstr (tostring (= carbroke (ppr (car expr) (+ col 1) t))))
       (pr carstr)
  -    (if (cdr expr)
  -        (do (sp)
  -            (let broke (ppr (cadr expr) (+ col (len carstr) 2) t)
  -              (pprest (cddr expr)
  -                      (+ col (len carstr) 2)
  -                      (no broke)))
  -            t)
  -        (do (rpar) t))))
  +    (let new-col (if carbroke (+ col 1) (+ col (len carstr) 2))
  +      (if (cdr expr)
  +          (do (if carbroke (prn) (sp))
  +              (let broke (ppr (cadr expr) new-col (no carbroke))
  +                (pprest (cddr expr)
  +                        new-col
  +                        (no broke)))
  +              t)
  +          (do (rpar) t)))))

   (def pprest (exprs col (o oneline t))
     (if (and oneline
BEFORE:

  arc> (ppr '(def rev (xs) ((afn (xs acc) (if (no xs) acc (self (cdr xs) (cons (car xs) acc)))) xs nil)))
  (def rev (xs)
    ((afn (xs acc) (if (no xs) acc (self (cdr xs) (cons (car xs) acc)))) xs nil))t
AFTER:

  arc> (ppr '(def rev (xs) ((afn (xs acc) (if (no xs) acc (self (cdr xs) (cons (car xs) acc)))) xs nil)))
  (def rev (xs)
    ((afn (xs acc)
       (if (no xs)
           acc
           (self (cdr xs)
                 (cons (car xs) acc))))
     xs nil))t
More patches as they come!