【发布时间】:2019-04-01 21:22:29
【问题描述】:
只是为了好玩,我写了以下代码:
proc "bake a cake" {"number_of_people" {number_of_children}} {
set fmt "Take %d pounds of flour and %d bags of marshmallows."
puts [format $fmt "${number_of_people}" ${number_of_children}]
puts "Put them into the oven and hope for the best."
}
"bake a cake" 3 3
{bake a cake} 5 0
我发现 proc 名称可能包含空格很有趣。我认为将它与基本上未使用的参数结合起来可以使 Tcl 程序看起来与口语自然语言非常相似,就像 Smalltalk 对其bakeACake forPeople: 3 andChildren: 3 所做的那样,只是没有奇怪的冒号干扰句子和不自然的词序.
为了进一步探索这个想法,我对 proc 的参数尝试了相同的模式,将每个 _ 替换为一个简单的空格。 tclsh8.6 不喜欢:
too many fields in argument specifier "number of people"
(creating proc "bake a cake")
invoked from within
"proc "bake a cake" {"number of people" {number of children}} {
set fmt "Take %d pounds of flour and %d bags of marshmallows."
puts [format $fmt "${n..."
(file "bake.tcl" line 1)
这引发了以下问题:
- 是否有令人信服的理由说明为什么 proc 名称可以包含空格但参数名称不能?
- 只是
proc的一个实现细节吗? - 是否可以编写
spaceproc来允许这种语法变体?
【问题讨论】:
标签: arguments tcl whitespace