Racket interaction in DrRacket and on terminal

617 views Asked by At

This program works fine in DrRacket :

(define (display-state input data)
  input)

(define (update-state input data) 
  data  )

(define (main input data)  
    (displayln (display-state input data))
    (main (read-line (current-input-port) 'any) (update-state input data)))

(main "" data)

It's the skeleton of a program that reads continually from a terminal interaction and does something with the user's input and a data state.

However, on the terminal, using

raco exe prog.rkt

It terminates after the first input. Anyone know why? Is it a bug / feature of read-line or current-input-port ?

1

There are 1 answers

2
interstar On

OK. I see what I did wrong. (Stupid, but I'll leave this in case anyone else has the same problem)

I expected raco exe to be running the program. But actually it was just compiling it into the executable.

So I was just typing into what I thought was the input when actually I was typing into the window waiting for compilation to terminate.

Actually I needed to compile with

raco exe prog.rkt

and THEN run with

./prog

Doh!