Skip to content

Conversation

@kpamnany
Copy link
Member

This enables taking a "snapshot" of scoped values and using that snapshot later.

@kpamnany kpamnany requested a review from vchuravy August 26, 2025 18:19
@adienes
Copy link
Member

adienes commented Aug 26, 2025

bikeshed: ScopedThunk ? Functor has always seemed both loaded and ambiguous to me

@JeffBezanson
Copy link
Member

We seem to be missing with(f, ::Scope). Then this could be implemented as

function inscope(f)
    s = current_scope()
    ()->with(f, s)
end

@Keno
Copy link
Member

Keno commented Aug 27, 2025

ScopedThunk seems better to me.

@kpamnany
Copy link
Member Author

I should have mentioned, that this was already added to ScopedValues.jl and is being upstreamed after some iteration. This interface was defined after some debate with @vchuravy.

I would have no objection to ScopedThunk instead of ScopedFunctor, but I do think that this use matches a rather well understood definition of a functor, and it has already been released in the package with this name. We could still change it if people insist...?

Re: @JeffBezanson's suggestion, using Scopes in user code was strongly discouraged by @vchuravy, and a with form that takes a Scope opens the door to that.

So, waiting on input from Valentin.

@Keno
Copy link
Member

Keno commented Aug 27, 2025

definition of a functor

What definition?

@kpamnany kpamnany force-pushed the kp-add-scopedfunctor branch from 8a443f9 to 588ef58 Compare August 27, 2025 12:42
@kpamnany
Copy link
Member Author

definition of a functor

What definition?

The C++ one.

Wikipedia:

In some languages, particularly C++, function objects are often called functors...
... the function is really a façade for a full object, carrying its own state.

@Keno
Copy link
Member

Keno commented Aug 27, 2025

Yikes. We do not use that terminology in Julia. (Please feel free to use this as a citation to remove the incorrect information from the julia section in the wikipedia page ;) ).

@Keno
Copy link
Member

Keno commented Aug 27, 2025

Although apparently we do in the manual... Am I just living in the twilight zone? We should not be.

@kpamnany
Copy link
Member Author

I don't see a problem with using a reasonably well-defined term pragmatically, even if category theorists complain.

@Keno
Copy link
Member

Keno commented Aug 27, 2025

It's just not what it does, in either definition - it's a type of closure that closes over the dynamic scope.

@Keno
Copy link
Member

Keno commented Aug 28, 2025

Although apparently we do in the manual

Ok, fixed that ;). I think for this pr, either ScopedThunk or ScopeClosure or ScopedClosure would be fine, but I'm vetoing Functor ;).

@kpamnany kpamnany changed the title ScopedValues: add ScopedFunctor ScopedValues: add ScopedThunk Aug 28, 2025
@kpamnany
Copy link
Member Author

I think the test failure is unrelated?

@kpamnany kpamnany merged commit 0679da1 into master Sep 6, 2025
7 checks passed
@kpamnany kpamnany deleted the kp-add-scopedfunctor branch September 6, 2025 18:37
@nsajko nsajko added the feature Indicates new feature / enhancement requests label Sep 7, 2025
@kpamnany
Copy link
Member Author

kpamnany commented Sep 9, 2025

@KristofferC can we backport this to 1.12?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Indicates new feature / enhancement requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants