# \[SOLVED\] Behavior of @generated with no arguments

**URL:** <https://discourse.julialang.org/t/solved-behavior-of-generated-with-no-arguments/35083>\
**Category:** General Usage\
**Tags:** question, metaprogramming\
**Created:** [February 24, 2020, 7:03pm UTC](https://discourse.julialang.org/t/solved-behavior-of-generated-with-no-arguments/35083 "2020-02-24T19:03:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)\
**Post date:** [February 24, 2020, 7:03pm UTC](https://discourse.julialang.org/t/solved-behavior-of-generated-with-no-arguments/35083/1 "2020-02-24T19:03:45Z")

</div>

EDIT: I somehow missed the appropriate section of the manual despite skimming through several times. Please disregard.

[https://docs.julialang.org/en/v1/manual/metaprogramming/#Optionally-generated-functions-1](https://docs.julialang.org/en/v1/manual/metaprogramming/#Optionally-generated-functions-1)

Here’s one of the current (v1.3.1) definitions of `ntuple`:

```julia
@inline function ntuple(f::F, ::Val{N}) where {F,N}
    N::Int
    (N >= 0) || throw(ArgumentError(string("tuple length should be ≥ 0, got ", N)))
    if @generated
        quote
            @nexprs $N i -> t_i = f(i)
            @ncall $N tuple t
        end
    else
        Tuple(f(i) for i = 1:N)
    end
end

```

This 0-argument version of `@generated` wasn’t something I was familiar with, _and it isn’t included in the `@generated` docstring_, so I looked it up as well.

```julia
macro generated()
    return Expr(:generated)
end

```

This only added to my confusion as `:generated` is not one of the [documented symbols for the `head` field of `Expr`](https://docs.julialang.org/en/v1/devdocs/ast/#Expr-types-1). `eval(Expr(:generated))` throws `ERROR: syntax: invalid syntax (generated)`, so evidently it’s not meaningful in global scope, but calling `f() = if @generated; :(println("foo")) else println("bars") end` prints “foo”, so it’s not testing whether the enclosing scope is a `@generated` function like I had initially assumed.

So what’s the deal with 0-argument `@generated` and `Expr(:generated)`? `@generated` is an exported symbol, so I would assume this is included in the v1.x stability backwards-compatibility guarantee despite not being documented.
