Giter VIP home page Giter VIP logo

Comments (5)

vchuravy avatar vchuravy commented on July 24, 2024 1

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.

CameronBieganek avatar CameronBieganek commented on July 24, 2024

Nonetheless I would encourage you to open a pull-request.

I don't feel I know enough about ScopedValues 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.

CameronBieganek avatar CameronBieganek commented on July 24, 2024

Does the @with macro not just lower to with?

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.

CameronBieganek avatar CameronBieganek commented on July 24, 2024

I might be able to work on a PR this evening.

from julia.

mnemnion avatar mnemnion commented on July 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.