#!/usr/bin/tclsh proc Div {a b} { if {$b == 0} { error "Error generated by error" "Info String for error" 401 } else { return [expr $a/$b] } } if {[catch {puts "Result = [Div 10 0]"} errmsg]} { puts "ErrorMsg: $errmsg" puts "ErrorCode: $errorCode" puts "ErrorInfo:\n$errorInfo\n" } if {[catch {puts "Result = [Div 10 2]"} errmsg]} { puts "ErrorMsg: $errmsg" puts "ErrorCode: $errorCode" puts "ErrorInfo:\n$errorInfo\n" }
#!/usr/bin/tclsh namespace eval MyMath { # Create a variable inside the namespace variable myResult namespace export Add } # Create procedures inside the namespace proc MyMath::Add {a b } { return [expr $a + $b] } namespace import MyMath::* puts [Add 10 30] namespace forget MyMath::*
#!/usr/bin/tclsh namespace eval MyMath { # Create a variable inside the namespace variable myResult namespace export Add } # Create procedures inside the namespace proc MyMath::Add {a b } { return [expr $a + $b] } namespace import MyMath::* puts [Add 10 30]
#!/usr/bin/tclsh namespace eval MyMath { # Create a variable inside the namespace variable myResult } namespace eval extendedMath { # Create a variable inside the namespace namespace eval MyMath { # Create a variable inside the namespace variable myResult } } set ::MyMath::myResult "test1" puts $::MyMath::myResult set ::extendedMath::MyMath::myResult "test2" puts $::extendedMath::MyMath::myResult
#!/usr/bin/tclsh 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 + $b] } MyMath::Add 10 23 puts $::MyMath::myResult
#!/usr/bin/tclsh proc add {a {b 100} } { return [expr $a+$b] } puts [add 10 30] puts [add 10]
#!/usr/bin/tclsh set colours [dict create colour1 "black" colour2 "white"] foreach item [dict keys $colours] { set value [dict get $colours $item] puts $value }
#!/usr/bin/tclsh set var {orange blue red green} lassign $var colour1 colour2 puts $colour1 puts $colour2
#!/usr/bin/tclsh set var {orange blue red green} lset var 0 black puts $var
#!/usr/bin/tclsh set var {orange blue red green} puts [lindex $var 1]
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more