Read only a single element

Discussion of Common Lisp
Post Reply
I X Code X 1
Posts: 59
Joined: Sun May 29, 2011 8:52 pm
Location: NY
Contact:

Read only a single element

Post by I X Code X 1 » Sun Jul 17, 2011 9:40 pm

Hello,

I'm writing a function and I am allowing the user to input a number/character (anything on the keyboard really). However, I only want them to be able to enter a single element. For example, if the user enters the letter m or the letter 5 it's fine, but I don't want the user to be able to enter the word moose, or the number 500.

Is there any (I've not been able to find one on the HyperSepc, but I could not be looking clearly enough) read function that stops taking input when the very first element is entered or only returns the first element that was entered? I'm using ACL Express Edition.

Thanks for any and all help!

I X Code X 1
Posts: 59
Joined: Sun May 29, 2011 8:52 pm
Location: NY
Contact:

Re: Read only a single element

Post by I X Code X 1 » Sun Jul 17, 2011 9:46 pm

Okay, I have not the slightest clue how I missed this. Maybe because it's late :oops:

(read-char) does what I am looking for.

Code: Select all

CG-USER(35): (read-char)
a

#\a
CG-USER(36): (read-char)
ajaj

#\a
CG-USER(37): (read-char)
1334

#\1
CG-USER(38): (read-char)
%%100

#\%
Might not want it to be a char, but I can always turn it into something once I have it as a char.

Konfusius
Posts: 62
Joined: Fri Jun 10, 2011 6:38 am

Re: Read only a single element

Post by Konfusius » Mon Jul 18, 2011 8:59 am

I X Code X 1 wrote:Is there any read function that stops taking input when the very first element is entered
Usually, a console always reads in a complete line. It's good practice to read the input and if it isn't of the required type then issue an error message and read the input again.

Post Reply