Skip to content

Feature request: Lazy @something macro #40933

@jeffreyesun

Description

@jeffreyesun

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions