Last Friday of each month: Difference between revisions

Content added Content deleted
(Added zkl)
Line 1,688: Line 1,688:
</pre>
</pre>


=={{header|zkl}}==
Gregorian calendar
<lang zkl>var [const] D=Time.Date;
fcn lastFridays(y){[1..12].pump(Console.println,
'wrap(m){ds:=D.daysInMonth(y,m);
[ds..1,-1].pump(Void,fcn(y,m,d){
D.weekDay(y,m,d) :
if (_==5)return(Void.Stop,"%d-%02d-%02d".fmt(y,m,d))
}.fp(y,m))
})
}
lastFridays(2012)</lang>
For each month in year y, count back from the last day in the month until a Friday is found and print that date. A pump is a loop over a sequence and Void.Stop stops the pump with a value. The first parameter to a pump is the sink. All the imperative loop constructs are available but I didn't feel like using them. A wrap is a function closure over unknown values in the function, necessary because functions are not lexically scoped.
{{out}}
<pre>
2012-01-27
2012-02-24
2012-03-30
2012-04-27
2012-05-25
2012-06-29
2012-07-27
2012-08-31
2012-09-28
2012-10-26
2012-11-30
2012-12-28
</pre>
[[Category:Date and time]]
[[Category:Date and time]]