Just because it's a standard utility does not mean
that it can not be improved.  For example:

calendar=: 3 : 0
a=. ((j<100)*(-100&|){.6!:0'')+j=. {.y
b=. a+-/<.4 100 400%~<:a
r=. 28+3,(~:/0=4 100 400|a),10$5$3 2
r=. ,(-7|b+0,+/\}:r)|."0 1 r(]&:>:*"1>/)i.42
m=. m,(0=#m=. <:}.y)#i.12
h=. 'JanFebMarAprMayJunJulAugSepOctNovDec'
h=. ' Su Mo Tu We Th Fr Sa',:"1~_3(_12&{.)\h
<"2 m{h,"2[12 6 21$,>(<'') ((r=0)#i.#r)} <"1 [ 3":,.r
)

The computation on the last line is rather curious.
Experimentation reveals that it is formatting
a bunch of dates from 1 to 31 and 0s, with blanks
replacing 0s.  Thus, instead of
   >(<'') ((r=0)#i.#r)} <"1 [ 3":,.r
you could say one of the following:
   ' ' (I.0=r)}3":,.r
   r{' ',3":1+i.31 1
(To be fair, I. was probably not available at the
time the utility was written.)  Moreover, r did
not need to be raveled, and the reshape can
exploit special code.  Thus:
   r=. (-7|b+0,+/\}:r)|."0 1 r(]&:>:*"1>/)i.42
   ...
   <"2 m{h,"2[12 6 21 ($,) r{' ',3":1+i.31 1

m is supposed to be the months in the argument,
or all months if none are supplied.  Instead of
   m=. m,(0=#m=. <:}.y)#i.12
you could say
   m=. (<:}.y),i.12*1=#y

Other improvements to the verb are possible.



----- Original Message -----
From: [EMAIL PROTECTED]
Date: Wednesday, May 9, 2007 10:07 am
Subject: Re: [Jgeneral] Generating Calendar Days

> Devon !
> 
> It's the code in the ~/j601/system/main/dates.ijs for calendar.
> Criticizing it is a direct critic of J's standard utilities... ;O)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to