"Gary Dodds" <············@hotmail.com> writes:
> Hi
>
> how can I read input from the keyboard into a list
Assuming that the keyboard is attached to *standard-input*
(loop with eof = (gensym)
for thing = (read *standard-input* nil eof)
until (eq thing eof)
collect thing)
Mmmmmm, tastes like ALGOL...
--
/|_ .-----------------------.
,' .\ / | No to Imperialist war |
,--' _,' | Wage class war! |
/ / `-----------------------'
( -. |
| ) |
(`-. '--.)
`. )----'
···@conquest.OCF.Berkeley.EDU (Thomas F. Burdick) writes:
> "Gary Dodds" <············@hotmail.com> writes:
>
> > how can I read input from the keyboard into a list
>
> Assuming that the keyboard is attached to *standard-input*
>
> (loop with eof = (gensym)
> for thing = (read *standard-input* nil eof)
> until (eq thing eof)
> collect thing)
>
> Mmmmmm, tastes like ALGOL...
I don't recall ALGOL having a collection facility. :-)
Btw, I think if you're really expecting to talk to the keyboard,
you should plan for a stop condition other than eof, since it's
OS-dependent whether an eof can be forced on the keyboard and it's
OS-dependent whether a Lisp will still be running after you do
force an eof on those that let you do so. No point in doing all
that collection if you're not going to ever return the value.
Kent M Pitman <······@world.std.com> writes:
> ···@conquest.OCF.Berkeley.EDU (Thomas F. Burdick) writes:
>
> > "Gary Dodds" <············@hotmail.com> writes:
> >
> > > how can I read input from the keyboard into a list
> >
> > Assuming that the keyboard is attached to *standard-input*
> >
> > (loop with eof = (gensym)
> > for thing = (read *standard-input* nil eof)
> > until (eq thing eof)
> > collect thing)
> >
> > Mmmmmm, tastes like ALGOL...
>
> I don't recall ALGOL having a collection facility. :-)
I didn't say what it smells like :-)
> Btw, I think if you're really expecting to talk to the keyboard,
> you should plan for a stop condition other than eof, since it's
> OS-dependent whether an eof can be forced on the keyboard and it's
> OS-dependent whether a Lisp will still be running after you do
> force an eof on those that let you do so. No point in doing all
> that collection if you're not going to ever return the value.
True, but this'll work for Windows and Unix. In my copy of CLISP, if
you type this at the toplevel, you don't get to *do* anything with the
list (it exits immediately), but you do get to see it returned. I
guess add the assumption of being able to generate EOF from the
keyboard, and I stand by my code. It gets everything into the list,
just like it was supposed to. As for its usefulness...
--
/|_ .-----------------------.
,' .\ / | No to Imperialist war |
,--' _,' | Wage class war! |
/ / `-----------------------'
( -. |
| ) |
(`-. '--.)
`. )----'
"Gary Dodds" <············@hotmail.com> wrote in message
··························@news11-gui.server.ntli.net...
> Hi
>
> how can I read input from the keyboard into a list
>
(defun read-keyboard-into-list()
"Why couldn't it be April 1st?"
(let ((*read-eval* nil))
(ignore-errors
(cons (read)
(read-keyboard-into-list)))))
-------------------
Geoff
"Geoff Summerhayes" <·············@hNoOtSmPaAiMl.com> wrote in message
···················@corp.supernews.com...
>
> "Gary Dodds" <············@hotmail.com> wrote in message
> ··························@news11-gui.server.ntli.net...
> > Hi
> >
> > how can I read input from the keyboard into a list
> >
>
>
> (defun read-keyboard-into-list()
> "Why couldn't it be April 1st?"
> (let ((*read-eval* nil))
> (ignore-errors
> (cons (read)
> (read-keyboard-into-list)))))
>
Oops, my bad. :-)
(defun read-keyboard-into-list()
"Why couldn't it be April 1st?"
(let ((*read-eval* nil))
(cons
(ignore-errors (read))
(read-keyboard-into-list))))
----------------
Geoff
* "Gary Dodds" <············@hotmail.com>
> how can I read input from the keyboard into a list
Common Lisp has no notion of keyboards, but reading from *standard-input* or
*terminal-io* may or may not be what you want. Can you please give some
more information on what you're trying to do? If it's homework, please say
so. What textbook are you using?
Erik
"Gary Dodds" <············@hotmail.com> wrote in message news:<·····················@news11-gui.server.ntli.net>...
> Hi
>
> how can I read input from the keyboard into a list
With a camera and some image recongition software. It's non-trivial.
The result is usually (q w e r t y u i o p ...) though unless you live
in some country with mutant keyboards.