From: ··········@gmail.com
Subject: Console I/O
Date: 
Message-ID: <1169579652.396092.19790@s48g2000cws.googlegroups.com>
I need to write a basic console app on Windows and I am considering
LISP. I need to be able to compile it, or at the very least start it
with a simple command like "lisp.exe myProgram" that can be wrapped in
a batch file. At no time should it display a REPL or anything like
that, I need it to look like any other console app.

1. Which versions of LISP would you recommend to a newbie for this
task?
2. What is the command for reading from the console? (Surprisingly,
neither the book I have on LISP or a basic web search turned up
anything.)

From: Harold
Subject: Re: Console I/O
Date: 
Message-ID: <1169583067.488953.322560@d71g2000cwa.googlegroups.com>
··········@gmail.com wrote:
> 1. Which versions of LISP would you recommend to a newbie for this
> task?

CLISP is great for getting your feet wet on Windows. It has TAB
completion of function / macro names and runs well from the command
line.

http://clisp.cons.org/

> 2. What is the command for reading from the console? (Surprisingly,
> neither the book I have on LISP or a basic web search turned up
> anything.)

clisp file.lisp
From: Harold
Subject: Re: Console I/O
Date: 
Message-ID: <1169583114.447191.253030@m58g2000cwm.googlegroups.com>
··········@gmail.com wrote:
> 2. What is the command for reading from the console? (Surprisingly,
> neither the book I have on LISP or a basic web search turned up
> anything.)

Try (read-line) to get started...
From: Richard M Kreuter
Subject: Re: Console I/O
Date: 
Message-ID: <874pqhtqdz.fsf@progn.net>
···········@gmail.com" <··········@gmail.com> writes:

> 2. What is the command for reading from the console? (Surprisingly,
> neither the book I have on LISP or a basic web search turned up
> anything.)

The standard defines several stream variables, including
*standard-input, *standard-output*, and *terminal-io*.  See:

http://www.lisp.org/HyperSpec/Body/var_stdebug-i_ace-outputst.html
http://www.lisp.org/HyperSpec/Body/var_stterminal-iost.html

The initial values of these variables are implementation-dependent,
but many implementations arrange things so that the initial bindings
of *standard-input* and *standard-output* are connected in some way to
*terminal-io*, at least when the Lisp is run interactively.  Note that
you can rebind *standard-input* and *standard-output* without
affecting *terminal-io*, e.g.,

(with-input-from-string (*standard-input* "abc")
  (read-char *terminal-io*)) ; reads from the terminal, not the string

Most routines that do character I/O accept stream designator
arguments.  As a stream designator, the symbol t designates
*terminal-io*.  The symbol nil designates *standard-input* for input
routines, and *standard-output* for output routines.  So, for example:

(read-char t)          ; reads from *terminal-io*
(read)                 ; reads from *standard-input*
(read-line nil)        ; reads from *standard-input*
(write-string line t)  ; writes to *terminal-io*
(write-char char)      ; writes to *standard-output*
(write-line line nil)  ; writes to *standard-output*

(with-open-file (*standard-input* <some pathname>)
  (let ((line (read-line)))  ; reads from the file
    (write-line line t)))    ; writes to the terminal

Note that read-byte and write-byte take streams, not stream
designators, and that format treats its first argument specially (have
a look at the CLHS entry for how).

--
RmK
From: ··········@gmail.com
Subject: Re: Console I/O
Date: 
Message-ID: <1169590584.013338.121430@k78g2000cwa.googlegroups.com>
Thanks, that looks like it is exactly what I need.

Jonathan

Richard M Kreuter wrote:
> ···········@gmail.com" <··········@gmail.com> writes:
>
> > 2. What is the command for reading from the console? (Surprisingly,
> > neither the book I have on LISP or a basic web search turned up
> > anything.)
>
> The standard defines several stream variables, including
> *standard-input, *standard-output*, and *terminal-io*.  See:
>
> http://www.lisp.org/HyperSpec/Body/var_stdebug-i_ace-outputst.html
> http://www.lisp.org/HyperSpec/Body/var_stterminal-iost.html
>
> The initial values of these variables are implementation-dependent,
> but many implementations arrange things so that the initial bindings
> of *standard-input* and *standard-output* are connected in some way to
> *terminal-io*, at least when the Lisp is run interactively.  Note that
> you can rebind *standard-input* and *standard-output* without
> affecting *terminal-io*, e.g.,
>
> (with-input-from-string (*standard-input* "abc")
>   (read-char *terminal-io*)) ; reads from the terminal, not the string
>
> Most routines that do character I/O accept stream designator
> arguments.  As a stream designator, the symbol t designates
> *terminal-io*.  The symbol nil designates *standard-input* for input
> routines, and *standard-output* for output routines.  So, for example:
>
> (read-char t)          ; reads from *terminal-io*
> (read)                 ; reads from *standard-input*
> (read-line nil)        ; reads from *standard-input*
> (write-string line t)  ; writes to *terminal-io*
> (write-char char)      ; writes to *standard-output*
> (write-line line nil)  ; writes to *standard-output*
>
> (with-open-file (*standard-input* <some pathname>)
>   (let ((line (read-line)))  ; reads from the file
>     (write-line line t)))    ; writes to the terminal
>
> Note that read-byte and write-byte take streams, not stream
> designators, and that format treats its first argument specially (have
> a look at the CLHS entry for how).
> 
> --
> RmK
From: Pascal Bourguignon
Subject: Re: Console I/O
Date: 
Message-ID: <87mz48ex78.fsf@thalassa.informatimago.com>
···········@gmail.com" <··········@gmail.com> writes:

> Richard M Kreuter wrote:
>> ···········@gmail.com" <··········@gmail.com> writes:
>>
>> > 2. What is the command for reading from the console? (Surprisingly,
>> > neither the book I have on LISP or a basic web search turned up
>> > anything.)
>>
>> (read-char t)          ; reads from *terminal-io*
>> (read)                 ; reads from *standard-input*
>> (read-line nil)        ; reads from *standard-input*
>> (write-string line t)  ; writes to *terminal-io*
>> (write-char char)      ; writes to *standard-output*
>> (write-line line nil)  ; writes to *standard-output*
>>
>> (with-open-file (*standard-input* <some pathname>)
>>   (let ((line (read-line)))  ; reads from the file
>>     (write-line line t)))    ; writes to the terminal
>
> Thanks, that looks like it is exactly what I need.
>
> Jonathan

Note that with clisp you can also use the SCREEN package to display on
the console, and the raw keyboard.  Be sure to read the clisp
implementation notes. http://clisp.cons.org/impnotes/index.html

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
----------> http://www.netmeister.org/news/learn2quote.html <-----------
---> http://homepage.ntlworld.com/g.mccaughan/g/remarks/uquote.html <---

__Pascal Bourguignon__                     http://www.informatimago.com/
From: ········@gmail.com
Subject: Re: Console I/O
Date: 
Message-ID: <1169860871.415892.214890@q2g2000cwa.googlegroups.com>
>
> Note that with clisp you can also use the SCREEN package to display on
> the console, and the raw keyboard.  Be sure to read the clisp
> implementation notes. http://clisp.cons.org/impnotes/index.html

Are there any non-trivial libraries built on clisp's SCREEN package?
I'd be interested in seeing it in action...




>
> --
> A: Because it messes up the order in which people normally read text.
> Q: Why is top-posting such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?
> ----------> http://www.netmeister.org/news/learn2quote.html <-----------
> ---> http://homepage.ntlworld.com/g.mccaughan/g/remarks/uquote.html <---
>
> __Pascal Bourguignon__                     http://www.informatimago.com/
From: Richard M Kreuter
Subject: Re: Console I/O
Date: 
Message-ID: <87r6tksbde.fsf@progn.net>
> Richard M Kreuter wrote:
>> ···········@gmail.com" <··········@gmail.com> writes:
>>
>> > 2. What is the command for reading from the console?
>>
>> The standard defines several stream variables, including
>> *standard-input, *standard-output*, and *terminal-io*...

Ugh, I forgot to mention *query-io*.  The CLHS reads

| The value of ‘*query-io*’, called query I/O, is a bidirectional
| stream to be used when asking questions of the user.

As you're working on a console-only program, *query-io* is likely to
be connected to *terminal-io* in some way, and so the distinction is
perhaps academic, but the stylistically correct thing might be to
prefer *query-io* to *terminal-io* for your user interaction.

--
RmK
From: Slava Pestov
Subject: Re: Console I/O
Date: 
Message-ID: <1169614589.964695.161830@k78g2000cwa.googlegroups.com>
On Jan 23, 2:14 pm, ···········@gmail.com" <··········@gmail.com>
wrote:
> 2. What is the command for reading from the console? (Surprisingly,
> neither the book I have on LISP or a basic web search turned up
> anything.)

Which book would that be? A lot of Lisp books that one comes across,
especially in libraries, are quite old and cover archaic dialects
(MacLISP, etc). I suggest looking at http://www.gigamonkeys.com/book/.

One of the first few sections
(http://www.gigamonkeys.com/book/practical-a-simple-database.html)
covers console I/O. Scroll down to "Improving user interaction".

Slava
From: Pascal Costanza
Subject: Re: Console I/O
Date: 
Message-ID: <51na9rF1lekdpU1@mid.individual.net>
··········@gmail.com wrote:
> I need to write a basic console app on Windows and I am considering
> LISP. I need to be able to compile it, or at the very least start it
> with a simple command like "lisp.exe myProgram" that can be wrapped in
> a batch file. At no time should it display a REPL or anything like
> that, I need it to look like any other console app.
> 
> 1. Which versions of LISP would you recommend to a newbie for this
> task?
> 2. What is the command for reading from the console? (Surprisingly,
> neither the book I have on LISP or a basic web search turned up
> anything.)

Executing a lisp script is typically quite straightforward. For batch 
processing, you also need to make sure that the lisp script 
automatically exits in the end. The respective ways to start lisp 
scripts are as follows:

Allegro: alisp -s script.lisp, exit with (excl:exit)
clisp: clisp -i init.lisp script.lisp, exits automatically
CMUCL: lisp -load script.lisp, exit with (ext:quit)
OpenMCL: openmcl -l script.lisp, exit with (ccl:quit)
SBCL: sbcl --load script.lisp, exit with (sb-ext:quit)

(I don't use LispWorks or MCL from the command line, so I don't know the 
details there. I don't regularly use other CL implementations either.)

I wouldn't bother compiling the scripts, it's more convenient that you 
can easily change them. It makes sense, though, that a script is 
relatively small and that the rest of the program is compiled. I use 
asdf to load programs from a script, because it is widely supported and 
automatically takes care of (re)compiling everything in the right order. 
Other system definition facilities are most probably also appropriate.

So a script can be as simple as the following few lines:

(asdf:oos 'asdf:load-op :some-program)
(program:run)
#+allegro (excl:exit)
#+cmu (ext:quit)
#+openmcl (ccl:quit)
#+sbcl (sb-ext:quit)

Of course, to use this, you need to know about system definition 
facilities and (most probably) about the Common Lisp package system.

If you are a newbie, or if your program is simple enough, the script can 
simply be your program.

I don't know what the best ways are to deploy without source code, since 
that's not important for my uses, but there are typically 
implementation-specific ways to create standalone executables. See the 
respective manuals for more information.

For reading and writing, just use the standard read and print functions.


Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: ··········@gmail.com
Subject: Re: Console I/O
Date: 
Message-ID: <1169591494.217375.47990@a75g2000cwd.googlegroups.com>
Pascal Costanza wrote:
> I don't know what the best ways are to deploy without source code, since
> that's not important for my uses, but there are typically
> implementation-specific ways to create standalone executables. See the
> respective manuals for more information.

Oh, I don't worry about that any more. In these days of easily
decompiled .NET and Java applications, not to mention purely
interperted languages like Flash and JavaScript, trying to hide your
source code is a fools errand.

I only want compiled binaries if it will improve the user experience.

Jonathan
From: John Thingstad
Subject: Re: Console I/O
Date: 
Message-ID: <op.tmrug4xppqzri1@pandora.upc.no>
On Tue, 23 Jan 2007 20:14:12 +0100, ··········@gmail.com  
<··········@gmail.com> wrote:

> I need to write a basic console app on Windows and I am considering
> LISP. I need to be able to compile it, or at the very least start it
> with a simple command like "lisp.exe myProgram" that can be wrapped in
> a batch file. At no time should it display a REPL or anything like
> that, I need it to look like any other console app.
>
> 1. Which versions of LISP would you recommend to a newbie for this
> task?
> 2. What is the command for reading from the console? (Surprisingly,
> neither the book I have on LISP or a basic web search turned up
> anything.)
>

If you take a look at my cite:

http://home.chello.no/~jthing

It contains lots of code for console input/output.
The first program Russian roulette ought to give you what
you need to get started.

They are made to run from the repl, but you can run them standalone if you  
want.
How is implementatin dependant.
Pascal covered a few of the options a week or so back.

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/