Arc Forumnew | comments | leaders | submitlogin
Can you help with shortening this code?
4 points by CatDancer 6106 days ago | 4 comments
I need to read N bytes from a stream and return the result as a list. Currently I'm using:

  (rev (accum a
    (repeat n
      (a (readb stream))))
but it seems like there ought to be a shorter / more elegant way of doing this. Can you help?

If you offer code suggestions, please let me know if it will run in arc2 or needs Anarki.

Thanks!



6 points by sjs 6106 days ago | link

How about this?

  (map [readb stream] (range 1 n))
It probably doesn't perform as well on big inputs.

-----

3 points by CatDancer 6106 days ago | link

I like that better than my code. ^_^

As for performance... hard to say, I think. My version conses up a big list and then reverses it, your version conses up a big list and then maps it. So without some actual testing or analysis...

-----

4 points by rkts 6106 days ago | link

  (n-of n (readb stream))

-----

1 point by CatDancer 6106 days ago | link

There we go!

-----