开发者

What is difference in several styles for proc syntax in tcl?

May I know how sytanx of proc affets on its working. in context of

-Memory consumption

-Argument passing

-scope of proc (local/global)

proc dosomething {} {
   #code here
}

proc dosomething { } {
    #code here
}

proc dosomething {
    #c开发者_开发知识库ode here
}

proc dosomething args {
     #code here
}

proc ::dosomething {} {
     #code here
}

And so on.....


They are mostly the same:

Defines a command with no arguments

proc dosomething {} {
   #code here
}

Same as above, defines a command with no arguments

proc dosomething { } {
    #code here
}

Not valid... should throw an error

proc dosomething {
    #code here
}

Defines a command with a variable number of arguments (ie, varargs)

proc dosomething args {
     #code here
}

Defines a command, in the top level namespace, with no arguments (same as the first two in most cases)

proc ::dosomething {} {
     #code here
}

There's no such thing as a local proc, btw. They can be inside a namespace, but all procs are global.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜