From: Richard A. O'Keefe
Subject: Re: counting the days
Date: 
Message-ID: <4hglq5$f8q@goanna.cs.rmit.EDU.AU>
····@usa.pipeline.com(Boaz Chow) writes:
>I am learning lisp in my school.   My first project is to write a lisp
>program to calculate the days between two given months.  For example, (days
>1 jan 31 mar) will give me 29+30+31 which is 90 
 
Are you _sure_ about that interface?
Or might it be
	(days 1 'Jan 31 'Mar)

>is there a for-loop in lisp? 

Surely your school has SOME books.  What lisp are you using?
Many Lisps (including Common Lisp and Scheme) have DO

	(DO ((variable-1 initial-value-1 next-value-1)
	     ...
	     (variable-n initial-value-n next-value-n))
	    (termination-condition final-result)
	    body)

For example,

    (defun (days-in-month Month)
	(do ((L `(Jan 31 Feb ,(if Leap-Year-p 29 28) Mar 31 Apr 30 May
		  31 Jun 30 Jul 31 Aug 31 Sep 30 Oct 31 Nov 30 Dec 31))
		(cddr L))
	    ((eq (car L) Month) (cadr L))))


Common Lisp also has LOOP.  It also has a whole bunch of functions with
'map' in their name that are ideally suited to looping over lists.  And
all of this is clearly and explicitly described in any Lisp book worth
having.

>I think I need a list like this ( (jan 31) (feb 29) (mar 30) ... (dec 31))
>in order to implement a for-loop in lisp, don't I? 

No.

>I was working on this program in the computer lab.  I was stuck yesterday
>because I lost count of the @·····@% "(" and the ···@!!# ")". 

You are obviously using the wrong tools.   *YOU* aren't supposed to keep
count of the parentheses.  Your EDITOR is supposed to do that.  If you
were using vi(le), you should have done
	vi -l foobar.lsp
and the % command (find matching bracket) would have helped you.  If you
were using emacs, it would all have been automatic.

I want to emphasise one thing here.  The problem as posed is ill-defined.
The difference between two dates depends not only on the day of the month
and the month of the year, but on what year it is.  Leap years and plain
years are different.  The arguments you are proposing to pass to the
function just plain don't provide enough information, no matter what
programming language you use.

-- 
The election is over, and Australia lost; the idjits elected _politicians_!
Richard A. O'Keefe; http://www.cs.rmit.edu.au/~ok; RMIT Comp.Sci.