Re: Dynamic includes

new topic     » goto parent     » topic index » view thread      » older message » newer message

> Is there already a general facility in Euphoria to access a variable from
> having its name in a string?  This is a useful capability to have. There
> is one Euphoria command/proc/function that has the variable name as a
> parameter in quotes - I forget which one.

<snip>

routine_id
      Syntax: i = routine_id(st)
      Description: Return an integer id number, known as a routine id, for a
user-defined Euphoria procedure or function. The name of the procedure or
function is given by the string sequence st. -1 is returned if the named
routine can't be found.
      2Comments: The id number can be passed to call_proc() or call_func(),
to indirectly call the routine named by st.
      The routine named by st must be visible, i.e. callable, at the place
where routine_id() is used to get the id number. Indirect calls to the
routine can appear earlier in the program than the definition of the
routine, but the id number can only be obtained in code that comes after the
definition of the routine - see example 2 below.

      Once obtained, a valid routine id can be used at any place in the
program to call a routine indirectly via call_proc()/call_func().

      Some typical uses of routine_id() are:

      1. Calling a routine that is defined later in a program.
      2. Creating a subroutine that takes another routine as a parameter.
(See Example 2 below)
      3. Using a sequence of routine id's to make a case (switch) statement.
      4. Setting up an Object-Oriented system.
      5. Getting a routine id so you can pass it to call_back(). (See
platform.doc)

      Note that C routines, callable by Euphoria, also have routine id's.
See define_c_proc() and define_c_func().





the debate over whether or not Euphoria should include a function called
variable_id() has gone on for some time. i believe someone altered the
interpreter to incorporate this, and it lies somewhere in the archive. i for
one would like it, and have found a need for it on occation.

~Greg
g.haberek at comcast.net

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu