The dust bin of grammar
Define an adverb A to apply to a verb in such a way that the verb is executed only on the nub of the argument, and the result is then expanded to give the same effect as if the verb had been applied to each atom. The result of applying the adverb to a verb f should produce something like this f@~. +/ .* = J provides facilities to make the job easier. Simply create a character string that gives the definition, and use x for the verb argument (since it will be a left argument): s=. 'x@~. +/ .* =' and apply the adverb definition adverb 1 : to this: A=. 1 : s ^. 1 2 3 2 3 NB. log without A 0 0.693147 1.09861 0.693147 1.09861 ^. A 1 2 3 2 3 NB. log with A 0 0.693147 1.09861 0.693147 1.09861 Now try an argument containing lots of repetitions: y=. 10000#10 time '^. y' NB. log without A 3.03333 time '^. A y' NB. log with A 0.9 3.03333%0.9 3.37037 What does the derived verb look like? f=.^. A lr<'f' ^.@~. +/ .* = Just as we desired. |