Namespace which tcl




















Michael Petrotta Add a comment. Active Oldest Votes. You invoke commands in another namespace using the fully-qualified syntax: ::the::other::namespace::command "some argument, as normal" You can also use partial namespace names; that's pretty common as a leading :: is a bit ugly Improve this answer.

Donal Fellows Donal Fellows k 18 18 gold badges silver badges bronze badges. If a given TCL file which exports that namespace also provides itself as a package Using 'namespace import'? The package require makes the code available at all, doing such source and load calls as are necessary behind the scenes. The documented commands might also be namespace export ed but it is entirely up to you to choose how to actually use the package.

FWIW, I usually do not use namespace import since I prefer to use the qualified names I think that's a bit clearer when I come to maintain the code, but that's entirely up to you. Hai Vu Hai Vu Sign up or log in Sign up using Google.

Sign up using Facebook. Sign up using Email and Password. The body of the structure is grouped with curly braces. This is important as the braces prevent the body from being substituted and evaluated until the proper time. In Tcl , mathematical expressions are evaluated using the expr command. This command works with integers, floating point values and logical Boolean values. There are many arithmetic operators and built-in math functions in Tcl. Boolean statements allow you to incorporate logic statements into your control structures and mathematical expressions for evaluation.

Braces, quotes, and square brackets control when variables and commands are processed. They are also used to group parameters. The character is used to skip lines and insert comments. This can be used both from within tkcon as well as from within a Tcl script. Procedures organize a repetitive group of commands into a logical block and allow for arguments to be parameterized. The task of extracting and manipulating information via a scripting language is often described using the term string manipulation.

Strings are a set of alphanumeric characters stored and manipulated together. These sets are concatenated, truncated, or partitioned by the script with a specific end in mind.

There are Tk commands that bring up the standard Windows style file browsers for selecting directories and files to open or save. Additionally, commands that allow you to extract information from the HyperWorks Desktop database, such as entity ID numbers on a mark, a list of assemblies, component names, elements per component, nodes per element, node values, and so forth. They are used to query information from the database or template system. The Script Exchange is a database of freely accessible scripts posted by users and Altair engineers.

A global procedure acts just like any function within Tcl. A global procedure can be called from a namespace without any need to import or otherwise localize the procedure. A procedure within a namespace is local to the namespace unless it is explicitly called or the procedure is exported from the namespace. The global scope is also designed such that any variables defined outside of a procedure or a namespace are automatically in the global scope. To access a global variable in a local scope, such as a procedure or namespace, you will need to use the global command.

As a script grows and as the number of scripts running simultaneously increases, the ability of the developer to avoid conflict between the names of procedures and variables defined in the global scope decreases. Likewise, any variable declared as global from within the procedure where the variable is defined is also included in the global scope, once the procedure has been run. Any attempt to access the variable before running the procedure will cause an error.

HyperWorks Desktop. HyperMesh Scripts This section contains details on general HyperWorks Desktop scripting concepts, along with documentation on the Tcl commands that can be used to query and modify the database and GUI. Tcl Tcl Namespaces Namespaces provide a means of organizing procedures and variables in Tcl. Search Help. Get Started Learn the basics and discover the workspace.

Tutorials Discover HyperWorks Desktop functionality with interactive tutorials. Manage Files and Data Learn how to create, open, import and save models. Display Controls Control the view and display of your model in the modeling window.

Session Navigation Use the Session Browser to view the current session and all the pages and windows it contains in a hierarchical display. Parameterize Report Templates Use the Parameters Browser to parameterize the contents of a session file or report template and automate a variety of analysis processes with the Parameters Browser. HyperWorks Collaboration Tools Explore, organize and manage your personal data, collaborate in teams, and connect to other data sources, such as corporate PLM systems to access CAD data or publish simulation data.

To resolve a command name, Tcl first looks in the current namespace, then in the namespaces in the path of the current namespace, and then in the global namespace.

It does not look in any intermediate containing namespaces , unless they happen to be in the path of the current namespace:. Tcl resolved the name in the global namespace and didn't search in the containing ns1 namespace. This behaviour can be modified via namespace path. LVwikignoming PYK The op was attempting to add a new routine to array , but the results were unexpected.

The solution, as provided by dkf , was to use ::set instead of just plain set in the body of the new routine, because ::tcl::array::set overrides ::set in that namespace.

So, this note is not specific to set, but applies in general. If you are seeing behavior that reports a problem that is unexpected, examine the code closely to see if you need to add namespacing to the commands in use.

Currently, the typical idiom for importing commands as functions into tcl::mathfunc is to use interp alias , which has the nasty effect of incurring some performance degradation on each invocation of the alias. If the source command has been exported from its own namespace, then it can be imported into another, which makes execution of the imported command considerably faster, and makes the new command robust against later renaming of the origin command.

Sometimes one might wish for more than what namespace import currently provides:. Here it is:. PYK See also proc alias for another implementation of the same.

Since Tcl8. In Tcl8. Note: unlike interp alias , you can not append any extra arguments with this "alias". However, if the intended argument is really just the subcommand of an ensemble as is string length , then you can simply alias the subcommand directly Known bugs: specifying bad arguments may leave some empty namespace and export-patterns behind.

That could be fixed with try or catch , but I thought it was already complicated enough as it is without fancy error handling. Hence, when removing command from origin namespace, the alias command will also cease to work. Better to copy the args and body of the original proc to the new namespace proc. PYK It's a question of knowing what you want to do. Sometimes, namespace import semantics are exactly what you want. Copying the args and the body of the original procedure is a distant third option.

If you're doing it, your design is probably suboptimal. There is no built-in namespace dup command, but such an action can be useful when a namespace is part of the implementation of an object system. Tcl's copy-on-write semantics make this less costly than it might at first seem. Duplicating a namespace involves duplicating some or all of the following:.

JeremyM I'm struggling with the decision as to whether to use a namespace or an object to hold code and variables that are a singleton, i. Because of this, a namespace seems like a more appropriate container, but I'm getting the feeling that namespaces are somewhat obsolete.



0コメント

  • 1000 / 1000