Re: Per-thread working directory and umask proposal Marc Nieper-WiÃkirchen 23 Apr 2020 18:55 UTC
Am Do., 23. Apr. 2020 um 19:55 Uhr schrieb Marc Feeley <email@example.com>: [...] > You could simply add a (dynamic-env-copy thunk) procedure that runs thunk with all the dynamic environment bindings copied, which could be useful anyway as a general purpose operation. Indeed, this would provide a way from (c) to (b); I'm wondering whether this can be implemented in O(1) (or at least not in O(n) where n is the size of the dynamic environment). > Your argument is similar to saying that we could get rid of “set!” altogether by just doing (define var (box val)) whenever we want a mutable variable. Then get rid of set-car! similarly… to just have box and set-box!. Very MLish! I view that as taking something away from my language, not the other way around! This is actually the situation with the parameter objects of R7RS-small where mutation is not standardized; so all you can do is to put boxes into the parameters. I would rather be able to set the parameter objects directly. (Apart from this being more direct and more Scheme-like, it would work on `current-input-port', etc., as well.) It probably depends on what would be used more, the (b) semantics or the (c) semantics. If the (b) semantics are at least not incorrect for most use cases, there's at least a way through the box thing to get to the (c) type of semantics. > In any case, mutation of parameter objects should not be viewed as good style, similarly to the use of “set!”. But this does not mean I want to remove it from the language because in some cases it is the right thing to use. > > If parameter bindings are automatically copied when a thread is started it prevents that new thread from changing the parent’s parameter bindings easily, but it is still possible to do so with continuations in a contrived way… by having the child call a continuation created in the parent (because the dynamic environment is captured by the continuation) and arranging for control to come back to the child (with another continuation). So this means copying the dynamic bindings on thread creation makes a simple thing (parameter object mutation) very complex to achieve, but not impossible… so you don’t get a “reliable parameter independence” property. A nice trick! Reliable parameter indepence wasn't my goal, though. Just true thread locals when used in a standard way. > > With respect to the performance issues, I have no simple answer yet. > > It would suffice to spawn parameters on demand, which would just make > > the mutation more costly, I think. > > I’m not sure I follow. You mean a kind of “copy-on-write”? I’d like to see the implementation of that and compare the performance to the case where there is no copy involved. Yes, something like a "copy-on-write". But I have to be careful what I say because I haven't yet thought about an implementation of that. It could possibly be implemented with a continuation mark. If one tries to modify a parameter across that mark, a copy could be modified instead. If this is possible, one could take the (c) semantics and instead of adding a potentially very costly `dynamic-env-copy' (whose semantics are not at all clear to me), calling the thunk with the continuation mark set would suffice.