By the way, here's what an argmunger looks like in Arc:
I've changed the method signature so the munger is the first argument: that's because (argmunge m1 (argmunge m2 f)) is equal to (argmunge m1:m2 f). It's usual in operad theory to have the munging functions acting on the right: this is because they usually only consider munging functions which are invertible (ie, permutations), and use the definition (sticking with Lisp notation):
(def argmunge (munger victim) (fn args (apply victim (map args munger))))It's used like so:
arc> ((argmunge '(1 0) cons) 'x 'y) (y . x) arc> ((argmunge '(2 3 1 1 0 3 2) list) 'a 'b 'c 'd 'e 'f 'g) (c d b b a d c)That took a couple of minutes to write, and worked first time. Sw33t! Though I thought I'd got it wrong at first, as there was a bug in my test code :-) Note, by the way, that I'm mapping one list over another, to get the moral equivalent of Perl's list-slicing: this is a spin-off of the way that Arc treats function calls and data-structure indexing as indistinguishable. I'd hoped that I could write an argmunger that could be handed either a list or a function as its munger and Do The Right Thing, but unfortunately I don't think there's any way of determining the domain of an Arc function (the equivalent of the list's length) automatically.
I've changed the method signature so the munger is the first argument: that's because (argmunge m1 (argmunge m2 f)) is equal to (argmunge m1:m2 f). It's usual in operad theory to have the munging functions acting on the right: this is because they usually only consider munging functions which are invertible (ie, permutations), and use the definition (sticking with Lisp notation):
((argmunge' f m) x(m 0) x(m 1) ...) = (f x0 x1 ...)So (argmunge' f m) is equal to (argmunge m-1 f). With this definition (which is fine if you only allow permutations) then (argmunge' (argmunge' f m1) m2) is equal to (argmunge' f m1:m2), so it makes more sense for the arguments to be that way round. But when you allow your munging function to be noninvertible, you have to use the definition I gave, and then it makes more sense to have the mungers acting on the left.
Tags: