4	Technical realization
4.1	Variants in realizing this change of “namespace import”
4.1.1	imported commands as list/array inside the Namespace structure
On one hand it would be easy to install a new attribute in the Namespace structure, a list or an array of imported commands, similar to the array of exported ones.
This new attribute has to be maintained, so a "dynamic" list would perhabs the best. This could be done in a similar way like the function DoImport works with the ImportRef attribute of the Command structure.
To maintain this list the related functions creating, importing, renaming, and deleting commands must be extended to grow or to shrink this list of imported commands of the current namespace.
Those functions are:
•	Tcl_ProcObjCmd (tclProc.c)
deleting an imported command element from that list (if existing),
•	Tcl_Import (tclNamesp.c)
creating an imported command element in that list,
•	TclRenameCommand (tclBasic.c)
deleting or changing an imported command element in that list
To get all imported commands of a namespace the "namespace import" command (NamespaceImportCmd function) would return a kind of string representation of the elements of the list of imported commands (list of command names).
The ImportRef structure could be reused as list of imported commands inside a namespace.
The runtime consumption would increase in Tcl_ProcObjCmd, Tcl_Import, TclRenameCommand, maintaining the list of imported commands.
Runtime consumption would be added to NamespaceImportCmd.
4.1.2	the imported commands knowing to be imported
On the other hand it would be more easy to maintain and more centralized, if only the command knows itself, if it is imported or not. Than only the function importing a command (DoImport in tclNamespc.h) would have to set a kind of flag.
If a command is redefined, deleted (by renaming) than the "flagged" Command structure will be deleted, so no maintainer will be needed.
To get all imported commands of a namespace the "namespace import" command (NamespaceImportCmd function) would have to loop over all namespace commands asking for the imported state, collecting the names of the imported ones in a list.
The runtime consumption would increase in DoImport, flagging the imported, newly created commands.
4.1.3	the ways to signal a command was imported
The Command structure is the place to signal if a command was imported, but there are different ways to achieve this (sorted by memory consumption and the chance for future enhancements):
•	insert a new flag bit for commands CMD_IS_IMPORTED to be used in the flags attribute of the Command structure
•	insert a "boolean" integer as a new attribute of the Command structure
•	insert a Namespace pointer to the exporting namespace as a new attribute of the Command structure – just to point to the “source” namespace
•	insert a Command pointer to the exported command as a new attribute of the Command structure – just to point to the “source” command (unnecessary, because an imported command has this pointer in his ClientData
None of the four possibilities costs much in implementing and even the first would do its job, without changing the Command structure at all, which is important to prevent changing the “fingerprint” of this structure.
The introduction of a new command flag bit CMD_IS_IMPORTED would add only a new define in tclInt.h, and the set of this flag in the DoImport function.
4.2	Realization of the "namespace import" command
4.2.1	changes in tclInt.h
Add the command flag bit right behind the definition of the Command structure and the two already exiting command flags.

/*
 * Flag bits for commands. 
 *
 * CMD_IS_DELETED -		Means that the command is in the process
 *				of being deleted (its deleteProc is
 *				currently executing). Other attempts to
 *				delete the command should be ignored.
 * CMD_TRACE_ACTIVE -		1 means that trace processing is currently
 *				underway for a rename/delete change.
 *				See the two flags below for which is
 *				currently being processed.
 * CMD_HAS_EXEC_TRACES -	1 means that this command has at least
 *				one execution trace (as opposed to simple
 *				delete/rename traces) in its tracePtr list.
 * CMD_IS_IMPORT -		1 means that this command was imported
 * TCL_TRACE_RENAME -		A rename trace is in progress. Further
 *				recursive renames will not be traced.
 * TCL_TRACE_DELETE -		A delete trace is in progress. Further 
 *				recursive deletes will not be traced.
 * (these last two flags are defined in tcl.h)
 */
#define CMD_IS_DELETED		0x1
#define CMD_TRACE_ACTIVE	0x2
#define CMD_HAS_EXEC_TRACES	0x4
#define CMD_IS_IMPORTED		0x8
4.2.2	changes in tclNamesp.c
The function DoImport has to be modified right behind creating the new imported command with Tcl_CreateObjCommand:
dataPtr	= (ImportedCmdData *) ckalloc(sizeof(ImportedCmdData));
importedCmd	= Tcl_CreateObjCommand(interp, 		Tcl_DStringValue(&ds), InvokeImportedCmd,
	(ClientData) dataPtr, DeleteImportedCmd);
importedCmdPtr		= (Command *) importedCmd;
importedCmdPtr->flags	|= CMD_IS_IMPORTED;
dataPtr->realCmdPtr	= cmdPtr;
dataPtr->selfPtr		= (Command *) importedCmd;
The function NamespaceImportCmd to react on having on arguments with return a list of imported commands. The new syntax would be:
namespace import ?-origins | ?-force? pattern ?pattern ...??
The command “namespace import” would return a list of absolute command names.
The option “-origin” would change the result list. Instead of the absolute command names the origins would be returned. The origins of the imported commands would be queryied with the function TclGetOriginalCommand.
Here the changes in the function NamespaceImportCmd:

static int
  NamespaceImportCmd(dummy, interp, objc, objv)
    ClientData dummy;		/* Not used. */
    Tcl_Interp *interp;		/* Current interpreter. */
    int objc;			/* Number of arguments. */
    Tcl_Obj *CONST objv[];	/* Argument objects. */
  {
    register int   i              = 0,
                   result         = TCL_OK;
    int            allowOverwrite = 0,
                   returnOrigins  = 0,
                   firstArg       = 2;
    char           *string        = (char *) NULL,
                   *pattern       = (char *) NULL;
    Namespace      *currNsPtr     = (Namespace*) NULL;
    Command        *command       = (Command *) NULL;
    Tcl_HashSearch search;
    Tcl_HashEntry  *hPtr          = (Tcl_HashEntry *) NULL;
    Tcl_Obj        *importedList  = (Tcl_Obj *) NULL;
                   *cmdNameObj    = (Tcl_Obj *) NULL;
    Tcl_Command    token;

    if (objc < 2) {
	Tcl_WrongNumArgs(
        interp,
        2, objv,
        "?-origins | ?-force? pattern ?pattern...??"
      );
	return TCL_ERROR;
    }

    /*
     * Detect the optional arguments "-force" and "-origins"
     * as the first argument.
     */
    if (firstArg < objc) {
	string = TclGetString(objv[firstArg]);
	if (*string == '-') {
        if (strcmp(string, "-force") == 0) {
          if ( objc <= 3 ) {
      	Tcl_WrongNumArgs(
              interp,
              3, objv,
              NULL
            );
	      return TCL_ERROR;
          }

	    allowOverwrite = 1;
          firstArg++;
        } elseif (strcmp(string, "-origins") == 0) {
          if ( objc != 3 ) {
	      Tcl_WrongNumArgs(
              interp,
              3, objv,
              NULL
            );
	      return TCL_ERROR;
          }

          returnOrigins = 1;
	  } else {
          Tcl_ResetResult( interp );
          Tcl_SetAppendResult(
            interp,
            "bad option \"",
            string,
            "\": must be –force, -origins, or omitted"
          );
          return TCL_ERROR;
        }
	}
    }

    if ((objc == 2) ||
        ((objc == 3) && (returnOrigins == 1) {
      /* get the current namespace and the first command of this
       * namespace
       */
      currNsPtr    = (Namespace*) Tcl_GetCurrentNamespace(interp)
	hPtr         = Tcl_FirstHashEntry(currNsPtr->cmdTable, &search);

      /* initialize the list of imported commands
       */
      importedList = Tcl_NewObj();

      /* loop over the commands of the current namespace
       * to test if they are imported and than, if so,
       * to get their absolute (original) names
       */
	for (; hPtr!= NULL ; hPtr=Tcl_NextHashEntry(&search)) {
        token   = (Tcl_Command) Tcl_GetHashValue(hPtr);
        command = (Command *) token;

        if (command->flags & CMD_IS_IMPORTED) {
          if (returnOrigins == 1) {
            /* get the origin of the imported namespace command
             */
            token = TclGetOriginalCommand(token);
          }

          /* get the absolute/full name of the imported
           * namespace command
           */
          cmdNameObj = Tcl_NewObj();

          Tcl_GetCommandFullName(interp, token, cmdNameObj);

          result = Tcl_ListObjAppendElement(
            interp, importedList, cmdNameObj
          );

          if (result == TCL_ERROR) {
            Tcl_DecrRefCount( importedList );
            return TCL_ERROR;
          }
        }
      }

      Tcl_SetObjResult(interp, importedList);
      return TCL_OK;
    }
    
    /* from here on the rest of NamespaceImportCmd */
  }