Generator (computer programming): Difference between revisions

Content deleted Content added
Uses: eager evaluation
F#: init
Line 414:
IO.WriteLn "I=", I
</source>
 
===F#===
{{see|Sequence expression}}
[[F Sharp (programming language)|F#]] provides generators via ''[[sequence expression]]s.''<ref name="seq">{{cite web | url = http://blogs.msdn.com/dsyme/archive/2007/09/22/some-details-on-f-computation-expressions-aka-monadic-or-workflow-syntax.aspx | title = Some Details on F# Computation Expressions | accessdate = 2007-12-14}}</ref> These can define a sequence (lazily evaluated, sequential access) via <code>seq { ... }</code>, a list (eagerly evaluated, sequential access) via <code>[ ... ]</code> or an array (eagerly evaluated, indexed access) via <code>[| ... |]</code> that contain code that generates values. For example,
<source lang=fsharp>
seq { for b in 0 .. 25 do
if b < 15 then
yield b*b }
</source>
forms a sequence of squares of numbers from 0 to 14 by filtering out numbers from the range of numbers from 0 to 25.
 
===Python===