This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Read only a single element

3 posts · 1161 views

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!

Re: Read only a single element

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.

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.

Re: Read only a single element

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.