TCL:关于源、包、命名空间命令 [英] TCL : Regarding source , package , namespace command

查看:39
本文介绍了TCL:关于源、包、命名空间命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解 tcl 中的模块化编程以及我们如何实现这一点.

I want to know about modular programming in tcl and how we can achieve that .

在一些 tcl 教程中提到像 source 命令在实现模块化"方面有一些缺点,因此我们在包"有更多缺点之后来到包",因此我们带来了包和命名空间的组合.

In some tcl tutorials mention like source command having some drawbacks in achieving "modularity" so that we came to the "package" after that "package" is having some more drawbacks so that we came with the combination of package and namespaces .

我想知道 3 个概念的缺点和适当的层次结构.有人可以帮我吗?

I want to know what are the drawbacks and proper hierarchy of 3 concepts . Can Anyone help me ?

推荐答案

我不确定我是否正确理解您的问题,因此我将尝试解释您在问题中抛出的 3 个命令:

I'm not sure if I understand your question correctly, so I'll try to explain the 3 commands you throwed in your question:

  • source:评估作为 Tcl 脚本的文件.——它只是打开文件,读取到 EOF 字符(Windows 和 *nix 上的 ^Z)并对其进行评估.
    它不跟踪源文件,因此您可以再次获取同一个文件(非常适合热修补),但缺点是:它会再次获取文件.
  • package:管理包.它基本上会跟踪所提供的包,并尝试找出它必须获取哪个文件才能加载新包.
  • namespace:他们为命令和变量提供上下文,因此您不必担心命令的唯一名称.只是命名空间必须是唯一的.与加载包或其他模块无关,它只是提供命名空间.

我建议你使用包,每个包在它自己的文件中,每个包的命名空间等于所有命令所在的包名.
您应该使用 namespace export 导出公共命令.

I suggest that you use packages, each package in it's own file, each package with a namespace equal to the package name where all commands reside.
You should export the public commands with namespace export.

这篇关于TCL:关于源、包、命名空间命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆