Arc Forumnew | comments | leaders | submitlogin
how exactly does a:b work?
1 point by hkBst 6169 days ago | 3 comments
how exactly does the function composition syntax a:b work?

Does it only work on functions or on macros too?

Can I do (a:[+ _ 1] 3) or (a:(fn () 3))?

Why is : infix? The same considerations as for + seem to hold for : ("Putting the + before the numbers looks odd when you're used to writing "1 + 2," but it has the advantage that + can now take any number of arguments, not just two:"). That would also make (:) return the identity function. Simply define

(= : (fn x (fold compose id x))

(= (: . x) (fold compose id x)); wow, same length ;)



1 point by randallsquared 6169 days ago | link

The colon operator does work on macros, but not, currently, on anonymous functions. I'm not sure if there's a reason for that or if it's just a bug.

Note that you can chain together composed functions, so

    (a:b:c 'works)

-----

1 point by randallsquared 6168 days ago | link

Hrm. Also, (|a:b| ...) works, but shouldn't.

-----

2 points by nostrademons 6167 days ago | link

It's because the ~: syntax is expanded at evaluation time, not at read-time. The Arc compiler looks at each symbol, and if it has one of those characters, it splits on the :, wraps in (compose ...), and adds a (complement ...) form every time the section begins with ~.

-----