Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Lazy @something macro #40933

Closed
jeffreyesun opened this issue May 23, 2021 · 2 comments
Closed

Feature request: Lazy @something macro #40933

jeffreyesun opened this issue May 23, 2021 · 2 comments

Comments

@jeffreyesun
Copy link

For performance reasons, we usually do not need to evaluate the second argument of the something function. For example, in this pattern I sometimes use for propagating default arguments:

function foo(; bar=nothing)
   bar = something(bar, defaultbar())
   ...
end

I propose a lazy version of this, @something:

macro something(valornothing, ex)
    return valornothing == :nothing ? ex : valornothing
end

to be used as follows:

function foo(; bar=nothing)
   bar = @something(bar, defaultbar())
   ...
end

so that defaultbar() need not be called when it is not needed.

@DilumAluthge
Copy link
Member

DilumAluthge commented May 23, 2021

Don't we already have this on master?

https://docs.julialang.org/en/v1.7-dev/base/base/#Base.@something

(Added in #40729.)

@jeffreyesun
Copy link
Author

My bad, this is indeed already going to be in 1.7. Sorry for wasting your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants