Calendar - for "REAL" programmers: Difference between revisions

m ({{out}})
Line 488:
 
=={{header|Elena}}==
 
{{incorrect|Elena|<br>The program isn't consistent with the task's requirement: <br>the program isn't wholly in uppercase. <br>}}
 
<lang elena>#define system.
Line 512 ⟶ 510:
#field theRow.
#constructor new &Yearyear:aYear &Monthmonth:aMonth
[
theMonth := aMonth.
theYear := aYear.
theLine := TextBuffer new.
theRow := Integer new &int:0.
]
 
#method firstLine : aDaywriteTitle
[
theRow << 0.
theDate := Date new &Yearyear:(theYear int) &Monthmonth:(theMonth int) &Dayday:aDay1.
control foreachrun:DayNames &doforEach: aName
[ theLine write:" " write:aName ].
]
#method nextLinewriteLine
[
theLine clear.
(theDate Monthmonth == theMonth)
? [
theLine~::stringOp write:" " &length:(((theDate DayOfWeekdayOfWeek) => 0 ? [ 7 ] ! [ theDate DayOfWeekdayOfWeek ]) subtract:1 int).
control do:
[
theLine~::stringOp write:(theDate Dayday) &paddingLeft:3 &with:" ".
theDate := theDate add &Daysdays:1.
]
&until:[(theDate Monthmonth != theMonth)or:[theDate DayOfWeekdayOfWeek == 1]].
].
#var(type:int) aLength := theLine length.
(aLength < 21)
? [ theLine~::stringOp write:" " &length:(21 - aLength). ].
theRow += 1.
^ theRow < 7.
]
#method enumeratoriterator = Iterator
{
^available = theRow < 7.
set &index:anIndex [ self firstLine:(anIndex + 1) ]
 
nextread &out'index:anIndex [ ^anIndex := selftheRow nextLineint. ]
 
write &index:anIndex
[
(anIndex <= theRow)
? [ self writeTitle. ].
#loop (anIndex > theRow) ?
[ self writeLine. ].
]
 
get = self.
}.
Line 565 ⟶ 570:
#method printTitleTo : anOutput
[
anOutput~::stringOp write:(MonthNames @(theMonth - 1)) &padding:21 &with:" ".
]
Line 576 ⟶ 581:
#class Calendar
{
#field(type:int) theYear.
#field(type:int) theRowLength.
#constructor new : aYear
Line 587 ⟶ 592:
#method printTo:anOutput
[
anOutput~::stringOp write:"[SNOOPY]" &padding:(theRowLength * 25) &with:" " writeLine.
anOutput~stringOp write:theYearwriteLine. &padding:(theRowLength * 25) &with:" " writeLine writeLine.
anOutput::stringOp write:theYear &padding:(theRowLength * 25) &with:" ".
anOutput writeLine writeLine.
#var(type:int) aRowCount := 12 / theRowLength.
#var Months := matrixControlMatrix new &mn:aRowCount &nm:theRowLength &eachevery_ij: (:i:j) [ CalendarMonthPrinter new &Year:theYear &Month:(i * theRowLength + j + 1) ].
(&index:i &index:j) [ CalendarMonthPrinter new &year:(theYear int) &month:((i * theRowLength + j + 1) int) ].
 
control foreachrun:Months &doforEach: aRow
[
control foreachrun:aRow &doforEach: aMonth
[
aMonth printTitleTo:anOutput.
Line 604 ⟶ 612:
anOutput writeLine.
control forrun:(ParallelEnumerator new:aRow) &doforEach: aLine
[
control foreachrun:aLine &doforEach: aPrinter
[
aPrinter printTo:anOutput.
 
anOutput write:" ".
].
 
anOutput writeLine.
].
].
]
}
 
// --- program ---
 
#symbol program =
[
#var aCalender := Calendar new:(consoleEx write:"EnterENTER theTHE yearYEAR:" readLine:(Integer new)).
aCalender printTo:consoleEx.
Anonymous user