Arc Forumnew | comments | leaders | submitlogin
1 point by Pauan 4973 days ago | link | parent

Oh! It seems that w/pipe-from is only in my own personal copy of Arc... it isn't included by default. Here you go:

  (mac w/pipe-from (var expr . body)
    `(let ,var (pipe-from ,expr)
       (after (do ,@body) (close ,var))))
It would appear readlines is also specific to my copy of Arc, so here it is as well:

  (def readlines (x)
    (drain:readline x))
I have included lots of useful stuff like that in my fork of Arc... And here is an obvious shortened version, for the common case of getting the output as a list of strings:

  (def pipe-lines (y)
    (w/pipe-from x y readlines.x))
Now you can just do (pipe-lines "ls -l")


2 points by akkartik 4973 days ago | link

In similar vein I showed a pipe-to a while back: http://arclanguage.org/item?id=14621

-----

1 point by Pauan 4973 days ago | link

I'm trying to get a generic pipe function working... here's the gist of it:

  (w/pipe "grep 'other'"
    (prn "other")
    (readlines))
Should return "other", but instead it's hanging... gotta figure out why. In any case, both pipe-to and pipe-from are now defined in terms of pipe.

---

I've also changed w/pipe-from so it automatically redirects to stdin:

  (w/pipe-from "ls -l" (readlines))

-----

1 point by Pauan 4973 days ago | link

"Should return "other", but instead it's hanging... gotta figure out why."

Ahhh, I got it... it's waiting for the pipe to close:

  (w/pipe "grep 'other'"
    (prn "other")
    (close stdout)
    (readlines))
That makes things trickier...

-----