[tclcn] 回复:[tclcn] Tcl 中的 with

  • From: "金金" <568263554@xxxxxx>
  • To: "tclcn" <tclcn@xxxxxxxxxxxxx>
  • Date: Sun, 15 Sep 2013 10:21:22 +0800

求 tcl中的 uplevel------------------ 原始邮件 ------------------
发件人: "Mike Manilone"<crtmike@xxxxxx>
发送时间: 2013年9月15日(星期天) 凌晨4:03
收件人: "tclcn"<tclcn@xxxxxxxxxxxxx>;
主题: [tclcn] Tcl 中的 with


我研究了一段时间,磕磕绊绊地终于把通用的 with 命令做出来了,扔到 Tcl 人维基 [1] 上了,标题叫做 Playing with with ;-) 
(上次有人在 IRC 上推荐搜索「playing with」开头的页面,看到了不少有趣的内容,因此这次我也把我的内容放进来了。)

这个 with 命令其实很简陋,而且别人说是有 BUG,但是我看不出来,也不会修。 :-(

另外一个有趣的用法是 set contents [with open {AnyFile r} {read $handle}] 就可以直接把文件内容读取进来。

这个功能其实是借鉴 Common Lisp 里面的 (with-open-file),然后借助超棒的 Tcl 扩展性,我轻松做到了无限扩充性。 XDD

[1] http://wiki.tcl.tk/38729

.

Other related posts: