[plt-scheme] Creating Executable

From: Paulo J. Matos (pocm at mega.ist.utl.pt)
Date: Sat Sep 7 12:46:28 EDT 2002

> You can use things like `read' or the teachpacks for getting input from
> the user, if you'd like.

I'm really having a problem at reading user input sometimes, and
also, printing if it is not ended by ~n.
For example:
(define-struct tran (val type date comment))

(define read-tran 
  (lambda ()
    (let ((val "")
          (comment "")
          (type 0))
      (printf "Creation of new Transaction~n")
      (printf "Amount: ")
      (set! val (read))
      (set! type (get-type))
      (printf "Comment: ")
      (clean-input-buf (current-input-port))
      (set! comment (read-line))
      (make-new-tran val type

(define get-type 
  (lambda ()
    (printf "Type: ")

;Prints possible types of transaction for user
(define print-type-options
  (lambda ()
    (printf "Type Options:~n")
    (printf "\t~a - Debit~n" *DEB*)
    (printf "\t~a - Credit~n" *CRED*)))

;to remove anything from input-buffer kind of flush(stdin) or
;something like that
(define clean-input-buf
  (lambda (buf)
    (if (char-ready? buf)
          (clean-input-buf buf)))))

If I make a (read-tran) it won't receive the comment. :(
> (read-tran)
Creation of new Transaction
Amount: 1243
Type Options:
	1 - Debit
	2 - Credit
Type: 2
#(struct:tran 1243 2 #(struct:date 13 41 17 7 9 2002 6 249 #t 0)

Any ideas?

Another things happens only if I make it an executable. When I
(printf "Input option: ")

The read will be done before the printf. How can I flush(stdout)?

Best regards,


> Robby

Paulo J. Matos : pocm(_at_)mega.ist.utl.pt
Instituto Superior Tecnico - Lisbon    
Software & Computer Engineering - A.I.
 - > http://mega.ist.utl.pt/~pocm 
	Yes, God had a deadline...
		So, He wrote it all in Lisp!

Posted on the users mailing list.