前のページ 次のページ 目次

13. Tcl/Tk と ruby/tk との違いは?

 what              Tcl/Tk                 ruby/Tk
 variable          set a 123              a = 123 or a = '123'
  initialization
 re-assignment     set b $a               b = a

 lists/arrays      set a {1 2 fred 7.8}   a = [1, 2, 'fred', 7.8]
 re-assignment     list set b $a          b = a

 associative       set a(Jan) 456.02      a = {'Jan' => 456.02, 'Feb' => 534.96}
  arrays           set a(Feb) 534.96
 re-assignment     foreach i \            b = a
                    [array names a] {
                   set b($i) = $a($i) }

 expressions       set a [expr $b+$c]     a = b + c

 increment         incr i                 i += 1

 declare           proc plus {a b} {      def plus(a, b)
  subroutines       expr $a + $b }            return a + b
                                          end

 variable scope    local default          local default
                   override w/ "global"   

 call              plus 1 2               plus(1,2)
  subroutines                             

 statement sep     newline or at ";"      newline or at ";"

 statement         "\" - newline          none required
  continuation

 verbatim strings  {}                     ''
  e.g.             {a \ lot@ of $stuff}   'a \ lot@ of $stuff'

 escaped strings   ""                     ""
  e.g.             "Who\nWhat\nIdunno"    "Who\nWhat\nIdunno"

 STDOUT            puts "Hello World!"    print "Hello!\n"
                   puts stdout "Hello!"   $stdout.print "Hello World!\n"


前のページ 次のページ 目次