Maybe put (close-output-port out) before read?
Thank you, it works! I’m a little confused when should I use close-output-port ? If I write a string and read it, it seems work.
This behavior is caused from the interaction of make-pipe + read. If you use make-pipe + read-char or string port + read, it would work fine.
The issue with make-pipe + read is that, read is looking for a delimiter. For example, if you have:
(define-values (in out) (make-pipe))
(display "123 " out)
(displayln (read in)) This would work fine, because after read encounters the space, it knows that 123 ends there, so it can produce 123 right away.
read-char doesn’t look for a delimiter, so it would work fine. String port is automatically delimited at the end, so it would work fine as well.
Thanks!
Does Racket currently support Scheme’s https://www.scheme.com/tspl4/examples.html#./examples:h11\|engine ? I have searched the internet and found a workaround: https://gist.github.com/soegaard/d32e12d89705c774b71ee78ef930a4bf (sicp-concurrency.rkt) (provide (rename-out [timed-datum #%datum]
[timed-apply #%app] ; <---- redefine #%app
[timed-set! set!])
(all-defined-out)) Each time we #%app a function, decrement the timer. However, it seemly cannot work well with Racket module system? Because it forces all modules to import sicp-concurrency.rkt (that is impracticable).
@chansey97 Is this what you have in mind? https://docs.racket-lang.org/reference/engine.html?q=engin
Yes, they are very similar, but there are some slight differences. Scheme’s engine uses fuel, while Racket’s engine uses milliseconds .
The advantage of fuel is that it is more stable (?). For example, If I write a procedure for non-termination test, Scheme’s engine seems more suitable. Because we can get the same result as long as the same fuel be given to the engine (not depend on the performance of the computer).
What is fuel?
@kellysmith12.21 Frankly speaking, I don’t know exactly what fuel is. I guess it is a minimal execution passage of a program.
It’s like car fuel. With fuel 5, you are only allowed to “execute 5 instructions”
Yes. For example, “fuel = 6” means the program executes 6 steps instead of 6 milliseconds.
Ah, so it’s less likely to vary between machines?
I think yes.