Calendar - for "REAL" programmers: Difference between revisions
Content added Content deleted
m (→{{header|X86 Assembly}}: added zkl header) |
(→{{header|zkl}}: added zkl code) |
||
Line 2,768: | Line 2,768: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
{{trans|D}} |
{{trans|D}} |
||
Using a large helping of grease, in the form of a pre-processor. |
|||
⚫ | |||
<lang zkl></lang> |
|||
The calendar code, file UPCAL.zkl (upper cased version of [[Calendar#zkl]]): |
|||
<lang zkl>VAR [CONST] D=TIME.DATE, DAYS="SU MO TU WE TH FR SA"; |
|||
FCN CENTER(TEXT,M) { STRING(" "*((M-TEXT.LEN())/2),TEXT) } |
|||
FCN ONEMONTH(YEAR,MONTH){ |
|||
DAY1:=D.ZELLER(YEAR,MONTH,1); //1969-1-1 -->3 (WED, ISO 8601) |
|||
DAYZ:=D.DAYSINMONTH(YEAR,MONTH); //1969-1 -->31 |
|||
LIST(CENTER(D.MONTHNAMES[MONTH],DAYS.LEN()),DAYS).EXTEND( |
|||
(1).PUMP(DAYZ,(0).PUMP(DAY1,LIST,T(VOID,""))).APPLY("%2S ".FMT) |
|||
.PUMP(LIST,T(VOID.READ,DAYS.LEN()/3,FALSE),STRING.CREATE)); |
|||
} |
|||
⚫ | |||
And the pre-processor, hand rolled for the above code (file bbb.zkl): |
|||
<lang zkl>code:=File(vm.arglist[0]).read(); |
|||
code=Data(Void,code.text.toLower()); |
|||
mixed:=T("string","String", "list","List", " t("," T(",",t(",",T(", |
|||
".tostring",".toString", "void.read","Void.Read", |
|||
"time.date","Time.Date", "utils.","Utils.", "zipwith","zipWith", |
|||
"daysinmonth","daysInMonth", "monthnames","monthNames", |
|||
"void","Void", "false","False", |
|||
"d.october","d.October", |
|||
); |
|||
mixed.pump(Void,Void.Read,'wrap(up,down){ code.replace(up,down) }); |
|||
Compiler.Compiler.compileText(code)();</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
$ zkl bbb UPCAL.zkl |
|||
3 days of peace & music |
|||
1969 |
|||
January February March |
|||
su mo tu we th fr sa su mo tu we th fr sa su mo tu we th fr sa |
|||
1 2 3 4 1 1 |
|||
5 6 7 8 9 10 11 2 3 4 5 6 7 8 2 3 4 5 6 7 8 |
|||
... |
|||
</pre> |
</pre> |
||