23 lines
645 B
Text
23 lines
645 B
Text
to average :l
|
|
output quotient apply "sum :l count :l
|
|
end
|
|
|
|
to make.sma :name :period
|
|
localmake "qn word :name ".queue
|
|
make :qn []
|
|
define :name `[ [n] ; parameter list
|
|
[if equal? count :,:qn ,:period [ignore dequeue ",:qn]]
|
|
[queue ",:qn :n]
|
|
[output average :,:qn]
|
|
]
|
|
end
|
|
|
|
make.sma "avg3 3
|
|
|
|
show map "avg3 [1 2 3 4 5] ; [1 1.5 2 3 4]
|
|
|
|
show text "avg3 ; examine what substitutions took place
|
|
[[n] [if equal? count :avg3.queue 3 [ignore dequeue "avg3.queue]] [queue "avg3.queue :n] [output average :avg3.queue]]
|
|
|
|
; the internal queue is in the global namespace, easy to inspect
|
|
show :avg3.queue ; [3 4 5]
|