TCL有一些功能指针的概念吗? [英] Does TCL have some concept of function pointers?

查看:254
本文介绍了TCL有一些功能指针的概念吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用TCL,我想实现类似策略模式的功能。我想通过TCL功能打印输出的策略,所以我可以轻松地在打印到屏幕之间切换并打印到日志文件。在TCL中最好的方式是什么?

Working with TCL and I'd like to implement something like the Strategy Pattern. I want to pass in the "strategy" for printing output in a TCL function, so I can easily switch between printing to the screen and printing to a log file. What's the best way to do this in TCL?

推荐答案

TCL允许您将过程的名称存储在变量中,然后使用该变量调用过程;所以

TCL allows you to store the name of a procedure in a variable and then call the procedure using that variable; so

proc A { x } {
   puts $x
}

set strat A
$strat Hello

将调用proc A并打印出你好

will call the proc A and print out Hello

这篇关于TCL有一些功能指针的概念吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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