Newsgroups: comp.lang.lisp,gnu.emacs.help
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!newsfeed.internetmci.com!howland.reston.ans.net!ix.netcom.com!netcom.com!bskendig
From: bskendig@netcom.com (Brian Kendig)
Subject: How do I write a non-blocking 'sleep-for' in elisp?
Message-ID: <bskendigDn0urz.9M8@netcom.com>
Organization: Starfleet Headquarters: San Francisco
Date: Mon, 19 Feb 1996 12:02:23 GMT
Lines: 31
Sender: bskendig@netcom5.netcom.com
Xref: glinda.oz.cs.cmu.edu comp.lang.lisp:20885 gnu.emacs.help:37390

I have an artificial intelligence program that runs in Emacs Lisp (for
portability).  It is designed to interact with other characters in real
time in an on-line MUD game.

Right now I am trying to solve this problem with it: the program
instantly generates and sends out a response to anything you type to it,
which immediately reveals that it's an AI and not a human typing on the
other end.

I've implemented an 'output queue' for the program; whenever it wants to
"type" some text to the game, it queues that text onto the end of an
output list.  It will periodically go through this list in order, and
for each string in the list, it will do a (sleep-for) for a length of
time based on the length of the string to simulate a delay for typing,
and then it will print that string.  This is so the main program can
keep running and dumping output into the queue without having to
actually wait for each line of text to be printed.

Problem is, every time it does a (sleep-for), it grinds the whole rest
of the program to a halt until the (sleep-for) time has expired.
There's no need to have a delay before printing to affect the execution
of the rest of the program, and I don't want this to happen.

Is there any way to tell Emacs Lisp "do such-and-such in N seconds and
don't tie up the system in the meantime"?

-- 
_/_/_/   Be insatiably curious.                 Je ne suis fait comme aucun
/_/_/    Ask "why" a lot.                de ceux que j'ai vus; j'ose croire
_/_/                           n'etre fait comme aucun de ceux qui existent.
  /    Brian Kendig         Si je ne vaux pas mieux, au moins je suis autre.
 /    bskendig@netcom.com                                       -- Rousseau
     http://home.netscape.com/people/brian/
