sorawee
2021-5-28 07:02:55

Maybe put (close-output-port out) before read?


noahstorym
2021-5-28 07:06:57

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.


sorawee
2021-5-28 07:15:45

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.


noahstorym
2021-5-28 07:19:39

Thanks!


chansey97
2021-5-28 21:28:01

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).


kellysmith12.21
2021-5-28 21:28:50

@chansey97 Is this what you have in mind? https://docs.racket-lang.org/reference/engine.html?q=engin


chansey97
2021-5-28 21:31:29

Yes, they are very similar, but there are some slight differences. Scheme’s engine uses fuel, while Racket’s engine uses milliseconds .


chansey97
2021-5-28 21:38:11

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).


kellysmith12.21
2021-5-29 00:20:46

What is fuel?


chansey97
2021-5-29 03:47:27

@kellysmith12.21 Frankly speaking, I don’t know exactly what fuel is. I guess it is a minimal execution passage of a program.


sorawee
2021-5-29 03:49:20

It’s like car fuel. With fuel 5, you are only allowed to “execute 5 instructions”


chansey97
2021-5-29 03:49:43

Yes. For example, “fuel = 6” means the program executes 6 steps instead of 6 milliseconds.


kellysmith12.21
2021-5-29 04:57:02

Ah, so it’s less likely to vary between machines?


chansey97
2021-5-29 05:03:19

I think yes.