From: Anssi Purola
Subject: Printing..
Date: 
Message-ID: <379B2FA2.3B1B0FDB@pp.inet.fi>
Why this doesn't print numbers from 1 to 100? It only prints '99'.


(defun loop-function()
 ( do ((i 0 (+ i 1))) (>= i 99) (print i)))

And what's right way to print something?

(setq temp 10)
 (print temp)

It shoul work, but it prints '10' twice.

BTW, Sorry about my English..

From: Kenneth P. Turvey
Subject: Re: Printing..
Date: 
Message-ID: <slrn7pmvte.7bd.kturvey@pug1.sprocketshop.com>
On Sun, 25 Jul 1999 15:39:20 GMT, 
Anssi Purola <············@pp.inet.fi> wrote:
>
>Why this doesn't print numbers from 1 to 100? It only prints '99'.
>
>
>(defun loop-function()
> ( do ((i 0 (+ i 1))) (>= i 99) (print i)))

This should be:

  (do ((i 0 (+ i 1))) 
      ((> i 99) t)
    (print i))

The problem was with your end test.  In CMUCL the function you provided
just gives an error.  

>And what's right way to print something?
>
>(setq temp 10)
> (print temp)
>
>It shoul work, but it prints '10' twice.

No, the function prints '10' once and then returns the value that it
printed.  This value is then printed by the reader so you know what the
return value was.  

-- 
Kenneth P. Turvey <·······@SprocketShop.com> 
----------------- http://www.tranquility.net/~kturvey

  One of the advantages of being disorderly is that one is constantly
  making exciting discoveries.  
        -- A. A. Milne
From: Erik Naggum
Subject: Re: Printing..
Date: 
Message-ID: <3141909324457850@naggum.no>
* Anssi Purola <············@pp.inet.fi>
| Why this doesn't print numbers from 1 to 100? It only prints '99'.
| 
| (defun loop-function()
|  ( do ((i 0 (+ i 1))) (>= i 99) (print i)))

  to make this slightly more readable:

(do ((i 0 (+ i 1)))
    (>= i 99)
  (print i)))

  the problem here is that (>= i 99) is a malformed termination clause.
  somehow, >= as a variable is is true in your image.  I suspect that this
  comes from something you have done previously.  if you start up a new
  image and try to evaluate it again, you will get an error.  (if you
  don't, you have a really weird Lisp environment.)

  try using ((>= i 99)), instead.  the termination clause is a list whose
  head is a form and whose tail is a body to be evaluated when the form
  evaluates to true, returning the value of the last form of the body.

| And what's right way to print something?
| 
| (setq temp 10)
|  (print temp)
| 
| It shoul work, but it prints '10' twice.

  it should print 10 three times: (1) the return value of the SETQ form,
  (2) the value of TEMP in the PRINT function, and (3) the return value of
  the PRINT form.

  this is because your Lisp system does (loop (print (eval (read)))) or
  something close to it while it reads and evaluates input from you.

#:Erik
-- 
  suppose we blasted all politicians into space.
  would the SETI project find even one of them?
From: Gareth McCaughan
Subject: Re: Printing..
Date: 
Message-ID: <867lnollz1.fsf@g.local>
Anssi Purola wrote:

> Why this doesn't print numbers from 1 to 100? It only prints '99'.
> 
> 
> (defun loop-function()
>  ( do ((i 0 (+ i 1))) (>= i 99) (print i)))

Your termination condition is wrong. Take a really careful look
at the description of the syntax for DO and try to match it up
against what you gave it, piece by piece. You'll soon spot the
problem.

> And what's right way to print something?
> 
> (setq temp 10)
>  (print temp)
> 
> It shoul work, but it prints '10' twice.

The first time it prints 10 because you told it to. The second time
it prints 10 because the Lisp system always displays the value(s)
returned from the expressions you feed it. The two "10"s are really
being printed by different entities: the first one by your program
and the second one by the "read-eval-print loop".

-- 
Gareth McCaughan  ················@pobox.com
sig under construction