Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

Any.fz


# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation.  If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
#  Tokiwa Software GmbH, Germany
#
#  Source code of Fuzion standard library feature Any
#
#  Author: Fridtjof Siebert (siebert@tokiwa.software)
#
# -----------------------------------------------------------------------

# Any -- parent feature of all features that do not have an explicit parent
#
public Any ref is


  # create a String from this instance.  Unless redefined, `a.as_string` will
  # create `"instance[T]"` where `T` is the dynamic type of `a`
  #
  public as_string String => "instance[{Any.this.dynamic_type.name}]"


  # convenience prefix operator to create a string from a value.
  #
  # This permits usage of `$` as a prefix operator in a similar way both
  # inside and outside of constant strings: $x and "$x" will produce the
  # same string.
  #
  public prefix $ => Any.this.as_string


  # Get the dynamic type of this instance.  For value instances `x`, this is
  # equal to `type_of x`, but for `x` with a `ref` type `x.dynamic_type` gives
  # the actual runtime type, while `type_of x` results in the static
  # compile-time type.
  #
  # There is no dynamic type of a type instance since this would result in an
  # endless hierarchy of types.  So for Type values, dynamic_type is redefined
  # to just return Type.type.
  #
  public dynamic_type => Any.this.type


  # Get a type as a value.
  #
  # This is a feature with the effect equivalent to Fuzion's `expr.type` call tail.
  # It is recommended to use `expr.type` and not `expr.type_value`.
  #
  # `type_value` is here to show how this can be implemented and to illustrate the
  # difference to `dynamic_type`.
  #
  public type.type_value => Any.this.type
last changed: 2025-01-23