Arc Forumnew | comments | leaders | submitlogin
2 points by rocketnia 3276 days ago | link | parent

  (define-values (*gtk-in* *gtk-out* _) (process "gtk-server -stdin"))
Well, Arc doesn't have a way to open processes that take stdin. Fortunately, Racket does, and if you're using Anarki, the $ macro makes it easy to write little pieces of Racket code in your Arc programs when necessary.

Racket's interface for (process ...) might be a bit different than Chicken Scheme's, so I found the documentation here: http://docs.racket-lang.org/reference/subprocess.html.

  (let (i o . ignored) ($.process "gtk-server -stdin")
    (= gtk-in i)
    (= gtk-out o))
The ($.process ...) call returns a list, and (let ...) destructures that list to make local bindings for i and o. This doesn't set up any global bindings, so I do that inside the (let ...).

---

I have a few corrections for this:

  (def gtk str
    (write str gtk-out)
    (if (~is "gtk_server_exit")
      (read-line gtk-in)))
Here's the corrected version:

  (def gtk (str)
    (disp (+ str "\n") gtk-out)
    (if (~is str "gtk_server_exit")
      (readline gtk-in))
The biggest difference is that I'm using (disp ...) where you were using (write ...). The functionality of (write ...) is to output s-expressions according to the same syntax you write code with, and this means written strings will always have quotation marks around them, which probably isn't what you want.

---

Thanks for exploring these interesting topics. :)