zman at bizonline.co.uk (Peter Z) writes:
> Date: 17 Dec 2003 14:21:13 -0800
>
> I'm having real problems reading user input, I hope someone can help.
>
> I'm trying to read in a number from the user - could be one or two
> digits - and choose an action based on that number. If I use
> readline, the result is always enclosed in square brackets, so my
> comparisons are always returning false.
To be more precise the result is a list which is derived from what
you typed in.
So if you type in
27
the result will be a list containing the number 27.
If you type in
2 7
the result will be a list containing two numbers, 2 and 7.
If you type in
3cat
the result will be a list containing the number 3 and the word "cat"
(because Pop-11 does not allow a text item to be made of an
integer followed by alphabetic characters, so it separates them.
If you type in
cat3
The result will be a list containing one word "cat3" because pop11
does allow an identifer to switch from alphabetic to numeric
(because many people like to use variables with names like
x1 x21 x3, etc.)
So if you just type in
27
then in order to get the number 27 all you need is to apply 'hd'
to the result of readline
hd(readline())
If you want to get two integers you'll have to extract two elements
from the list, using successive applications of hd and tl, or using
hd and destpair, or using explode (= dl for lists), or using the
pattern matcher. See TEACH PRIMER, chapter 6, or chapter six of the
online primer
http://www.cs.bham.ac.uk/research/poplog/primer/START.html
or TEACH MATCHARROW
http://www.cs.bham.ac.uk/research/poplog/teach/matcharrow
> Any ideas? Either for an
> alternative input method,
There are alternative input methods which are sometimes more
appropriate, e.g. using charin, or rawcharin, with incharitem
bu they will certainly require you to dig deeper into pop11.
Eg REF CHARIO
> A further problem is that the dk keyboard remapping command isn't
> being remembered after I close xved, even if I tell it to make the
> changes permanent. Without it, arrow keys etc don't work. I'm using
> Red Hat 9 on desktop x86.
Well, look at the text inserted by DK, make a copy of it (e.g.
using the mouse to select) then insert that text into your
vedinit.p file
$poplib/vedinit.p
As a last resort create a file of utilities that you always need
compiled and put that into $poplib/init.p
$poplib should be defined when you are running XVed.
Aaron
PS
If you are using the Birmingham Poplog on the CD produced for
students, alas the version of poplog on there was built before I had
installed the latest changes to Ved and XVed. They are in the
current version of
http://www.cs.bham.ac.uk/research/poplog/bham-linux-poplog.tar.gz
(about 21 Mbytes). I could produce a CD containing that to be
borrowed from the school library if you don't have a fast enough
connection to download that much conveniently.
===
====
Aaron Sloman, ( http://www.cs.bham.ac.uk/~axs/ )
School of Computer Science, The University of Birmingham, B15 2TT, UK
EMAIL A.Sloman AT cs.bham.ac.uk (ReadATas@please !)
PAPERS: http://www.cs.bham.ac.uk/research/cogaff/ (And free book on Philosophy of AI)
FREE TOOLS: http://www.cs.bham.ac.uk/research/poplog/freepoplog.html
|