Arc Forumnew | comments | leaders | submitlogin
Ellipsize REPL Output
3 points by fallintothis 3350 days ago | discuss
Prompted by the side note at http://arclanguage.org/item?id=12256, here's a fun toy I whipped up to solve the problem of overly-long REPL output.

  (def terse-repl ((o limit 80))
    (prn "Use (verbose-repl) to turn off ellipsized output.")
    (catch
      (while t
        (disp "arc> ")
        (on-err [do (disp "Error: ") (write (details _)) (prn)]
                (fn ()
                  (let expr (read)
                    (if (is expr ':a)
                         (quit)
                        (iso expr '(verbose-repl))
                         (do (prn "Turning off ellipsized output.")
                             (throw))
                         (let val (eval expr)
                           (prn (ellipsize (tostring (write val)) limit))
                           (= that val thatexpr expr)))))))))


  arc> (terse-repl)
  Use (verbose-repl) to turn off ellipsized output.
  arc> (= x (n-of 1000000 (rand)))
  (0.9777547694679798 0.07493917168754799 0.13700886175451876 0.6612940629825846 0...
  arc> (verbose-repl)
  Turning off ellipsized output.
  nil
  arc> (len x)
  1000000
Not very useful, but I thought I'd share it anyway.