Version 86 of Robert Hicks

Updated 2015-09-04 18:52:16 by RLH

Also known as RLH

Email

set email [string map {at @ x . ext com} rlhicksatwehicksxext]

LinkedIn

My Public Profile

To do list

Books I need to get

  • Tcl and Tk Programming for the Absolute Beginner
  • Tcl and the Tk Toolkit
  • Tcl 8.5 Network Programming
  • Tcl and Tk 8 Programming Cookbook
  • incr Tcl from the Ground Up

Things I like

  • I love the Tcl community
  • I like that Tcl is different from other dynamic languages syntax wise
# futils.tcl --
#
#   This package provides some extra file utilities that are not in the core or
#   in tcllib.
#

package provide futils 1.0

#---------------------------------------------
# Create the namespace
#---------------------------------------------
namspace eval ::futils {
    # export the commands
    namespace export with
}

# ::futils::with --
#
#       This proc ensures that files get closed even when errors happen. It is
#       inspired by the Python language with function.
#
# Arguments:
#       file    file to open
#
# Examples:
#       ::with [open foo.txt w] as file { 
#           puts $file "Hello!" 
#       }
#
#       ::with [open foo.txt r] as file {
#           set data [read $file]
#           puts $data
#       }
#
proc ::futils::with {} {
    uplevel 1 [list set $name $file]
    
    if [catch {uplevel 1 [list eval $block]}] result {
        puts stderr "Warning: $result"
    }
    uplevel 1 [list close $file]
}