{"id":781,"date":"2020-11-12T02:04:38","date_gmt":"2020-11-12T10:04:38","guid":{"rendered":"http:\/\/gantovnik.com\/bio-tips\/?p=781"},"modified":"2020-11-12T02:04:38","modified_gmt":"2020-11-12T10:04:38","slug":"134-global-variable-in-tcl","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2020\/11\/134-global-variable-in-tcl\/","title":{"rendered":"#134 Global variable in tcl"},"content":{"rendered":"<p>#134 Global variable in tcl<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nset f &quot;This is a global variable&quot;;\r\n\r\n#This procedure cannot access the global variable f.\r\nproc testproc1 { } {\r\n   catch {puts $f} val;\r\n   puts $val;\r\n}\r\n\r\n#This procedure can access the global variable f using the global command.\r\nproc testproc2 { } {\r\n   global f;\r\n   catch {puts $f} val;\r\n   puts $val;\r\n}\r\ntestproc1;\r\ncan't read &quot;f&quot;: no such variable\r\n\r\ntestproc2;\r\nThis is a global variable\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#134 Global variable in tcl set f &quot;This is a global variable&quot;; #This procedure cannot access the global variable f. proc testproc1 { } { catch {puts $f} val; puts $val; } #This procedure can access the global variable f using the global command. proc testproc2 { } { global f; catch {puts $f} val; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[24,27],"tags":[],"class_list":["post-781","post","type-post","status-publish","format-standard","hentry","category-hypermesh","category-tcl"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-cB","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":783,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/11\/135-global-namespace-in-tcl\/","url_meta":{"origin":781,"position":0},"title":"#135 Global namespace in tcl","author":"gantovnik","date":"2020-11-12","format":false,"excerpt":"#135 Global namespace in tcl It is possible to reference global variables inside procedures using global namespace indicator: [code language=\"python\"] set ::element_list \"1 2 3 4 5\"; proc ::element_info {} { puts $::element_list; set ::node_list \"10 20 30 40\"; puts $::node_list; } element_info; 1 2 3 4 5 10 20\u2026","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1339,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/01\/133-create-vectors-and-planes-using-tcl-in-hypermesh-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":781,"position":1},"title":"#250 Global variable using :: prefix in tcl","author":"gantovnik","date":"2022-01-05","format":false,"excerpt":"Qualifying a global variable is done by prefixing the variable name with the :: character sequence. This is a special case of namespace qualification where the :: prefix indicates that the variable resides in the global namespace. Example: [code language=\"python\"] set globalvar 100.2 proc test1 {} { puts \"test1: $::globalvar\"\u2026","rel":"","context":"In &quot;tcl&quot;","block_context":{"text":"tcl","link":"https:\/\/gantovnik.com\/bio-tips\/category\/tcl\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1341,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/01\/133-create-vectors-and-planes-using-tcl-in-hypermesh-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":781,"position":2},"title":"#251 Global variable using global keyword in tcl","author":"gantovnik","date":"2022-01-05","format":false,"excerpt":"The global variable can be declared with the global keyword. Example: [code language=\"python\"] set globalvar 100.2 proc test1 {} { global globalvar puts \"test1: $globalvar\" } proc test2 {} { global globalvar puts \"test2: $globalvar\" } test1 test2 [\/code] Result: [code language=\"python\"] test1: 100.2 test2: 100.2 [\/code]","rel":"","context":"In &quot;tcl&quot;","block_context":{"text":"tcl","link":"https:\/\/gantovnik.com\/bio-tips\/category\/tcl\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1331,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/01\/133-create-vectors-and-planes-using-tcl-in-hypermesh-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":781,"position":3},"title":"#246 Create a procedure with variable number of arguments in tcl","author":"gantovnik","date":"2022-01-04","format":false,"excerpt":"An example of a procedure with variable number of arguments is [code language=\"python\"] proc avg {numbers} { set sum 0 foreach number $numbers { set sum [expr $sum + $number] } set average [expr $sum\/[llength $numbers]] return $average } puts [avg {50 50 50 60}] puts [avg {50 50 50}]\u2026","rel":"","context":"In &quot;tcl&quot;","block_context":{"text":"tcl","link":"https:\/\/gantovnik.com\/bio-tips\/category\/tcl\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1337,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/01\/133-create-vectors-and-planes-using-tcl-in-hypermesh-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":781,"position":4},"title":"#249 Creating namespace in tcl","author":"gantovnik","date":"2022-01-05","format":false,"excerpt":"Namespace is a container for a set of identifiers that are used to group variables and procedures. Example: [code language=\"python\"] namespace eval MyMath { # Create a variable inside the namespace variable myResult } # Create procedures inside the namespace proc MyMath::Add {a b } { set ::MyMath::myResult [expr $a\u2026","rel":"","context":"In &quot;tcl&quot;","block_context":{"text":"tcl","link":"https:\/\/gantovnik.com\/bio-tips\/category\/tcl\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1403,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/02\/210-parametric-curve-in-3d-2-2-2-2-2-2-2-2-2-2-2-2-2-3-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":781,"position":5},"title":"#268 A progress indicator using tcl\/tk","author":"gantovnik","date":"2022-02-10","format":false,"excerpt":"#268 A progress indicator using tcl\/tk. [code language=\"python\"] # Create a simple progress gauge set, initially set to 0% proc gaugeCreate {win {color \"gray\"} } { frame $win canvas $win.display \\ -borderwidth 0 \\ -background white \\ -highlightthickness 0 \\ -width 200 \\ -height 20 pack $win.display -expand yes $win.display\u2026","rel":"","context":"In &quot;tcl&quot;","block_context":{"text":"tcl","link":"https:\/\/gantovnik.com\/bio-tips\/category\/tcl\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/02\/ex268.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/781","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=781"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/781\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}