[Shin The Gin] - Wouldn't it be nice for an interative environment to save its complete state into a file and restore it later? How would one do it with Tcl? I know [Tcl] has a lot of introspection capabilities, but do they enable a complete saving of states? [RS]: See [serializing] and [Dumping interpreter state] [NEM]: See also [continuation], depending on what is meant by interpreter state. ''[escargo]'': It sounds like saving and restoring a [Smalltalk] workspace (or also going back a ways, an [APL] workspace). Squeak Smalltalk [http://minnow.cc.gatech.edu/squeak.1] has workspaces. [Shin The Gin] ''escargo:'' Yes, that's what I had in mind. I think of it as a multistep routine. 1. Save all variables 1. Save all arrays 1. Save all procedures 1. Save all images 1. Traverse and save the widget tree Whereas '''save''' here means to write out tcl code, that can be sourced later. In a bigger picture, I dream of a TclTk environment that comes up with a Transcript like [Smalltalk], workspaces with "Do It" and "Print It" in their option menu and some Tools for browsing lists, arrays and text. I wouldn't need a Class Hierarchy Browser, but instead there should be a [Namespace Browser] and a nice File Browser. I've done some investigations last night and made [envsave.tcl]. It's not as complete as the list above, but saves alls globals, procedure and widgets. [George Peter Staplin] You should be able to do essentially what Emacs does, and dump the dynamic portions of the executable image. Basically with an ELF executable you can dump the .data segment to an image file, and then restore it on the next startup. There's a little more involved, but it's definitely possible. [Lars H]: This "Emacs approach" is rather crude though, GPS. Languages with poor [introspection] capabilities have to do it by dumping raw memory (MS Word also comes to mind), but surely Tcl can do better! (OK, sometimes speed is of the essence, but usually it's not.) [RJ] I do this.. only saves variable contents. To save window state, capture widget contents to variables first, then in the restore, insert them. Same with focus, tags, etc. (Global only here. For namespaces, just add another nested level of foreach [[lappend [[namespace children ::]] ::]]) proc save_state {} { uplevel { set fh [open $statefile w] foreach v [info var] { if [array exists $v] { puts $fh "a $v = [array get $v]" } else { puts $fh "v $v = [set $v]" } } close $fh } } package require fileutil # cuz I love this package (obv. you could open/close a file yourself) proc restore_state {} { uplevel { fileutil::foreachLine l $::statefile { if {[lindex $l 1] == "type"} { continue } if {[lindex $l 0] == "a"} { array set [lindex $l 1] [lrange $l 3 end] # puts "setting a [lindex $l 1]" } else { set [lindex $l 1] [lrange $l 3 end] # puts "setting v [lindex $l 1]" } } puts "Done restoring session" } } ---- ''See also:'' * [fileutil] (man page [http://tcllib.sourceforge.net/doc/fileutil.html]) * [envsave.tcl] An attempt to save a running TclTk environment ---- [Category Concept]