[plt-scheme] Creating Executable

From: Robert Bruce Findler (robby at cs.uchicago.edu)
Date: Sat Sep 7 12:56:23 EDT 2002

To flush stdout, use:

  (flush-output)

as in:

  (define (prompt-user-for-number)
    (printf "Number please: ")
    (flush-output)
    (read))

You might also consider using Paul Graunke's web servlets for getting
input or the MrEd manual for GUI input (of course, those are going to
require some work to read the documentation, but they are more modern
ways of communicating with your user).

Robby

At 07 Sep 2002 17:46:28 +0100, Paulo J. Matos wrote:
> 
> > 
> > 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
>                      comment))))
> 
> (define get-type 
>   (lambda ()
>     (print-type-options)
>     (printf "Type: ")
>     (read-numeric-char)))
> 
> ;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)
>         (begin
>           (read)
>           (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
> Comment: 
> #(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
> do:
> (printf "Input option: ")
> (read)
> 
> The read will be done before the printf. How can I flush(stdout)?
> 
> Best regards,
> 
> Paulo
> 
> > 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.