Anonymous user
Talk:Averages/Simple moving average: Difference between revisions
→J Implementation: new section
(→PL/I and problem description: Clarified?) |
(→J Implementation: new section) |
||
Line 25:
:Hi, hopefully the changes to the task description have clarified things. --[[User:Paddy3118|Paddy3118]] 04:11, 26 March 2010 (UTC)
== J Implementation ==
Here is a rephrasing of the J implementation, with a description:
<lang J>lex =: conjunction define(dyad define)
n__x=.1|.!.y n__x
(+/%#)(#~1-128!:5)n__x
)
a=.cocreate''
n__a=.m#_.
a&v
)</lang>
The inner 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 a verb (<code>v</code>). (In the original definition, there was no v and instead that verb was defined in place.) 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.
--[[Special:Contributions/159.54.131.7|159.54.131.7]] 18:02, 7 June 2010 (UTC)
|