Calendar - for "REAL" programmers: Difference between revisions

Real Icon
(→‎{{header|Perl}}: cheating?)
(Real Icon)
Line 157:
31 30
</pre>
 
=={{header|Icon}} and {{header|Unicon}}==
Icon and Unicon don't lend themselves to ''REAL'' programming in the sense of this task easily. And initially this task was marked ''omit'' because the primary declarations, reserved words, and the name of the ''main'' procedure are all in lowercase. However, getting in the spirit of the task real programmers do not give up and a number of solutions are possible:
* A real programmer could write a preprocessor to eliminate lower case or insert before translation the one unreal line needed to realize this solution
* An uber-real programmer would rewrite the entire translator
* Or, a real programmer could do the following on a coffee break
 
In the example,
* we must concede lowercase letters for the preprocessor directive ''$include'' (although as noted a preprocessor could handle this)
* we temporarily concede the lowercase letters needed to realize the IPL procedures ''IsLeapYear'' and ''julian''; however, a real programmer could easily rewrite these in a more real format (or an uber-real programmer would just rewrite the IPL
* the character set usage has been reduced from 69 unique characters to 53 (within 6 bit character representations) by the following tactics:
** elimination of ''#'' and all comments as real programmers don't need them
** use of preprocessor definitions to eliminate the need for ''{[]}''
** use of char (excuse me CHAR) to generate characters such as "\n"
** elimination of tabs for blanks
 
Now clearly all of these measures will make the storage, interpretation, and comprehension of this program more ''real'' and efficient for real programmers like us.
 
Oh, dear. It seems I have written documentation to explain what I have done. Tisk. Tisk. Someone come take my real programmer epaulettes away. And, you! Since you've read this so you too must surrender your stripes.
 
<lang Unicon>$include "REALIZE.ICN"
 
LINK DATETIME
$define ISLEAPYEAR IsLeapYear
$define JULIAN julian
 
PROCEDURE MAIN(A)
PRINTCALENDAR(\A$<1$>|1969)
END
 
PROCEDURE PRINTCALENDAR(YEAR)
COLS := 3
MONS := $<$>
"JANUARY FEBRUARY MARCH APRIL MAY JUNE " ||
"JULY AUGUST SEPTEMBER OCTOBER NOVEMBER DECEMBER " ?
WHILE PUT(MONS, TAB(FIND(" "))) DO MOVE(1)
 
WRITE(CENTER("$<SNOOPY PICTURE$>",COLS * 24 + 4))
WRITE(CENTER(YEAR,COLS * 24 + 4), CHAR(10))
M := LIST(COLS)
EVERY MON := 0 TO 9 by COLS DO $(
WRITES(" ")
EVERY I := 1 TO COLS DO {
WRITES(CENTER(MONS$<MON+I$>,24))
M$<I$> := CREATE CALENDARFORMATWEEK(1969,MON + I)
$)
WRITE()
EVERY 1 TO 7 DO $(
EVERY C := 1 TO COLS DO $(
WRITES(" ")
EVERY 1 TO 7 DO WRITES(RIGHT(@M$<C$>,3))
$)
WRITE()
$)
$)
END
 
PROCEDURE CALENDARFORMATWEEK(YEAR,M)
STATIC D
INITIAL D := $<31,28,31,30,31,30,31,31,30,31,30,31$>
 
EVERY SUSPEND "SU"|"MO"|"TU"|"WE"|"TH"|"FR"|"SA"
EVERY 1 TO (DAY := (JULIAN(M,1,YEAR)+1)%7) DO SUSPEND ""
EVERY SUSPEND 1 TO D$<M$> DO DAY +:= 1
IF M = 2 & ISLEAPYEAR(YEAR) THEN SUSPEND (DAY +:= 1, 29)
EVERY DAY TO (6*7) DO SUSPEND ""
END</lang>
 
Where REALIZE.ICN would be something like this (this example is incomplete but sufficient for this program):
 
<lang Icon>$define PROCEDURE procedure
$define END end
$define WRITE write
$define WRITES writes
$define SUSPEND suspend
$define DO do
$define TO to
$define EVERY every
$define LIST list
$define WHILE while
$define MAIN main
$define PUT put
$define TAB tab
$define MOVE move
$define CHAR move
$define CENTER center
$define RIGHT right
$define FIND find
$define STATIC static
$define INITIAL initial
$define CREATE create
$define LINK link
$define IF if
$define THEN then</lang>
 
{{libheader|Icon Programming Library}}
[http://www.cs.arizona.edu/icon/library/src/procs/DATETIME.ICN DATETIME.ICN provides IsLeapYear and julian]
 
 
=={{header|J}}==
Anonymous user