I guessed at the argument because of the complete lack of documentation,
but:
  calendar 2007
|domain error: calendar
| a=.((j<100) *(-100&|){.6!:0'')+j=.{.

I hope you're not using this as an example of a coding style to emulate:
the use of uninformative names like "a' for the year (I guess), "r" for the
number
of days per month, and so on, only provides ammunition for critics who
claim that the language is unreadable.

Maybe something like this (which I just translated from old APL code that
probably had its genesis somewhere in the depths of IP Sharp) would be
better:

NB.*calendar: return text calendar for Year-Month YM (in form YYYYMM).
calendar=: 3 : 0
  if. 158210>:y do. 'Date must be after 158210 (October 1582).'
  else.
      mos=.
'Jan';'Feb';'Mar';'Apr';'May';'Jun';'Jul';'Aug';'Sep';'Oct';'Nov';'Dec'
      days=. 'Sun';'Mon';'Tue';'Wed';'Thu';'Fri';'Sat'
      fom=. dow 0 100 100#:>:100*y NB. Day-of-week of first day of month.
       'yr mo'=. 0 100#:y
       len=. 28+((~:/0=4 100 400 4000|yr)*2=mo)+(2~:mo)*2+-.mo e. 9 4 6 11
      cal=. days,":&.>6 7$(-fom)|.42{.":&.>>:i.len
      cal=. ,/"2 >(->:>./,#&>cal){.&.>cal
      tit=. (":yr),~' ',~>mos{~<:mo
      cal=. cal,~({:$cal)({.|.~[:-[:<.[:-:[-[:#]) tit NB. Center title
  end.
NB.EG calendar 200705 NB. Calendar for May 2007
)

Example uses:

  calendar 158101
Date must be after 158210 (October 1582).

  calendar 200705
         May 2007
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

  calendar &.> 200700+>:i.3 4  NB. 2007 calendar...
+----------------------------+----------------------------+----...
| Jan 2007 | Feb 2007 | ...
| Sun Mon Tue Wed Thu Fri Sat| Sun Mon Tue Wed Thu Fri Sat| Sun...
| 1 2 3 4 5 6| 1 2 3| ...
| 7 8 9 10 11 12 13| 4 5 6 7 8 9 10| 4...
...

On 5/9/07, Tracy Harms <[EMAIL PROTECTED]> wrote:

Here is the definition of the calendar verb referred
to by others here.  It has provided me with an
interesting object of focus in my studies.


calendar =: 3 : 0
a=. ((j<100)*(-100&|){.6!:0'')+j=. {.
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.
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
)

By the way, I would like to identify the author of the
verb defined above, because I'd like to give proper
credit when I refer to it in the future.  I am in the
process of creating a "guided tour" through the
definition of this verb, which I'll post on the web
when completed.


--
Tracy B. Harms

     It is the central thesis of this book that the descriptive
     and analytic power of an adequate programming language amply
     repays the considerable effort required for its mastery.
                                Kenneth E. Iverson
                                A Programming Language, 1962




____________________________________________________________________________________
Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm




--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to