Comments (5)
I don't want to propose an exact wording, I just want to point out that it's pretty confusing the way that it is written now.
Nonetheless I would encourage you to open a pull-request.
This example does not appear to be a good example of dynamic scoping:
I see how that can be confusing. It would probably make sense to introduce:
f() = @show scoped_val[]
h() = @show scoped_val2[]
const scoped_val = ScopedValue(1)
const scoped_val2 = ScopedValue(0)
# Enter a new dynamic scope and set value
@show f() # 1
@show h() # 0
with(scoped_val => 2) do
f() # 2
h() # 0
with(scoped_val => 3, scoped_val2 => 5) do
f() # 3
h() # 5
end
f() # 2
h() # 0
end
f() # 1
h() # 0
But the example was not meant as a contrast against let
and rather an introduction into how scoped values behave.
and I have no idea what the purpose of the example is
To simply show the usage of the macro form?
Regarding 4
you are correct, I thought @kwdef
added a copy constructor.
julia> Base.@kwdef struct Configuration
color::Bool = false
verbose::Bool = false
end
Configuration
julia> Configuration(Configuration(), color = true)
ERROR: MethodError: no method matching Configuration(::Configuration; color::Bool)
Threading a value through the entire call-chain doesn't seem so bad to me.
That assumes you have control of the entire call-chain (which you often don't) and doesn't handle propagation to tasks cleanly.
from julia.
Nonetheless I would encourage you to open a pull-request.
I don't feel I know enough about ScopedValue
s to be writing the docs for them. 😅
and I have no idea what the purpose of the example is
To simply show the usage of the macro form?
I still think that could use some more explanation. How does the macro avoid the creation of another call-frame? Does the @with
macro not just lower to with
? Maybe I'm dumb, but I have no idea how @with(STATE => state, f())
is useful or how it avoids a call-frame or how it is semantically different from with(f, STATE => state)
.
from julia.
Does the
@with
macro not just lower towith
?
Looking at the code, it looks like with
is defined in terms of @with
. In the original PR, with
had its own try-finally
block.
I'm used to thinking of @foo(...)
as lowering to foo(...)
as a general design principle, but I guess Base sometimes does more exotic things with macros, like inserting compiler hints into Expr
objects that have no surface level syntax equivalent. (I guess inserting compiler hints is a sneaky way to avoid adding keywords like inline
or inbounds
to the language.)
from julia.
I might be able to work on a PR this evening.
from julia.
I'd also like to draw attention to this post and the two proceeding it (this isn't about the name of ScopedValues
, I promise). Specifically, I read the example with scopes and spawned threads wrong, when accompanied by the sentence about "the usual caveats for global variables apply in the context of concurrent programming".
I'd suggest spawning the threads and then introducing the scopes, and clarifying that the "usual caveats" is about the case where a ScopedValue
points to mutable data.
from julia.
Related Issues (20)
- exit_current_timer implementation is unsound HOT 1
- export statement lowering correctness, causing regression HOT 5
- sleep_state not_sleeping is not reset as required by signals
- [Test] need shim for FieldError HOT 1
- Julia builds for `native` CPU, even with `XC_HOST = x86_64-w64-mingw32` HOT 2
- Performance regressions in linear algebra benchmarks with Hermitian and Triangular matrices
- Performance regressions in BaseBenchmarks due to #54647 (Cleanup `MemoryRef`) HOT 2
- observed failure of TestPkg thread test
- race condition in waitany test
- Regression in threads tests on FreeBSD
- Operations on `views` much slower when indices are `start:1:stop` HOT 7
- [1.11+] jl_array_t no longer contains elsz HOT 1
- Unreachable reached HOT 2
- `mkpath` does not stably return the original path
- Deserialization in a Module() HOT 2
- `last(::Tuple{})` throws `BoundsError` HOT 5
- document `FieldError`
- peek docstring has a disconnect HOT 2
- Precompiling and FunctionWrappers lead to extra runtime allocations HOT 4
- Matrix `exp` and `log` are not inverse of each other HOT 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from julia.