Arc Forumnew | comments | leaders | submitlogin
Problems with compose
2 points by shader 4765 days ago | 3 comments
I've run into an interesting case where akkartik's recent change from compose as a macro to a function has caused me some problems. In ppr, I map a heavily composed function len:tostring:print:car across a list, in order to compare the lengths of each expression. (code: https://github.com/nex3/arc/blob/master/load/ppr.arc#L44) Now, normally I suppose this wouldn't be a problem, but because tostring is a macro and the recent changes affect compositions that happen in non-functional position, this code no longer works.

This really doesn't deserve an entirely new topic, but unfortunately the time-limit on replies have expired.

So, should I just change the ppr code to fix the problem? Or is there a better solution that could accommodate both use cases?



1 point by akkartik 4765 days ago | link

Ah, I didn't intend to actually change behavior. Feel free to revert http://github.com/nex3/arc/commit/cbf2bd3e08 (or I'll do it this evening -- and figure out what I'm missing).

edit: Done (http://github.com/nex3/arc/commit/f72acc2997). I'm still unclear on why the macro form is different, and why it works in some macro situations but not others (I've added two examples to that commit)

-----

1 point by akkartik 4764 days ago | link

It seems we can use macros in compose as long as the rightmost arg isn't a macro.

  arc> (def a(x) (+ 1 x))
  arc> (mac b(x) `(+ 1 ,x))

  arc> (map a:b '(1 2 3))
  Error: "Can't coerce  #(tagged mac #<procedure: b>) fn"
  arc> (map b:a '(1 2 3))
  (3 4 5)
  arc> (map a:b:a '(1 2 3))
  (4 5 6)
  arc> (map b:b:a '(1 2 3))
  (4 5 6)
Ah, it's because of the call to apply in the base case. And my function version called apply at each step.

-----

1 point by rocketnia 4764 days ago | link

Whoops, I should have seen this coming when I commented at http://arclanguage.org/item?id=15172. ^_^;

-----