{"action":"created","issue":{"url":"https://api.github.com/repos/andreas-kupries/critcl/issues/48","labels_url":"https://api.github.com/repos/andreas-kupries/critcl/issues/48/labels{/name}","comments_url":"https://api.github.com/repos/andreas-kupries/critcl/issues/48/comments","events_url":"https://api.github.com/repos/andreas-kupries/critcl/issues/48/events","html_url":"https://github.com/andreas-kupries/critcl/issues/48","id":49655037,"number":48,"title":"critcl::reset for multiple compilations","user":{"login":"tpoindex","id":5752090,"avatar_url":"https://avatars.githubusercontent.com/u/5752090?v=3","gravatar_id":"","url":"https://api.github.com/users/tpoindex","html_url":"https://github.com/tpoindex","followers_url":"https://api.github.com/users/tpoindex/followers","following_url":"https://api.github.com/users/tpoindex/following{/other_user}","gists_url":"https://api.github.com/users/tpoindex/gists{/gist_id}","starred_url":"https://api.github.com/users/tpoindex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tpoindex/subscriptions","organizations_url":"https://api.github.com/users/tpoindex/orgs","repos_url":"https://api.github.com/users/tpoindex/repos","events_url":"https://api.github.com/users/tpoindex/events{/privacy}","received_events_url":"https://api.github.com/users/tpoindex/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/andreas-kupries/critcl/labels/feature","name":"feature","color":"0052cc"}],"state":"open","locked":false,"assignee":{"login":"andreas-kupries","id":577247,"avatar_url":"https://avatars.githubusercontent.com/u/577247?v=3","gravatar_id":"","url":"https://api.github.com/users/andreas-kupries","html_url":"https://github.com/andreas-kupries","followers_url":"https://api.github.com/users/andreas-kupries/followers","following_url":"https://api.github.com/users/andreas-kupries/following{/other_user}","gists_url":"https://api.github.com/users/andreas-kupries/gists{/gist_id}","starred_url":"https://api.github.com/users/andreas-kupries/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreas-kupries/subscriptions","organizations_url":"https://api.github.com/users/andreas-kupries/orgs","repos_url":"https://api.github.com/users/andreas-kupries/repos","events_url":"https://api.github.com/users/andreas-kupries/events{/privacy}","received_events_url":"https://api.github.com/users/andreas-kupries/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/andreas-kupries/critcl/milestones/3","html_url":"https://github.com/andreas-kupries/critcl/milestones/3.1.14","labels_url":"https://api.github.com/repos/andreas-kupries/critcl/milestones/3/labels","id":984966,"number":3,"title":"3.1.14","description":null,"creator":{"login":"andreas-kupries","id":577247,"avatar_url":"https://avatars.githubusercontent.com/u/577247?v=3","gravatar_id":"","url":"https://api.github.com/users/andreas-kupries","html_url":"https://github.com/andreas-kupries","followers_url":"https://api.github.com/users/andreas-kupries/followers","following_url":"https://api.github.com/users/andreas-kupries/following{/other_user}","gists_url":"https://api.github.com/users/andreas-kupries/gists{/gist_id}","starred_url":"https://api.github.com/users/andreas-kupries/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreas-kupries/subscriptions","organizations_url":"https://api.github.com/users/andreas-kupries/orgs","repos_url":"https://api.github.com/users/andreas-kupries/repos","events_url":"https://api.github.com/users/andreas-kupries/events{/privacy}","received_events_url":"https://api.github.com/users/andreas-kupries/received_events","type":"User","site_admin":false},"open_issues":4,"closed_issues":0,"state":"open","created_at":"2015-02-18T18:40:37Z","updated_at":"2015-05-05T20:44:50Z","due_on":null,"closed_at":null},"comments":17,"created_at":"2014-11-21T04:34:54Z","updated_at":"2015-05-06T02:45:03Z","closed_at":null,"body":"Critcl currently only allows one compilation per program execution, here is an example:\r\n```\r\n$ tclsh8.6\r\n% package require critcl\r\n3.1.12\r\n% critcl::cproc foo {} int {return 1;}\r\n% foo\r\n1\r\n% critcl::cproc bar {} int {return 2;}\r\ncritcl::cproc (level 2 cmd {critcl::cproc bar {} int {return 2;}} line 1 type eval): Illegal attempt to define C code in  after it was built.\r\n```\r\nI propose a \"critcl::reset\" command be added, so that multiple compilations are supported.  I have a quick-and-dirty patch to do this.  The patch works by saving the critcl namespace variables and arrays, and restoring that state when critcl::reset is called.\r\n\r\n```\r\n*** critcl.tcl.orig\t2014-11-20 11:35:19.115447013 -0700\r\n--- critcl.tcl\t2014-11-20 12:33:14.360826503 -0700\r\n***************\r\n*** 4847,4856 ****\r\n--- 4847,4899 ----\r\n      return\r\n  }\r\n  \r\n+ proc ::critcl::InitialState {} {\r\n+     variable _initialState\r\n+     foreach _ns [concat [namespace current] [namespace children]] {\r\n+         dict set _initialState $_ns [namespace eval $_ns {\r\n+             set _arrays []\r\n+             set _vars []\r\n+             foreach _v [lsort [info vars]] {\r\n+                 if {[regexp {^(_)|(arg)|(auto_)|(env)|(errorInfo)|(tcl_)|(history).*} $_v]} {\r\n+                     continue\r\n+                 }\r\n+                 if {[array exists $_v]} {\r\n+                     if {[catch {lappend _arrays $_v [array get $_v]}]} {\r\n+                         lappend _arrays $_v {}\r\n+                     }\r\n+                 } else {\r\n+                     if {[catch {lappend _vars   $_v [set $_v]}]} {\r\n+                         lappend _vars $_v {}\r\n+                     }\r\n+                 }\r\n+             }\r\n+             list arrays $_arrays vars $_vars\r\n+         }]\r\n+     }\r\n+     rename ::critcl::InitialState {}\r\n+     return \r\n+ }\r\n+ \r\n+ proc ::critcl::reset {} {\r\n+     variable _initialState\r\n+     foreach ns [concat [namespace current] [namespace children]] {\r\n+         lassign [dict get $_initialState $ns] arrays arraydata vars vardata\r\n+         foreach {_v _d} $arraydata {\r\n+             unset ${ns}::$_v\r\n+             array set ${ns}::$_v $_d\r\n+         }\r\n+         foreach {_v _d} $vardata {\r\n+             set ${ns}::$_v $_d\r\n+         }\r\n+     }\r\n+     return \r\n+ }\r\n+ \r\n  # # ## ### ##### ######## ############# #####################\r\n  ## State\r\n  \r\n  namespace eval ::critcl {\r\n+     variable _initialState ;# state of package arrays/variables after initialization\r\n      variable mydir    ;# Path of the critcl package directory.\r\n      variable run      ;# interpreter to run commands, eval when, etc\r\n  \r\n***************\r\n*** 5019,5024 ****\r\n--- 5062,5068 ----\r\n  \r\n  \tvariable code\t         ;# This array collects all code snippets and\r\n  \t\t\t\t  # data about them.\r\n+         array set code {}\r\n  \r\n  \t# Keys for 'code' (above) and their contents:\r\n  \t#\r\n***************\r\n*** 5206,5209 ****\r\n--- 5250,5254 ----\r\n  ## Ready\r\n  \r\n  ::critcl::Initialize\r\n+ ::critcl::InitialState\r\n  return\r\n\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/andreas-kupries/critcl/issues/comments/99299559","html_url":"https://github.com/andreas-kupries/critcl/issues/48#issuecomment-99299559","issue_url":"https://api.github.com/repos/andreas-kupries/critcl/issues/48","id":99299559,"user":{"login":"andreas-kupries","id":577247,"avatar_url":"https://avatars.githubusercontent.com/u/577247?v=3","gravatar_id":"","url":"https://api.github.com/users/andreas-kupries","html_url":"https://github.com/andreas-kupries","followers_url":"https://api.github.com/users/andreas-kupries/followers","following_url":"https://api.github.com/users/andreas-kupries/following{/other_user}","gists_url":"https://api.github.com/users/andreas-kupries/gists{/gist_id}","starred_url":"https://api.github.com/users/andreas-kupries/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreas-kupries/subscriptions","organizations_url":"https://api.github.com/users/andreas-kupries/orgs","repos_url":"https://api.github.com/users/andreas-kupries/repos","events_url":"https://api.github.com/users/andreas-kupries/events{/privacy}","received_events_url":"https://api.github.com/users/andreas-kupries/received_events","type":"User","site_admin":false},"created_at":"2015-05-06T02:45:03Z","updated_at":"2015-05-06T02:45:03Z","body":"Working - Good.\r\nUsage - This is wholly internal and automatic."}}