From: Emre Sevinc
Subject: How to "sleep" and continue LOOP?
Date: 
Message-ID: <87vf0qdb89.fsf@ileriseviye.org>
Why doesn't this simply print 1s slowly?

 CL-USER> (loop (format t "~a~%" 1) (sleep 1))

It simply doesn't do anything until I try to
abort it and then simply prints a few 1s on
each line.

How can I say, run this function which produces
some output, wait for a second and then run the
same function again, in an infinite loop?

I can make it do what I say for a single shot
as in:

 (progn (format t "~a~%" 1) (sleep 1))

but that's all, no infinite loop here.

There must be something I understood completely
wrong (about (sleep ...) maybe?). Any suggestions?

Thanks in advance.

Happy hacking,

-- 
Emre Sevinc

eMBA Software Developer         Actively engaged in:
http:www.bilgi.edu.tr           http://ileriseviye.org
http://www.bilgi.edu.tr         http://fazlamesai.net
Cognitive Science Student       http://cazci.com
http://www.cogsci.boun.edu.tr

From: Duane Rettig
Subject: Re: How to "sleep" and continue LOOP?
Date: 
Message-ID: <4y85mim3z.fsf@franz.com>
Emre Sevinc <·····@bilgi.edu.tr> writes:

> Why doesn't this simply print 1s slowly?
>
>  CL-USER> (loop (format t "~a~%" 1) (sleep 1))

A couple of people have already provided a fix for you (i.e.
use force-output or finish-output) but they didn't answer
your question of "why".  You might be able to infer the
answer from the fix, but:

The answer is: it _is_ printing 1s slowly - you're just not seeing
the result.  The question is: where are these 1s going?  They're
going to the stream which is *standard-output*, which in most lisps
is buffered.  So the printing is being done, but it is not getting to
the final destination unless you wait long enough for the stream's
buffer to be filled.

This issue is actually a stream issue, and demonstrates a tension
between I/O speed (i.e. only perform the expensive data transfer
with full buffers) vs interactivity (i.e. I need to see the interactive
data now).  If the lisp you are running on makes a distinction between
interactive and noninteractive streams, you may not have that problem,
especially on a call to format, since the implementation may do the
force-output for you at the end of a format call.

It is obvious you were probably not doing this experiment on Allegro CL;
if you had been, it would have done what you had expected, unless you
were tying in to a prompt over a socket stream which had not been made
interactive.  I don't know about other implementations, but in
Allegro CL, interactive-stream-p is setfable, and so you would have
been able then to say (setf (interactive-stream-p *standard-output*) t)
and then format would do the rest for you.

-- 
Duane Rettig    ·····@franz.com    Franz Inc.  http://www.franz.com/
555 12th St., Suite 1450               http://www.555citycenter.com/
Oakland, Ca. 94607        Phone: (510) 452-2000; Fax: (510) 452-0182   
From: Emre Sevinc
Subject: Re: How to "sleep" and continue LOOP?
Date: 
Message-ID: <87mzm2cuuf.fsf@ileriseviye.org>
Duane Rettig <·····@franz.com> writes:

> Emre Sevinc <·····@bilgi.edu.tr> writes:
>
>> Why doesn't this simply print 1s slowly?
>>
>>  CL-USER> (loop (format t "~a~%" 1) (sleep 1))
>
> A couple of people have already provided a fix for you (i.e.
> use force-output or finish-output) but they didn't answer
> your question of "why".  You might be able to infer the
> answer from the fix, but:
>
> The answer is: it _is_ printing 1s slowly - you're just not seeing
> the result.  The question is: where are these 1s going?  They're
> going to the stream which is *standard-output*, which in most lisps
> is buffered.  So the printing is being done, but it is not getting to
> the final destination unless you wait long enough for the stream's
> buffer to be filled.

Hmm, you mean that, if I waited enough I'd see it because
the buffer would be full and the Lisp system would be
naturally forced to print the buffer, right?



> This issue is actually a stream issue, and demonstrates a tension
> between I/O speed (i.e. only perform the expensive data transfer
> with full buffers) vs interactivity (i.e. I need to see the interactive
> data now).  If the lisp you are running on makes a distinction between
> interactive and noninteractive streams, you may not have that problem,
> especially on a call to format, since the implementation may do the
> force-output for you at the end of a format call.
>
> It is obvious you were probably not doing this experiment on Allegro CL;

I'm using SBCL 0.9.2


> if you had been, it would have done what you had expected, unless you
> were tying in to a prompt over a socket stream which had not been made
> interactive.  I don't know about other implementations, but in
> Allegro CL, interactive-stream-p is setfable, and so you would have
> been able then to say (setf (interactive-stream-p *standard-output*) t)
> and then format would do the rest for you.

I've checked SBCL and it says:

CL-USER> (interactive-stream-p *standard-output*)
NIL

So it seems that since the default value is NIL I must
either set it, or finish/force output.

When I tried 

CL-USER> (setf (interactive-stream-p *standard-output*) t)

SBCL gives errors.

Anyway, I think I understood the issue.

Thanks a lot for the detailed explanation and
the opportunity to contrast Allegro CL and SBCL.

BTW, is Allegro's something extra or does ANSI standard
defines about setfability of (interactive-stream-p ...)?


-- 
Emre Sevinc

eMBA Software Developer         Actively engaged in:
http:www.bilgi.edu.tr           http://ileriseviye.org
http://www.bilgi.edu.tr         http://fazlamesai.net
Cognitive Science Student       http://cazci.com
http://www.cogsci.boun.edu.tr
From: Christophe Rhodes
Subject: Re: How to "sleep" and continue LOOP?
Date: 
Message-ID: <sqpsqy4et6.fsf@cam.ac.uk>
Emre Sevinc <·····@bilgi.edu.tr> writes:

> I've checked SBCL and it says:
>
> CL-USER> (interactive-stream-p *standard-output*)
> NIL

Be aware that you have not in fact checked SBCL's behaviour, as you
are using some user interface (probably slime, judging by your CL-USER
prompt) which interposes its own streams.  Started up on its own, SBCL
returns T for (interactive-stream-p *standard-output*).

Christophe
From: Emre Sevinc
Subject: Re: How to "sleep" and continue LOOP?
Date: 
Message-ID: <87ek7ecm1q.fsf@ileriseviye.org>
Christophe Rhodes <·····@cam.ac.uk> writes:

> Emre Sevinc <·····@bilgi.edu.tr> writes:
>
>> I've checked SBCL and it says:
>>
>> CL-USER> (interactive-stream-p *standard-output*)
>> NIL
>
> Be aware that you have not in fact checked SBCL's behaviour, as you
> are using some user interface (probably slime, judging by your CL-USER
> prompt) which interposes its own streams.  Started up on its own, SBCL
> returns T for (interactive-stream-p *standard-output*).

Oh! Yes, exactly! I never tought this way. Looks like I should
not trust SLIME for this kind of stuff (Emre wonders what other
areas of Lisp [e.g. SBCL implementation] is reflected differently
in SLIME...).


-- 

"Music sounds better on wax, text edits better in Emacs." -
by 'drewc' in comp.lang.lisp

Emre Sevinc

eMBA Software Developer         Actively engaged in:
http:www.bilgi.edu.tr           http://ileriseviye.org
http://www.bilgi.edu.tr         http://fazlamesai.net
Cognitive Science Student       http://cazci.com
http://www.cogsci.boun.edu.tr
From: Bulent Murtezaoglu
Subject: Re: How to "sleep" and continue LOOP?
Date: 
Message-ID: <87slvufn7d.fsf@p4.internal>
>>>>> "ES" == Emre Sevinc <·····@bilgi.edu.tr> writes:
[...]
    ES> BTW, is Allegro's something extra or does ANSI standard
    ES> defines about setfability of (interactive-stream-p ...)?

It is an extension/improvement that is allowed by the standard.  See

http://www.lispworks.com/documentation/HyperSpec/Body/05_ab.htm

The required ones for function call forms are:

http://www.lispworks.com/documentation/HyperSpec/Body/05_abb.htm

and no, interactive-stream-p is not among the ones listed above.  

cheers,

BM
 
From: Emre Sevinc
Subject: Re: How to "sleep" and continue LOOP?
Date: 
Message-ID: <87aci2clw5.fsf@ileriseviye.org>
Bulent Murtezaoglu <··@acm.org> writes:

>>>>>> "ES" == Emre Sevinc <·····@bilgi.edu.tr> writes:
> [...]
>     ES> BTW, is Allegro's something extra or does ANSI standard
>     ES> defines about setfability of (interactive-stream-p ...)?
>
> It is an extension/improvement that is allowed by the standard.  See
>
> http://www.lispworks.com/documentation/HyperSpec/Body/05_ab.htm
>
> The required ones for function call forms are:
>
> http://www.lispworks.com/documentation/HyperSpec/Body/05_abb.htm
>
> and no, interactive-stream-p is not among the ones listed above.  

Did somebody say that CL was big? I'm sure someone did... Yes,
someone should've said that, at least once (Emre wanders around
in a toughtful manner like a young tourist tries to find
his way in an ancient temple full of wonders...)

-- 

"Music sounds better on wax, text edits better in Emacs." -
by 'drewc' in comp.lang.lisp


Emre Sevinc

eMBA Software Developer         Actively engaged in:
http:www.bilgi.edu.tr           http://ileriseviye.org
http://www.bilgi.edu.tr         http://fazlamesai.net
Cognitive Science Student       http://cazci.com
http://www.cogsci.boun.edu.tr
From: Rainer Joswig
Subject: Re: How to "sleep" and continue LOOP?
Date: 
Message-ID: <BF5AFB48.187CC%joswig@lisp.de>
Am 24.09.2005 12:13 Uhr schrieb "Emre Sevinc" unter <·····@bilgi.edu.tr> in
··············@ileriseviye.org:

> 
> Why doesn't this simply print 1s slowly?
> 
>  CL-USER> (loop (format t "~a~%" 1) (sleep 1))
> 
> It simply doesn't do anything until I try to
> abort it and then simply prints a few 1s on
> each line.

You may want to force the output after each format.

> 
> How can I say, run this function which produces
> some output, wait for a second and then run the
> same function again, in an infinite loop?
> 
> I can make it do what I say for a single shot
> as in:
> 
>  (progn (format t "~a~%" 1) (sleep 1))
> 
> but that's all, no infinite loop here.
> 
> There must be something I understood completely
> wrong (about (sleep ...) maybe?). Any suggestions?
> 
> Thanks in advance.
> 
> Happy hacking,
From: Bulent Murtezaoglu
Subject: Re: How to "sleep" and continue LOOP?
Date: 
Message-ID: <87y85mg2vz.fsf@p4.internal>
>>>>> "ES" == Emre Sevinc <·····@bilgi.edu.tr> writes:

    ES> Why doesn't this simply print 1s slowly?

    CL-USER> (loop (format t "~a~%" 1) (sleep 1))

    ES> It simply doesn't do anything until I try to abort it and then
    ES> simply prints a few 1s on each line.

Try it with finish-output.

http://www.lispworks.com/documentation/HyperSpec/Body/f_finish.htm

BM
From: Emre Sevinc
Subject: Re: How to "sleep" and continue LOOP?
Date: 
Message-ID: <87r7becvc7.fsf@ileriseviye.org>
Bulent Murtezaoglu <··@acm.org> writes:

>>>>>> "ES" == Emre Sevinc <·····@bilgi.edu.tr> writes:
>
>     ES> Why doesn't this simply print 1s slowly?
>
>     CL-USER> (loop (format t "~a~%" 1) (sleep 1))
>
>     ES> It simply doesn't do anything until I try to abort it and then
>     ES> simply prints a few 1s on each line.
>
> Try it with finish-output.


Thanks, it worked beautifully.

> http://www.lispworks.com/documentation/HyperSpec/Body/f_finish.htm



-- 
Emre Sevinc

eMBA Software Developer         Actively engaged in:
http:www.bilgi.edu.tr           http://ileriseviye.org
http://www.bilgi.edu.tr         http://fazlamesai.net
Cognitive Science Student       http://cazci.com
http://www.cogsci.boun.edu.tr