has_ivar

Gamma: Version 4.0
Prev |  | Next

# `has_ivar`

`has_ivar` -- queries for the existence of an instance variable.

## Syntax

    has_ivar (instance|class, variable)

## Arguments

`instance`|`class`

  An instance of a class; or a class.

`variable`

  An instance variable name, as a symbol.

## Returns

t if the instance or class contains the named instance variable, or if any parent (base) of the class contains the instance variable, otherwise nil.

## Description

This function queries an instance or class to determine whether a given instance variable exists for that instance or class. When querying classes, if any parent (base) of that class contains the given instance variable, this function returns t. It is possible for a class to contain an instance variable, and an instance of that class not to contain it, but only if `class_add_ivar` was called after the instance was created. See `class_add_ivar` for details.

## Example

| This example is based on the class and method developed in `method`. The variable name is preceded by # to prevent evaluation. See Quote Operators for more information.

        Gamma> Square;
        (defclass Square RegPolygon [(area . (defun Square.area (self) (sqr (@ self length))))][length (sides . 4)])
        Gamma> sqB;
        {Square (length) (sides . 4)}
        Gamma> has_ivar(Square, #sides);
        t
        Gamma> has_ivar(Square, #perimeter);
        nil
        Gamma> has_ivar(sqB, #area);
        nil
        Gamma> has_ivar(sqB, #length);
        t
        Gamma>

## See Also

`class_add_ivar`

Prev | Home | Next
`has_cvar` | Up | `instance_vars`

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.