Talk:Averages/Simple moving average: Difference between revisions

m
m (J: remove some ambiguity)
Line 28:
:: Please add the framework (Proc Options(main)) to show how this could be used.--[[User:Walterpachl|Walterpachl]] ([[User talk:Walterpachl|talk]]) 09:54, 30 January 2014 (UTC)
 
== J ALternateAlternate Implementation ==
 
Here is a streaming variant of the J implementation, with a description:
Line 41:
)</lang>
 
The "inner" (most indented) definition is a verb which takes two arguments: A numbernamespace (<code>yx</code>) and a namespacenumber (<code>xy</code>). In the inner definition <code>n__x=.1|.!.y n__x</code> shifts the number <code>y</code> into the list named <code>n</code> in the <code>x</code> namespace. Then, <code>(+/%#)(#~1-128!:5)n__x</code> removes all NaN values from the list and finds the average of the values that remain.
 
The "outer" definition here is a conjunction which takes two arguments: A number (<code>m</code>) and the verb (<code>v</code>) defined above. In this outer definition, <code>a=.cocreate<nowiki>''</nowiki></code> defines a new, empty namespace <code>a</code>. Then, <code>n__a=.m#_.</code> populates the name <code>n</code> in that namespace with <code>m</code> NaN values. Finally, we curry the verb <code>v</code> with this namespace and return the derived verb.
6,962

edits