Arc Forumnew | comments | leaders | submitlogin
1 point by Zak 6170 days ago | link | parent

Probably not, but it's still useful as a generic way to write generator functions. Your par macro isn't working as expected for me. Is this a bug, or am I using it wrong?

  (def accgen (n) (par ++ n))
  #<procedure: accgen>
  arc> (= foo (accgen 5))
  #<procedure>
  arc> (foo 8)
  Error: "Function call on inappropriate object #3(tagged mac #<procedure>) (5 8)"


1 point by rkts 6170 days ago | link

Well, I was thinking par would be call-by-value. So your accumulator would have to be something like

  (def ref (x) (obj contents x))

  (def ++ref (x (o by 1)) (++ (x 'contents) by))

  (def accgen (n) (par ++ref (ref n)))
I don't know if a call-by-reference par could be implemented using macros. I also don't know that that's a good idea, since it could lead to bugs when mutation is involved.

  (= fns nil)

  (= x 1)
  (push (par + x) fns)

  (= x 2)
  (push (par + x) fns)

  (= x 3)
  (push (par + x) fns)

  (map [_ 1] fns) => (4 4 4)  ; probably not what you want
Edit: I think the issue is that we have slightly different definitions of partial application. You are thinking of it as a sort of syntactic sugar on top of closures, whereas I (being primarily an ML programmer) am used to thinking of partial application as a function call. So that's why we have different intuitions about how it should work.

-----

1 point by rkts 6170 days ago | link

By the way, why are you bothering with generators? Arc being an exploratory language, the idea seems to be to use lists for everything, at least at first. Iterators/generators are often a premature optimization.

-----

1 point by sjs 6170 days ago | link

Did you mean to write (def accgen (n) (par + n))?

-----

3 points by Zak 6170 days ago | link

I did not: an accumulator increments. See http://paulgraham.com/accgen.html

-----