Arc Forumnew | comments | leaders | submitlogin
2 points by kinnard 3129 days ago | link | parent

I think I understand. You want a function that prints arbitrary user prompts and then takes in user inputs?

You should share your hack!



3 points by mpr 3128 days ago | link

Yep, thats the idea. Anyway, here is my hack, in all its hackish glory:

    (define (trash-line c)
      (if (equal? c #\newline)
        '()
        (trash-line (read-char))))

    (define (tl2 interactive?)
      (when interactive? (display "arc> "))
      (on-err (lambda (c)
                (set! last-condition* c)
                (parameterize ((current-output-port (current-error-port)))
                  ((error-display-handler) (exn-message c) c)
                  (newline))
                (tl2 interactive?))
        (lambda ()
          (let ((expr (read)))

            ;; HACK located here
            (trash-line (read-char)) ; throw away until we hit the newline


            (if (eof-object? expr)
                 (begin (when interactive? (newline))
                        (exit)))
            (if (eqv? expr ':a)
                'done
                (let ((val (arc-eval expr)))
                  (when interactive?
                    (write (ac-denil val))
                    (newline))
                  (parameterize ((current-namespace (main-namespace)))
                    (namespace-set-variable-value! '_that val)
                    (namespace-set-variable-value! '_thatexpr expr))
                  (tl2 interactive?)))))))
So I call the trash-line function after the expr is read, but before it is eval'd by arc, so that there is not leading #\newline in the input buffer.

This does seem to work for the readline'ing I was doing yesterday. Probably doesn't handle all cases.

As akkartik mentioned above, this hack is obviated by running scripts in batch mode.

-mpr

Edit: this change is in my ac.scm file around line 1250

-----

2 points by akkartik 3128 days ago | link

I like it! I don't think it'll break anything; can you send a pull request? Then we'll be able to run such code reliably at the repl! That would be sweet.

Edit 38 minutes later: hmm, there's one issue. Right now you can type multiple expressions in on a single line, but this change would drop everything after the end of the first expression. A better approach would be to drop only whitespace and stop at the very first non-whitespace character.

-----

2 points by mpr 3128 days ago | link

Thanks! Yeah, I am aware of that bug, and was kind of ignoring it ;) I'll implement your suggested fix then send a pull request.

-----

3 points by mpr 3128 days ago | link

Pull request submitted

-----