Template:Nasal Closure Wrapper: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
(doc; cat: Nasal Code Generation Templates) |
||
Line 14: | Line 14: | ||
foreach(var t; timers) | foreach(var t; timers) | ||
t.stop(); | t.stop(); | ||
}); | });<noinclude> | ||
{{Informative template|1= | |||
__NOTOC__ | |||
== Goal == | |||
This template can be used insert a [[Nasal]] snippet with an example of a function using <code>maketimer()</code>. | |||
== Usage == | |||
{{obr}}'''Nasal Closure Wrapper''' {{!}}''variable='' {{!}}''vector=''{{cbr}} | |||
All parameters are optional. | |||
See also [[Nasal Loops#for, while, foreach, and forindex loops]]. | |||
; variable | |||
: Name of local variable for the <code>foreach()</code> loop. | |||
: Defaults to <code>delay</code>. | |||
; vector | |||
: Vector for the <code>foreach()</code> loop. | |||
: Defaults to <code>[2.0, 4.0, 8.0]</code>. | |||
== Technical details == | |||
This template uses {{tl|Nasal Anonymous Func}} | |||
}} | |||
[[Category:Nasal Code Generation Templates]] | |||
</noinclude> |
Latest revision as of 10:52, 21 June 2019
var timers = []; foreach(var delay; [2.0, 4.0, 8.0] ) { #this declares an anonymous/unnamed function (func(arg...) { var interval=delay; var myTimer = maketimer(interval, func() { print("Hello from the ", interval,"-second timer!"); }); # end of the embedded func myTimer.start(); append(timers, myTimer); })(); # this will directly invoke the unnamed function } # end of the foreach loop # kill all timers maketimer(60, func() { foreach(var t; timers) t.stop(); });
The following template description is not displayed when the template is inserted in an article.
Goal
This template can be used insert a Nasal snippet with an example of a function using maketimer()
.
Usage
{{Nasal Closure Wrapper |variable= |vector=}}
All parameters are optional.
See also Nasal Loops#for, while, foreach, and forindex loops.
- variable
- Name of local variable for the
foreach()
loop. - Defaults to
delay
.
- vector
- Vector for the
foreach()
loop. - Defaults to
[2.0, 4.0, 8.0]
.
Technical details
This template uses {{Nasal Anonymous Func}}