Talk:Averages/Simple moving average: Difference between revisions

m
J: remove some ambiguity
(→‎PL/I and problem description: please add framework and output)
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 ALternate Implementation ==
 
Here is a rephrasingstreaming variant of the J implementation, with a description:
 
<lang J>lex =: conjunction define(dyad define)
Line 41:
)</lang>
 
The "inner" (most indented) definition is a verb which takes two arguments: A number (<code>y</code>) and a namespace (<code>x</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 athe verb (<code>v</code>). (In the original definition, there was no v and instead that verb was defined in placeabove.) 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.
 
--[[User:Rdm|Rdm]] 18:04, 7 June 2010 (UTC)
6,962

edits