next up previous
Contents Next: Input and Output Up: Input and Output Previous: Nicer Output Using


Input from the keyboard is controlled using read, read-line, and read-char.

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.

Here is f-to-c using read:

(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~%"
              (float ctemp))           ;; print floated value
    ctemp))                            ;; return ratio value


Please enter Fahrenheit temperature: 56   ;; user enters 56

56 degrees Fahrenheit is 13.333333333333333 degrees Celsius

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.

© Colin Allen & Maneesh Dhagat
November 1999