S-Lang Run-Time Library Reference: Version 1.4.0: Miscellaneous Functions

Next Previous Contents

## 19. Miscellaneous Functions

## 19.1 __get_reference

Synopsis

  Get a reference to a global object

Usage

  `Ref_Type __get_reference (String_Type nm)`

Description

  This function returns a reference to a global variable or function whose name is specified by `nm`. If no such object exists, it returns `NULL`, otherwise it returns a reference.

Example

  For example, consider the function:

  > `

  >         define runhooks (hook)
  >         {
  >            variable f;
  >            f = __get_reference (hook);
  >            if (f != NULL)
  >              @f ();
  >         }

  > `

  This function could be called from another S-lang function to allow customization of that function, e.g., if the function represents a mode, the hook could be called to setup keybindings for the mode.
See Also

  `is_defined, typeof, eval, autoload, __is_initialized, __uninitialize`

## 19.2 __uninitialize

Synopsis

  Uninitialize a variable

Usage

  `__uninitialize (Ref_Type x)`

Description

  The `__uninitialize` function may be used to uninitialize the variable referenced by the parameter `x`.

Example

  The following two lines are equivalent:

  > `

  >          () = __tmp(z);
  >          __uninitialize (&z);

  > `

See Also

  `__tmp, __is_initialized`

## 19.3 _auto_declare

Synopsis

  Set automatic variable declaration mode

Usage

  `Integer_Type _auto_declare`

Description

  The `_auto_declare` may be used to have all undefined variables implicitely declared as `static`. If set to zero, any variable must be declared witha `variable` declaration before it can be used. If set to one, then any undeclared variabled will be declared as a `static` global variable.

  The `_auto_declare` variable is is local to each compilation unit and setting its value in one unit has no effect upon its value in other units. The value of this variable has no effect upon the variables in a function.

Example

  The following code will not compile if `X` not been declared:

  > `

  >         X = 1;

  > `

  However,

  > `

  >         _auto_declare = 1;   % declare variables as static.
  >         X = 1;

  > `

  is equivalent to

  > `

  >         static variable X = 1;

  > `

Notes

  This variable should be used sparingly and is intended primarily for interactive applications where one types S-lang commands at a prompt.

## 19.4 getenv

Synopsis

  Get the value of an environment variable

Usage

  `String_Type getenv(String_Type var)`

Description

  The `getenv` function returns a string that represents the value of an environment variable `var`. It will return `NULL` if there is no environment variable whose name is given by `var`.

Example

  > `

  >         if (NULL != getenv ("USE_COLOR"))
  >           {
  >             set_color ("normal", "white", "blue");
  >             set_color ("status", "black", "gray");
  >             USE_ANSI_COLORS = 1;
  >           }

  > `

See Also

  `putenv, strlen, is_defined`

## 19.5 implements

Synopsis

  Name a private namespace

Usage

  `implements (String_Type name);`

Description

  The `implements` function may be used to name the private namespace associated with the current compilation unit. Doing so will enable access to the members of the namespace from outside the unit. The name of the global namespace is `Global`.

Example

  Suppose that some file `t.sl` contains:

  > `

  >          implements ("Ts_Private");
  >          static define message (x)
  >          {
  >             Global->vmessage ("Ts_Private message: %s", x);
  >          }
  >          message ("hello");

  > `

  will produce `"Ts_Private message: hello"`. This `message` function may be accessed from outside via:

  > `

  >         Ts_Private->message ("hi");

  > `

Notes

  Since `message` is an intrinsic function, it is global and may not be redefined in the global namespace.

See Also

  `use_namespace, current_namespace, import`

## 19.6 putenv

Synopsis

  Add or change an environment variable

Usage

  `putenv (String_Type s)`

Description

  This functions adds string `s` to the environment. Typically, `s` should of the form `"name=value"`. The function signals a S-lang error upon failure.

Notes

  This function is not available on all systems.

See Also

  `getenv, sprintf`

## 19.7 use_namespace

Synopsis

  Change to another namespace

Usage

  `use_namespace (String_Type name)`

Description

  The `use_namespace` function changes the current namespace to the one specified by the parameter. If the specified namespace does not exist, an error will be generated.

See Also

  `implements, current_namespace, import`

## 19.8 current_namespace

Synopsis

  Get the name of the current namespace

Usage

  `String_Type current_namespace ()`

Description

  The `current_namespace` function returns the name of the current namespace. If the current namespace is anonymous, that is, has not been given a name via the `implements` function, the empty string `""` will be returned.

See Also

  `implements, use_namespace, import`

Next Previous Contents