For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
function
Compile-time reflection over function values.
reflect_fn[func] is a comptime alias for the ReflectedFn[func] handle
type, exposing function introspection through static methods. This is the
function-side counterpart to reflect[T] / Reflected[T] for types.
from std.reflection import reflect_fn
def my_func(x: Int) -> Int:
return x + 1
def main():
print(reflect_fn[my_func].display_name()) # "my_func"
print(reflect_fn[my_func].linkage_name()) # mangled symbol name
comptime values
reflect_fn
comptime reflect_fn[func_type: AnyType, //, func: func_type] = ReflectedFn[func]
A compile-time alias for the reflection handle type of function func.
Resolves to ReflectedFn[func], a type whose static methods expose function
introspection. Use it as reflect_fn[my_func].display_name() rather than
constructing an instance.
Example:
from std.reflection import reflect_fn
def add(a: Int, b: Int) -> Int:
return a + b
def main():
print(reflect_fn[add].display_name()) # "add"
Parameters
- func_type (
AnyType): The function's type (inferred). - func (
func_type): The function value to introspect.
Structs
-
ReflectedFn: A compile-time reflection handle type for a function value.