我在最近又試著使用 html tidy 的時候發現這個命令列工具在最近幾年改寫以後,其實只是 libtidy 的包裝。所以也許可以透過 Tcl 呼叫 libtidy 來做到相同的事(而不是 exec tidy tool),所以嘗試寫了一個 Tcl extension,看起來基本的功能和選項設定沒問題,所以我把 code 放一份到 github 了。
2021/01/01 更新
能夠設 encoding 似乎會造成問題,目前先移掉,預設編碼使用 utf8,版本升為 v0.2。
我在最近又試著使用 html tidy 的時候發現這個命令列工具在最近幾年改寫以後,其實只是 libtidy 的包裝。所以也許可以透過 Tcl 呼叫 libtidy 來做到相同的事(而不是 exec tidy tool),所以嘗試寫了一個 Tcl extension,看起來基本的功能和選項設定沒問題,所以我把 code 放一份到 github 了。
2021/01/01 更新
能夠設 encoding 似乎會造成問題,目前先移掉,預設編碼使用 utf8,版本升為 v0.2。
Write a script to replace the character ‘e’ with ‘E’ in the string ‘Weekly Challenge’. Also print the number of times the character ‘e’ is found in the string.
#!/usr/bin/env tclsh
set times [regsub -all "e" "Weekly Challenge" "E" result]
puts "Find e $times times"
puts "Output: $result"
使用 Regular Expressions 來做替代字串的任務。
也可以使用 string map 來替代字串,下面是 Replace e with E 的其它寫法:
#!/usr/bin/env tclsh
set str "Weekly Challenge"
set count 0
foreach x [split $str {}] {
if {$x == "e"} {
incr count
}
}
puts "Find e $count times"
set result [string map {e E} $str]
puts "Output: $result"
也可以在計算 e 數目的時候就同時建構字串:
#!/usr/bin/env tclsh
set str "Weekly Challenge"
set count 0
set result {}
foreach x [split $str {}] {
if {$x == "e"} {
incr count
append result "E"
} else {
append result $x
}
}
puts "Find e $count times"
puts "Output: $result"
下面是 Isomorphic Strings 使用 string first 解的結果:
#!/usr/bin/env tclsh
#
# You are given two strings $A and $B.
# Write a script to check if the given strings are Isomorphic.
# Print 1 if they are otherwise 0.
#
proc isIsomorphic {str1 str2} {
set len [string length $str1]
if {$len != [string length $str2]} {
return 0
}
for {set i 0} {$i < $len} {incr i} {
set floc1 [string first [string index $str1 $i] $str1]
set floc2 [string first [string index $str2 $i] $str2]
if {$floc1 != $floc2} {
return 0
}
}
return 1
}
if {$argc == 2} {
set string1 [lindex $argv 0]
set string2 [lindex $argv 1]
} else {
exit
}
puts [isIsomorphic $string1 $string2]
下面是使用 Tcl 試著解 Count Number 的答案:
#!/usr/bin/tclsh
#
# You are given a positive number $N.
# Write a script to count number and display as you read it.
#
# For example,
# Input: $N = 1122234
# Output: 21321314
# as we read "two 1 three 2 one 3 one 4"
#
puts -nonewline "Please input a number: "
flush stdout
gets stdin number
if {$number <= 0} {
puts "Number requires > 0."
exit
}
array set mapping [list 1 one 2 two 3 three 4 four 5 five 6 six 7 seven 8 eight 9 nine]
set last [string index $number 0]
set index 0
set results [list]
lset results $index [list 1 $last]
for {set i 1} {$i < [string length $number]} {incr i} {
set current [string index $number $i]
if {$current == $last} {
set indexlist [lindex $results $index]
set curval [lindex $indexlist 0]
incr curval
set indexlist [list $curval $current]
} else {
incr index
set indexlist [list 1 $current]
}
lset results $index $indexlist
set last $current
}
set answer {}
foreach r $results {
append answer [join $r ""]
}
puts "\nOutput: $answer"
puts -nonewline "as we read \""
set nresults [list]
for {set index 0} {$index < [llength $results]} {incr index} {
set r [lindex $results $index]
set key [lindex $r 0]
set value [lindex $r 1]
lappend nresults "$mapping($key) $value"
}
puts -nonewline [join $nresults " "]
puts "\""
下面是試著使用 Tcl 解 DNA Sequence 問題的解法:
#!/usr/bin/env tclsh
#
# DNA is a long, chainlike molecule which has two strands twisted
# into a double helix. The two strands are made up of simpler molecules
# called nucleotides. Each nucleotide is composed of one of the
# four nitrogen-containing nucleobases cytosine (C), guanine (G),
# adenine (A) and thymine (T).
# Write a script to print nucleobase count in the given DNA sequence.
# Also print the complementary sequence where Thymine (T) on one strand
# is always facing an adenine (A) and vice versa; guanine (G) is always
# facing a cytosine (C) and vice versa.
#
set dna "GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG"
set ccount [llength [regexp -all -inline "C" $dna]]
set gcount [llength [regexp -all -inline "G" $dna]]
set acount [llength [regexp -all -inline "A" $dna]]
set tcount [llength [regexp -all -inline "T" $dna]]
puts "C: $ccount"
puts "G: $gcount"
puts "A: $acount"
puts "T: $tcount"
set complement ""
set length [string length $dna]
for {set i 0} {$i < $length} {incr i} {
set substring [string index $dna $i]
if {[string compare $substring "C"]==0} {
append complement "G"
} elseif {[string compare $substring "G"]==0} {
append complement "C"
} elseif {[string compare $substring "A"]==0} {
append complement "T"
} elseif {[string compare $substring "T"]==0} {
append complement "A"
}
}
puts ""
puts "Complement:"
puts $complement
也可以這樣寫:
#!/usr/bin/env tclsh
#
# DNA is a long, chainlike molecule which has two strands twisted
# into a double helix. The two strands are made up of simpler molecules
# called nucleotides. Each nucleotide is composed of one of the
# four nitrogen-containing nucleobases cytosine (C), guanine (G),
# adenine (A) and thymine (T).
# Write a script to print nucleobase count in the given DNA sequence.
# Also print the complementary sequence where Thymine (T) on one strand
# is always facing an adenine (A) and vice versa; guanine (G) is always
# facing a cytosine (C) and vice versa.
#
set dna "GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG"
set ccount 0
set gcount 0
set acount 0
set tcount 0
set complement ""
set length [string length $dna]
for {set i 0} {$i < $length} {incr i} {
set substring [string index $dna $i]
if {[string compare $substring "C"]==0} {
incr ccount
append complement "G"
} elseif {[string compare $substring "G"]==0} {
incr gcount
append complement "C"
} elseif {[string compare $substring "A"]==0} {
incr acount
append complement "T"
} elseif {[string compare $substring "T"]==0} {
incr tcount
append complement "A"
}
}
puts "C: $ccount"
puts "G: $gcount"
puts "A: $acount"
puts "T: $tcount"
puts ""
puts "Complement:"
puts $complement
如果使用 array 實作,就會是下面的樣子:
#!/usr/bin/env tclsh
#
# DNA is a long, chainlike molecule which has two strands twisted
# into a double helix. The two strands are made up of simpler molecules
# called nucleotides. Each nucleotide is composed of one of the
# four nitrogen-containing nucleobases cytosine (C), guanine (G),
# adenine (A) and thymine (T).
# Write a script to print nucleobase count in the given DNA sequence.
# Also print the complementary sequence where Thymine (T) on one strand
# is always facing an adenine (A) and vice versa; guanine (G) is always
# facing a cytosine (C) and vice versa.
#
set dna "GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG"
set complement ""
array set count {}
set length [string length $dna]
for {set i 0} {$i < $length} {incr i} {
set substring [string index $dna $i]
incr count($substring)
switch $substring {
"C" {
append complement "G"
}
"G" {
append complement "C"
}
"A" {
append complement "T"
}
"T" {
append complement "A"
}
}
}
foreach {key value} [array get count] {
puts "$key: $value"
}
puts ""
puts "Complement:"
puts $complement
You are given a positive integer $N. Write a script to sum GCD of all possible unique pairs between 1 and $N.
找出來最大公因數 (greatest common divisor) 的和。這裡使用輾轉相除法寫一個取得 gcd 值的函式。
#!/usr/bin/tclsh
#
# You are given a positive integer $N.
# Write a script to sum GCD of all possible unique pairs
# between 1 and $N.
#
proc gcd {a b} {
while {$b > 0} {
set r [::tcl::mathop::% $a $b]
set a $b
set b $r
}
return $a
}
puts -nonewline "Input: "
flush stdout
gets stdin number
if {$number <= 1} {
puts "Number requires > 1."
exit
}
set sum 0
for {set i 1} {$i <= $number} {incr i} {
for {set j [::tcl::mathop::+ $i 1]} {$j <= $number} {incr j} {
set value [gcd $i $j]
set sum [expr $sum + $value]
}
}
puts "Output: $sum"
也可以使用 tcllib math::numtheory 套件中的 gcd 函式取得最大公因數的值再加總起來。
#!/usr/bin/tclsh
#
# You are given a positive integer $N.
# Write a script to sum GCD of all possible unique pairs
# between 1 and $N.
#
package require math::numtheory
puts -nonewline "Input: "
flush stdout
gets stdin number
if {$number <= 1} {
puts "Number requires > 1."
exit
}
set sum 0
for {set i 1} {$i <= $number} {incr i} {
for {set j [::tcl::mathop::+ $i 1]} {$j <= $number} {incr j} {
set value [math::numtheory::gcd $i $j]
set sum [expr $sum + $value]
}
}
puts "Output: $sum"
You are given an array of positive integers @N. Write a script to return an array @M where $M[i] is the product of all elements of @N except the index $N[i].
#!/usr/bin/env tclsh
#
# You are given an array of positive integers @N.
# Write a script to return an array @M where $M[i] is the product
# of all elements of @N except the index $N[i].
#
if {$argc <= 1} {
puts "Please input a list."
exit
}
set mylist $argv
set p [tcl::mathop::* {*}$mylist]
set result [list]
foreach element $mylist {lappend result [tcl::mathop::/ $p $element]}
puts $result
使用 lmap 來尋訪串列中的每一個元素來解題,可以改寫如下:
#!/usr/bin/env tclsh
#
# You are given an array of positive integers @N.
# Write a script to return an array @M where $M[i] is the product
# of all elements of @N except the index $N[i].
#
if {$argc <= 1} {
puts "Please input a list."
exit
}
set mylist $argv
set p [tcl::mathop::* {*}$mylist]
set result [lmap element $mylist {tcl::mathop::/ $p $element}]
puts $result
試著使用 Tcl 解 Longest Consecutive Sequences 問題。
#!/usr/bin/env tclsh
#
# You are given an unsorted array of integers.
# Write a script to find the longest consecutive sequence.
# Print 0 if none sequence found.
#
if {$argc <= 1} {
puts "Please input a list."
exit
}
# To compare two list's length
proc mysortproc {x y} {
set len1 [llength $x]
set len2 [llength $y]
if {$len1 > $len2} {
return -1
} elseif {$len1 < $len2} {
return 1
} else {
return 0
}
}
set len [llength $argv]
set mylist [lsort -integer $argv]
set last [lindex $mylist 0]
set index 0
set results [list]
lset results $index [list $last]
for {set count 1} {$count < $len} {incr count} {
set current [lindex $mylist $count]
if {$current != [expr $last + 1]} {
incr index
}
set indexlist [lindex $results $index]
set indexlist [lappend indexlist $current]
lset results $index $indexlist
set last $current
}
# Sort our results by using sublists's length
set results [lsort -command mysortproc $results]
if {[llength [lindex $results 0]] > 1} {
puts [lindex $results 0]
} else {
puts 0
}
如果要使用 anonymous function,則可以改寫如下:
#!/usr/bin/env tclsh
#
# You are given an unsorted array of integers.
# Write a script to find the longest consecutive sequence.
# Print 0 if none sequence found.
#
if {$argc <= 1} {
puts "Please input a list."
exit
}
set len [llength $argv]
set mylist [lsort -integer $argv]
set last [lindex $mylist 0]
set index 0
set results [list]
lset results $index [list $last]
for {set count 1} {$count < $len} {incr count} {
set current [lindex $mylist $count]
if {$current != [expr $last + 1]} {
incr index
}
set indexlist [lindex $results $index]
set indexlist [lappend indexlist $current]
lset results $index $indexlist
set last $current
}
# Sort our results by using sublists's length
set results [lsort -command {apply {{x y} {
set len1 [llength $x]
set len2 [llength $y]
if {$len1 > $len2} {
return -1
} elseif {$len1 < $len2} {
return 1
} else {
return 0
}
}}} $results]
if {[llength [lindex $results 0]] > 1} {
puts [lindex $results 0]
} else {
puts 0
}
也可以使用其它的方式,直接記錄 Longest Consecutive Sequences 的排序,如下所示:
#!/usr/bin/env tclsh
#
# You are given an unsorted array of integers.
# Write a script to find the longest consecutive sequence.
# Print 0 if none sequence found.
#
if {$argc <= 1} {
puts "Please input a list."
exit
}
set len [llength $argv]
set mylist [lsort -integer $argv]
set last [lindex $mylist 0]
set index 0
set curresult [list $last]
set maxresult [list $last]
set curval 1
set maxval 1
for {set count 1} {$count < $len} {incr count} {
set current [lindex $mylist $count]
if {$current == [expr $last + 1]} {
lappend curresult $current
incr curval
if {$curval > $maxval} {
set maxresult $curresult
set maxval $curval
}
} else {
set curval 1
set curresult [list $current]
}
set last $current
}
if {$maxval > 1} {
puts $maxresult
} else {
puts "0"
}
使用者在命令列輸入一個字串,使用 Memfrob 編碼(字串的每個字元 XOR 42)以後輸出結果:
#!/usr/bin/env tclsh
proc memfrob {origString} {
set length [string length $origString]
set resultString ""
for {set count 0} {$count < $length} {incr count} {
set result [string index $origString $count]
set result [binary format c [expr [scan $result %c] ^ 42]]
append resultString $result
}
return $resultString
}
if {$argc >= 1} {
set countString [lindex $argv 0]
} elseif {$argc == 0} {
puts "Please input a string"
exit
}
puts "String: $countString"
puts "Result: [memfrob $countString]"
Web Services for Tcl (tclws) 最近釋出了 3.0.0 版,加入了 -hostProtocol 選項,同時將 Tcl 版本的要求從 8.4 升到 8.6。
在最近一個月 Web Services for Tcl 有比較多的小更新版本,從 2.7.0, 2.7.1 到 3.0.0 這幾個版本的更新。
只是用來測試 string reverse 的 script,用來反轉使用者輸入的數字的程式:
#!/usr/bin/tclsh
puts -nonewline "Please input a number: "
flush stdout
gets stdin number
set positive 1
if {$number < 0} {
set positive 0
set number [expr $number * -1]
}
set number [string reverse $number]
if {$positive > 0} {
puts $number
} else {
set number [expr $number * -1]
puts $number
}
最近我在試著使用 zsh 作為平常使用的 shell(還在測試中),所以試寫了一個會移除 .*history* 檔案的 zsh shell script:
#!/usr/bin/env zsh
pushd $(pwd)
cd $HOME
for file in $(ls .*history*); do
rm $file && touch $file
done
popd
那麼如果用 Tcl 寫呢?程式應該會是這個樣子:
#!/usr/bin/env tclsh
set currdir [pwd]
cd $::env(HOME)
set files [glob -nocomplain -type f .*history*]
foreach filename $files {
file delete -force $filename
if {[file exists $filename]==0} {
close [open $filename a]
}
}
cd $currdir
A pandigital number, like 4730825961, is a ten-digit number in which each digit from zero to nine appears exactly once. A square number, like 25² = 625, is a number with an integral square root. Your task is to write a program that finds all of the pandigital square numbers.
下面是嘗試的結果:
#!/usr/bin/env tclsh
set digital [list "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"]
proc is_pandigital {n} {
set length [string length $n]
if {$length != 10 } {
return 0
}
foreach mychar $::digital {
if {[string first $mychar $n] == -1} {
return 0
}
}
return 1
}
set minvalue [expr int(floor(sqrt(1023456789)))]
set maxvalue [expr int(floor(sqrt(9876543210)))]
for {set n $minvalue} {$n <= $maxvalue} {incr n} {
set num [expr $n * $n]
if {[is_pandigital $num]==1} {
puts $num
}
}
tksvg 釋出新的版本 v0.4。
要注意的是,如果是使用 source code 自己編譯,需要更新 Makefile.in 才能夠正確安裝,下面就是 github 上的修改方式:
INSTALL = @INSTALL@
-INSTALL_FLAGS = @INSTALL_FLAGS@
-INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(INSTALL_FLAGS)
-INSTALL_LIBRARY = @INSTALL_PROGRAM@ $(INSTALL_FLAGS)
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_LIBRARY = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
#!/usr/bin/env tclsh
proc find {n} {
set i 0
set a 0
if {$n <= 0} {
return 0;
}
while {$i < $n} {
incr a
if {[expr ($a%3)==2 && ($a%5)==3 && ($a%7)==2]==1} {
incr i
}
}
return $a
}
for {set num 1} {$num <= 10} {incr num} {
puts "The $num answer is [find $num]."
}
#!/usr/bin/env tclsh
#
# The concatenation of the first four integers, written in binary, is 11011100;
# that is, 1 followed by 10 followed by 11 followed by 100. That concatenated
# number resolves to 220. A similar process can convert the concatenation of
# the first n binary numbers to a normal decimal number.
#
proc bitcat {number} {
# Convert decimal to binary and collect the result
set result ""
for {set i 1} {$i <= $number} {incr i} {
append result [format %llb $i]
}
return $result
}
puts -nonewline "Please input a number: "
flush stdout
gets stdin number
if {$number <= 0} {
puts "Number requires > 0."
exit
}
puts [expr (0b[bitcat $number]) % ((10 ** 9) + 7)]
#!/usr/bin/env tclsh
#
# The concatenation of the first four integers, written in binary, is 11011100;
# that is, 1 followed by 10 followed by 11 followed by 100. That concatenated
# number resolves to 220. A similar process can convert the concatenation of
# the first n binary numbers to a normal decimal number.
#
proc bitcat {result index} {
for {set counter $index} {$counter > 0} {set counter [::tcl::mathop::>> $counter 1]} {
set result [::tcl::mathop::<< $result 1]
}
return [::tcl::mathop::| $result $index]
}
proc solution {number} {
set result 0
for {set index 1} {$index <= $number} {incr index} {
set result [bitcat $result $index]
}
return [expr $result % ((10 ** 9) + 7)]
}
puts -nonewline "Please input a number: "
flush stdout
gets stdin number
if {$number <= 0} {
puts "Number requires > 0."
exit
}
puts [solution $number]
#!/usr/bin/env tclsh
#
# Trailing Zero-Bits
# Given a positive integer, count the number of trailing zero-bits in its binary
# representation. For instance, 18 = 10010, so it has 1 trailing zero-bit,
# and 48 = 110000, so it has 4 trailing zero-bits.
#
puts -nonewline "Please input a number: "
flush stdout
gets stdin number
if {$number <= 0} {
puts "Number requires > 0."
exit
}
set trailing {{number} {
set index 0
while {[::tcl::mathop::& $number 1]!=1} {
incr index
set number [::tcl::mathop::>> $number 1]
}
return $index
}}
set count [apply $trailing $number]
puts $count
#!/usr/bin/tclsh
#
# Hidden Squares:
# A number n may have squares hidden among its digits. For instance,
# in the number 1625649, the consecutive digits 1, 4, 9, 16, 25, 49,
# 64, 256 and 625 are all squares.
#
namespace path {::tcl::mathop ::tcl::mathfunc}
puts -nonewline "Please input a number: "
flush stdout
gets stdin number
if {$number <= 0} {
puts "Number requires > 0."
exit
}
set max [int [sqrt $number]]
for {set i 1} {$i <= $max} {incr i} {
set n [* $i $i]
if {[string first $n $number] >= 0} {
puts -nonewline "$n "
}
}
puts ""
#!/usr/bin/tclsh
#
# Given a length-n list like (a b c d e), the rotations of the list are
# the n lists (a b c d e), (b c d e a), (c d e a b), (d e a b c), and (e a b c d),
# in any order.
#
if {$argc == 0} {
puts "Please input a string"
exit
}
set len [llength $argv]
set rorateList $argv
for {set index 0} {$index < $len} {incr index} {
puts $rorateList
set first [lindex $rorateList 0]
set rorateList2 [lrange $rorateList 1 [expr $len - 1]]
lappend rorateList2 $first
set rorateList $rorateList2
}
#!/usr/bin/env tclsh
#
# Calculates the Harmonic series.
# h(n) = 1 + 1/2 + 1/3 + … + 1/n
#
if {$argc >= 1} {
set N [lindex $argv 0]
} elseif {$argc == 0} {
puts "Please input a number."
exit
}
if {[string is integer $N]==0} {
puts "It is not a number."
exit
}
set h 0.0
for {set count $N} {$count >= 1} {incr count -1} {
set h [expr $h + 1.0 / $count]
}
puts [format "%5E" $h]
#!/usr/bin/env tclsh
#
# Calculates the Harmonic series.
# h(n) = 1 + 1/2 + 1/3 + … + 1/n
#
if {$argc >= 1} {
set N [lindex $argv 0]
} elseif {$argc == 0} {
puts "Please input a number."
exit
}
if {[string is integer $N]==0} {
puts "It is not a number."
exit
}
set h 0.0
set I 1
while {$I <= $N} {
set h [expr $h + 1.0 / $I]
incr I
}
puts [format "%5E" $h]
set mylist [list 2 4 6 8 10]
lindex $mylist 1
這樣就會得到 4 這個值。
#!/usr/bin/tclsh
proc divmod {C N} {
set answer [list]
if {($C <= 0) || ($N <= 0) || ($C < $N)} {
return $answer
}
set element [expr $C / $N]
set remainder [expr $C % $N]
for {set count 0} {$count < $N} {incr count} {
lappend answer $element
}
if {$remainder != 0} {
for {set count 0} {$count < $remainder} {incr count} {
set myvalue [lindex $answer $count]
incr myvalue 1
lset answer $count $myvalue
}
}
return $answer
}
puts -nonewline "Please input a number C: "
flush stdout
gets stdin C
puts -nonewline "Please input a number N: "
flush stdout
gets stdin N
set myanswer [divmod $C $N]
puts "The answer list: $myanswer"
if {$argc >= 1} {
set n [lindex $argv 0]
} elseif {$argc == 0} {
puts "Please input a number."
exit
}
if {[string is integer $n]==0} {
puts "It is not a number."
exit
}
switch $n {
{1} {puts "1"}
{2} {puts "121"}
{3} {puts "12321"}
{4} {puts "1234321"}
{5} {puts "123454321"}
{6} {puts "12345654321"}
{7} {puts "1234567654321"}
{8} {puts "123456787654321"}
{9} {puts "12345678987654321"}
default {puts "Please input 0 < n < 10"}
}
if {$argc >= 1} {
set n [lindex $argv 0]
} elseif {$argc == 0} {
puts "Please input a number."
exit
}
if {[string is integer $n]==0} {
puts "It is not a number."
exit
}
if {$n < 1 || $n > 9} {
puts "Please input 0 < n < 10"
exit
}
set positive 1
set count 0
while {1} {
if {$positive == 1} {
incr count
puts -nonewline $count
if {$count == $n} {
set positive 0
continue
}
} else {
incr count -1
if {$count > 0} {
puts -nonewline $count
} else {
break
}
}
}
puts ""
#!/usr/bin/env tclsh
if {$argc >= 1} {
set countString [lindex $argv 0]
} elseif {$argc == 0} {
puts "Please input a string"
exit
}
package require sha256
puts "String: $countString"
puts "Result: [string toupper [sha2::sha256 -hex $countString]]"
#!/usr/bin/env tclsh
if {$argc >= 1} {
set countString [lindex $argv 0]
} elseif {$argc == 0} {
puts "Please input a string"
exit
}
package require md5
puts "String: $countString"
puts "Result: [md5::md5 -hex $countString]"
#!/usr/bin/env tclsh
foreach filename [glob -nocomplain -type f *] {
puts "$filename: [file size $filename] bytes"
}
Overview ======== 5 new packages in 5 modules 11 changed packages in 9 modules 2 internally changed packages in 1 modules 47 unchanged packages in 19 modules 79 packages, total in 31 modules, total New in tklib 0.7 ================ Module Package New Version Comments --------------------- --------------------- ------------- ---------- canvas canvas::gradient 0.2 notifywindow notifywindow 1.0 persistentSelection persistentSelection 1.0b1 scrollutil scrollutil::common 1.5 widgetPlus widgetPlus 1.0b2 --------------------- --------------------- ------------- ---------- Changes from tklib 0.6 to 0.7 ============================= tklib 0.6 tklib 0.7 Module Package Old Version New Version Comments --------------- -------------------- ------------- ------------- ---------------- controlwidget rdial 0.3 0.7 D EF EX crosshair crosshair 1.1 1.2 B EF EX datefield datefield 0.2 0.3 D EF mentry mentry::common 3.6 3.10 B D EF I plotchart Plotchart 2.1.0 2.4.1 B D EF I --------------- -------------------- ------------- ------------- ---------------- tablelist tablelist::common 5.7 API B D EF I P tablelist::common 6.8 API B D EF I P --------------- -------------------- ------------- ------------- ---------------- tooltip tooltip 1.4.4 1.4.6 B D EF --------------- -------------------- ------------- ------------- ---------------- wcb Wcb 3.4 3.6 B D EF I P wcb 3.4 3.6 B D EF I P --------------- -------------------- ------------- ------------- ---------------- widgetl widget::listentry 0.1.1 0.1.2 D I widget::listsimple 0.1.1 0.1.2 D I --------------- -------------------- ------------- ------------- ---------------- Invisible changes (documentation, testsuites) ============================================= tklib 0.6 tklib 0.7 Module Package Old Version New Version Comments --------------- --------------- ------------- ------------- ---------- controlwidget controlwidget 0.1 0.1 D meter 1.0 1.0 EX --------------- --------------- ------------- ------------- ----------
#!/usr/bin/env tclsh
proc rand_range {min max} {
return [expr int(rand()*($max-$min+1)) + $min]
}
set answer [rand_range 1 1000]
while {1} {
puts -nonewline "Please input a number to guess (1-1000): "
flush stdout
gets stdin guess
if {$guess == $answer} {
break;
} else {
if {$guess < $answer} {
puts "Please guess more higher"
} else {
puts "Please guess more lower"
}
}
}