On 8/16/2017 3:34 PM, Zelphir Kaltstahl wrote:
Just a few quick questions regarding the places code:

1. Is `?` like `if`? For me it says that it is an undefined identifier.

Um? ... I think that probably is a lambda glyph that didn't render for you. If you are looking at

  (let [
        (output (lambda (fmt . whatever)
                  (apply eprintf fmt whatever)
                  (flush-output (current-error-port))

then that surely is the case.

That special output function is an artifact of wanting to print on the console from the place. Normally stderr to a process is unbuffered, however a place is just a kernel thread running a separate copy of the Racket VM. Racket (or maybe the DrRacket debugger) buffers stderr for places, so the port has to be flushed to see output as it happens rather than waiting for the place to terminate or the buffer to fill up.

Places support stdio so they can be pipelined like Unix processes, but in practice most interactions with them should be through channel messaging. Channel descriptors, file handles, tcp ports, etc. all can be passed around via messages, so you can implement arbitrarily complex connection schemes using messaging that are impossible using simple pipes.

2. If I understand correctly, the place is looping and in each iteration is 
looks if there is a message on the channel, which matches something. Is this 
creating a lot of extra work for looking on the channel all the time?

Yes. A place terminates when its last instruction is executed, so you need to use a loop to keep it alive. Channels are signaling objects (event sources). 'place-channel-get' blocks until there is a message available or until the channel is closed.

3. What are `p`, `_i`, `_o` and `_e` doing?

The 'place*' call returns 4 values: a channel to the new place, and the ports bound to its stdio. 'p' is the channel - the only value I'm interested in. The others are placeholders. Unfortunately, with multiple value returns, Racket [like Scheme] doesn't allow for ignoring don't cares - you have to catch all the values.

4. Could I replace `set!-values` with a `let`?

No, but you could replace it with 'let-values'.

Or you could use 'place' which returns a single value (the channel) instead of 'place*' which returns 4. I chose 'place*' specifically because I wanted console output from the places and needed to pass the stdio port to them.

It's a matter of style. I prefer to limit nesting levels (or use let*) because indentation quickly gets out of control. YMMV. From a technical perspective, binding code is somewhat faster than assignment code - but in practice with the current compiler the difference rarely matters. And starting places is a slow process anyway.


You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to