60 lines
2.1 KiB
HTML
60 lines
2.1 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
|
<!Originally converted to HTML using LaTeX2HTML 95 (Thu Jan 19 1995) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
|
<HEAD>
|
|
<TITLE> Reading</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<meta name="description" value=" Reading">
|
|
<meta name="keywords" value="lp">
|
|
<meta name="resource-type" value="document">
|
|
<meta name="distribution" value="global">
|
|
<P>
|
|
<BR> <HR>
|
|
<A HREF="node62.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A>
|
|
<A HREF="node58.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A>
|
|
<A HREF="node60.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <BR>
|
|
<A HREF="lp.html"><B>Contents</B></A>
|
|
<B> Next:</B>
|
|
<A HREF="node62.html"> Input and Output </A>
|
|
<B>Up:</B>
|
|
<A HREF="node58.html"> Input and Output</A>
|
|
<B> Previous:</B>
|
|
<A HREF="node60.html"> Nicer Output Using </A>
|
|
<BR> <HR> <P>
|
|
<H1> Reading</H1>
|
|
<P>
|
|
Input from the keyboard is controlled using read, read-line, and read-char.
|
|
<P>
|
|
Read expects to receive a well-formed Lisp expression, i.e. an atom, list or string. It will not return a value until a complete expression has been entered -- in other words all opening parentheses or quotes must be matched.
|
|
<P>
|
|
Here is f-to-c using read:
|
|
<P>
|
|
<BLOCKQUOTE>
|
|
<PRE>(defun f-to-c ()
|
|
(format t "~%Please enter Fahrenheit temperature: ")
|
|
(let* ((ftemp (read))
|
|
(ctemp (* (- ftemp 32) 5/9)))
|
|
(format t
|
|
"~%~s degrees Fahrenheit is ~s degrees Celsius~%"
|
|
ftemp
|
|
(float ctemp)) ;; print floated value
|
|
ctemp)) ;; return ratio value
|
|
|
|
> (f-to-c)
|
|
|
|
Please enter Fahrenheit temperature: 56 ;; user enters 56
|
|
|
|
56 degrees Fahrenheit is 13.333333333333333 degrees Celsius
|
|
|
|
40/3
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
Read-line always returns a string. Read-line will take in everything until the return key is pressed and return a string containing all the characters typed. Read-char reads and returns a single character.
|
|
<P>
|
|
<BR> <HR>
|
|
<P>
|
|
<ADDRESS>
|
|
<I>© Colin Allen & Maneesh Dhagat <BR>
|
|
March 2007 </I>
|
|
</ADDRESS>
|
|
</BODY>
|