Copyrights©2009, All rights Reserved

Disclaimer

Home | Free Books Center | Members | MM Guru | Quotes Diary | Contact us | Blog | Sign In | Sign Up

GALLERY SERVICES FORUM Home ABOUT US

 Education Made Easy

TCL: "Tool Command Language

+++++++++QnA++++++++++


1) What is the command to print a line of text?

  A) puts

  B) printf

  C) print


2) What may words be grouped with?

  A) Curly brackets -- {}

  B) Single Quotes -- ''

  C) Curly brackets or double quotes -- {} or ""


3) What character starts a comment?

  A) The semicolon -- ;

  B) The asterisk -- *

  C) The number sign -- #

  D) A smiley  :-)


4) You must declare the type of a variable in Tcl

  A) True

  B) False


5) The "set" command creates a variable and assigns it a value

  A) True

  B) False


6) The "puts" command will:

  A) put a value into a variable.

  B) put a variable into memory

  C) print a string to the standard output.


7) What will this script print:

set x "test"

puts x

  A) test

  B) x

  C) test x


8) What is the final value of the variable "a":

set a 1

set a "two"


  A) two

  B) 1

  C) generates an error


9) The dollarsign in "$i" means:

  A) use the value of the variable "i".

  B) that "i" is an integer variable.

  C) that "i" is a string variable.


10) What will this script output?

set i 100.00

puts "\$$i"

  A) a syntax error.

  B) $100.00

  C) $i


11) What will this script output:

set i 10

set j "The value of i is"

puts "$j $i"

  A) "$i $j"

  B) "i j"

  C) The value of i is 10


12) A double quote means

  A) group a set of words and variables into a single unit.

  B) evaluate a set of numbers and symbols mathematically.

  C) there are no variables in a set of words.


13) The primary difference between quote (") and curly braces ({}) is

  A) quotes allow special characters to be substituted and braces do not.

  B) quotes group strings and curly braces group lists.

  C) quotes can only be used for alphabetic characters, braces for numbers.


14) What will this script output?

set i 100.00

puts {\$$i}

  A) $100.00

  B) syntax error

  C) \$$i


15) What will this script output:

set x {I like "quotes"}

puts $x

  A) I like quotes

  B) I like "quotes"  //

  C) {I like "quotes"}


16) What will this script output:

set x "I like "quotes""

puts $x

  A) error - extra quotes //

  B) I like "quotes"

  C) I like quotes


17) What will this script output:

set x {I like {braces}}

puts $x

  A) error - nested braces

  B) I like {braces}//

  C) I like braces


18) Square brackets will group a set of words

  A) and allow substitutions.

  B) disable any special character processing.

  C) evaluate those words as a Tcl command.


18) What will be the value of "y" after this command is evaluated:

set y [set x 33]

  A) 33   //

  B) x

  C) [set x 33]


19) What will be the value of "y" after this command is evaluated:

set y {[set x 33]}

  A) 33

  B) x

  C) [set x 33]


20) Which command will assign the same value to "x" and "y"

  A) set x 33; set x $y

  B) set y [set x 33]

  C) set x,y 33


21) The "expr" command will

  A) evaluate an expression arithmetically.

  B) evaluate a Tcl expression.

  C) convert a boolean expression to English.


22) The "expr" command

  A) only works with integers.

  B) includes trigonometric and exponential functions.

  C) can parse words like "one" and "deux" into numbers.


23) What will be the value of x after this script is evaluated:

set x {expr [2+2]}

  A) no output - syntax error.

  B) 4

  C) {expr [2+2]}


24) Which command will assign the value 4 to the variable "x":

  A) set x [expr 2+2]

  B) set x "expr 2+2"

  C) set x {expr 2+2}


25) What will be the result of x after this script is evaluated:

set x 2

set x [expr $x+$x]

  A) 4

  B) 6

  C) 8


26) The "switch" command will

  A) switch the contents of two variables.

  B) evaluate the script associated with a value that matches a pattern.

  C) switch a variable between two values.


27) What will this script output when it is evaluated:

set x 1

switch $x {

  0 {puts a}

  1 {puts b}

  2 {puts c}

}

  A) "b"

  B) "1"

  C) No output - syntax error.


28) When the switch command finds a pattern that matches a test value

  A) it evaluates the script associated with that pattern.

  B) it evaluates all scripts following that pattern.

  C) it evaluates all scripts except the script associated with that pattern.


29) A "switch" command

  A) can have a "default" pattern to match if no other pattern matches.

  B) only use character strings for patterns.

  C) only use numeric strings for patterns.


30) The "if" command will

  A) evaluate an associated script if the test is false.

  B) evaluate an associated script if the test is true.

  C) select one of several options.


31) An "if" script can have

  A) only one "elseif" associated with it.

  B) multiple "else" statements associated with it.

  C) multiple "elseif" statements associated with it.


32) When an "if" test is false and there is no "else" or "elseif"

  A) the interpreter generates an error condition.

  B) the interpreter continues to the next line.

  C) the user is asked for input.


33) What will this script output when it is evaluated?

set x 3

if {$x > 4} {

  puts "$x is bigger than 4"

}

  A) 3 is bigger than 4

  B) nothing

  C) 3 is smaller than 4


34) What will this script output when it is evaluated?

set x 3; set y 4

if {($x+$y) == 7} {

  puts "lucky 7"

}

  A) lucky 7

  B) nothing

  C) syntax error


35) The "while" command

  A) will loop N times if the initial test is true.

  B) will loop as long as a test fails.

  C) will loop until a test fails.


36) What will this script output when it is evaluated:

set x 1

while {$x < 10} {

  puts "X: $x"

  set y [expr $x + 1]

}

  A) an infinite number of "X: 1" lines.

  B) lines from "X: 1" to "X: 9"

  C) lines from "X: 1" to "X: 10"


37) You should use a looping construct

  A) instead of repeating identical commands in a script.

  B) to reduce the number of lines the interpreter needs to process.

  C) whenever a script is over 100 lines long.


38) How many times with this loop iterate:

set x 0

while {$x < 10} {

  puts $x

  set x [expr $x+1]

}

  A) 9 times

  B) 10 times

  C) 11 times


39) To perform the same operation for values from 1 to 10

  A) use the foreach command.

  B) use the for command.

  C) use the do-while command.


40) How many times is the "start" script in a for loop evaluated:

  A) Once, before the body is evaluated.

  B) Once, after the first pass through the body.

  C) Every time the body is evaluated.


41) What will be the value of "total" after this code runs:


for {set total 1; set count 1} {$count < 3} {incr count} {

  set total [expr {$total + $total}]

}


  A) 1

  B) 2

  C) 4


42) The "test" script is evaluated:

  A) Once when the script starts

  B) On each pass, before evaluating the body

  C) On each pass, after evaluating the body


43) The "while" command

  A) is best when you want to loop until a condition occurs.

  B) is best when you want to loop on each element in a list.

  C) is best when you want to loop for each value between two integers.


44) Internal commands (like for) are handled differently from user defined commands.

  A) True

  B) False


45) The "proc" command

  A) Defines a procedure interface

  B) Defines a new procedure

  C) Is a pre-processor macro

  D) Defines and executes a procedure


46) You should consider using a procedure if a set of code is

  A) copied more than once

  B) copied more than twice

  C) copied more than three times


47) Using procedures

  A) Makes code more readable

  B) Makes code more re-usable

  C) Simplifies debugging

  D) All of the above


48) The "return" command will

  A) Return to the original code without evaluating the procedure

  B) Return a value from a procedure

  C) Insert a carriage return into an output stream


49) What is the default value for "b" in this procedure:

proc demo {a {b 2} {c 3} } {...}

  A) 3

  B) 2

  C) None


50) How many arguments does this procedure require:

proc demo {args one two} {...}

  A) 3

  B) any number

  C) 4


51) What will this procedure do:

proc foo {args} {

  set t 0

  foreach n $args {

    incr t $n

  }

  return $t

}

  A) Count the number of elements in a list.

  B) Return the total of a set of floating point numbers.

  C) Return the total of a set of integers.


52) To create a procedure that may accept two argument,

and has a default value of "2" if only one argument is defined,

which command is correct:

  A) proc {b 2 a} {...}

  B) proc {a {b 2}} {...}

  C) proc {a b 2} {...}

  D) proc {{a required} {b default 2}} {...}


53) When you call a command like this:

set i 1

command $i

  A) It is "call by name"

  B) It is a syntax error

  C) It is "call by value"


54) If you call a command like this:

set i 1

command i


  A) It is "call by name"

  B) It is a syntax error

  C) It is "call by value"


55) The upvar command will


  A) Map a variable from the calling scope into the local procedure scope.

  B) Map a variable from the local scope into the calling scope.

  C) Copy the value of a variable from the calling scope to the local scope.


56) What will be the value of i after this code is evaluated:


proc inc {nm} {

  upvar $nm x

  incr x

}

set i 2

inc i

  A) 4

  B) 3

  C) 2


57) What will be the value of i after this code is evaluated:


proc inc {nm} {

  incr nm

}

set i 2

inc $i

  A) 3

  B) 2

  C) 4


58) The "global" command

  A) maps a variable from the global scope into the procedure scope and gives it a unique name.

  B) maps a variable from the global scope into the procedure scope retaining the original name.

  C) makes a global-scope variable automatically map into all procedures.


59) Which of these commands assigns a list to the variable "lst"

  A) set lst "a b c"

  B) set lst {a b c}

  C) set lst [list a b c]

  D) All of the above


60) What will this command return:

llength {this {is a} list}

  A) 1

  B) 2

  C) 3

  D) 4


61) Which command will return the first element of a list

  A) lindex $lst 0

  B) lindex $lst 1

  C) lindex $lst first


62) What will be the contents of lst after this command:

set lst [split "commas,can,delimit elements" ,]

  A) commas can delimit elements

  B) commas can {delimit elements}

  C) commas can delimit,elements


63) The quickest way to iterate through the elements of a list is to

  A) use the "foreach" command.

  B) use the "for" and "lindex" commands

  C) use the "while" command


64) What is the result of

concat a {b c} d

  A) a {b c} d

  B) {a {b c} d}

  C) a b c d


65) What are the contents of "lst" after this script is evaluated:

set lst {}

lappend lst a {b c} d

  A)  a b c d

  B) a {b c} d

  C) {a b c d}


66) What are the contents of "lst" after this script is evaluated:

set lst {a {b c} d}

set lst [linsert lst 1 e]

  A) a b c d e

  B) a e {b c} d

  C) lst e


67) What are the contents of "lst" after this script is evaluated:

set lst {a {b c} d}

set lst [lreplace $lst 1 1 e]

  A) a {b c} e

  B) a e d

  C) e {b c} d


68) What are the contents of "lst" after this script is evaluated:

set lst {a {b c} d}

set lst [lreplace $lst 1 1]

  A) a d

  B) {b c} d

  C) a {b c} d


69) What is returned by this code:

set lst {a b c d}

lsearch $lst a

  A) 0

  B) 1

  C) 2


70) Which code snippet will sort the list {a b c A B C} into {A a B b C c}?

  A) lsort {a b c A B C}

  B) lsort -dictionary {a b c A B C}

  C) lsort -decreasing {a b c A B C}


71) What will be the contents of lst after this script is evaluated:

set lst {1 2 3 4 5}

set lst [lrange $lst 1 3]

  A) 1 2 3

  B) 2 3 4 5

  C) 2 3 4


72) Which command will return 1?

  A) lsearch {aa bb cc dd} b

  B) lsearch {aa bb cc dd} b*

  C) lsearch {aa bb cc dd} [a-b]

  D) lsearch {aa bb cc dd} b??


73) What will this command return:

string length {12 34}

  A) 3

  B) 4

  C) 5


74) Which command will return "2"

  A) string index "12 34" 1

  B) string index "12 34" 0

  C) string index "12 34" 2


75) What will this command return:

string range "1234567" 1 5

  A) 12345

  B) 23456

  C) 123456


76) What is the index of the first character in a string?

  A) 0

  B) 1

  C) begin


77) Which script will return "5"

  A) string index 12345 5

  B) string index 12345 end

  C) string index 12345 last


78) Which script returns true?

  A) string compare "abc" "abc"

  B) string match "abc" "a*"

  C) string equal "abc" "abc"


79) Which script returns 2?

  A) string first 3 "123"

  B) string first "123" 2

  C) string first 2 "1234"


80) When might you use "string compare".

  A) When checking strings for equality.

  B) When sorting a set of strings.

  C) All of the above.


81) Which script will return 4

  A) string first 4 "0123401234"

  B) string last 4 "0123401234"

  C) string range "0123401234" 3 3


82) Which script will return true:

  A) string match "abc" "a*"

  B) string match "a*" "abc"

  C) string equal "a*" "abc"

  D) string match "a?" "abc"


83) What will this script return:

set st "this is a test"

string range $st [string wordstart $st 5] [string wordend $st 5]

  A) " is "

  B) "is"

  C) "is "

  D) " is"


84) The %6.2f option to format will print

  A) a six digit floating point number with 2 digits to the right of the decimal

  B) a five digit floating point number with 2 digits to the right of the decimal

  C) at least 6 spaces for a number 3 (or more) to the left of the decimal and 2 to the right


85) What value will end up in str when this script is evaluated:

set str "abcabcabc"

set str [string trim ca]

  A) bcabcab

  B) bbb

  C) bcabcb


86) Which command will strip trailing spaces, but leave leading spaces.

  A) string trimleft

  B) string trimright

  C) string trim


87) To capitalize a word use:

  A) string toupper

  B) string totitle

  C) string capitalize


88) The "glob" rules use a "*" to match any number of any character.

How do you identify any number of any characters with regexp?

  A) *

  B) +

  C) .*

  D) ?


89) The glob rules use a ? to match a single character.

How do you identify a single characters with regexp?

  A) .

  B) *

  C) ?

  D) +


90) Which regular expression would identify all letters between "a" and "m"?

  A) [am]

  B) [a-m]

  C) [am]*

  D) [a-m]*


91) Which string would match the regular expression A+B+

  A) AAaaBBbb

  B) CCAABBDD

  C) BBB

  D) BBAA


92) What is the value of m2 after this code is evaluated?

set l {Regular expressions are useful and powerful}

regexp {(e.*s)} $l m1 m2

  A) egular expressions

  B) e us

  C) egular expressions are us

  D) NO MATCH


93) What will end up in the variables b and c

set str "better tests choose correctly"

regexp {(b.*)(c.*)} $str a b c

  A) b: "better tests choose corre" c: "ctly"

  B) b: "better tests " c: "choose correctly"

  C) b: "better tests choose " c: "correctly"


94) Which test would assign "choose correctly" to variable c?

set str "better tests choose correctly"

regexp $test $str a b c

  A) set test {(b.*)(c.*)}

  B) set test {(b[^c]*)(c.*)}

  C) set test {(b.*)(co.*)}


95) What will be the contents of "findings" after this script is evaluated:

set str "better tests choose correctly"

foreach test [list {b[^ ]*} {c[^ ]*} {d[^ ]*} ] {

  if {[regexp $test $str word]} {

    lappend findings $word

  }

}

  A) better choose

  B) b c

  C) better choose correctly


96) Will the following script produce the same results?

set str "better tests choose correctly"

foreach l {a b c d} {

  if {[regexp "$l\[^ ]*" $str word]} {

    lappend findings $word

  }

}

  A) No

  B) Yes


97) Will the following script produce the same results as the previous script?

(The difference is quoting around the test)

set str "better tests choose correctly"

foreach l {a b c d} {

  if {[regexp {$l\[^ ]*} $str word]} {

    lappend findings $word

  }

}

  A) No

  B) Yes



98) If you use a quoted string, instead of a curly-braced string as a

test with regexp

  A) you must backslash escape parentheses and square braces

  B) you must backslash escape square braces

  C) you must backslash escape dollar signs in front of variable names


99) What will this script do:

set french {amusant est tres }

set english {fun is great}

set str "Tcl is great fun"

foreach f $french e $english {

  regsub $e $str $f str

}

  A) Convert "Tcl is great fun" to "amusant est tres Tcl"

  B) Nothing

  C) Translate "Tcl is great fun" to "Tcl est tres amusant"


100) You can tell if a variable is an array because

  A) It will have an index in parentheses.

  B) It will have an index in square brackets.

  C) It will have an index in curly braces.


101) Tcl arrays

  A) Must be indexed with an integer.

  B) Must use an integer greater than 0 as index.

  C) Can use any character or set of characters as the index.


102) The "array exists" command will

  A) return True if the name is an array or a procedure that returns an array.

  B) only return True if a variable is an array.

  C) return false if an array has only one index.


103) The "array names" command

  A) returns a list of unused names that can be used with an array.

  B) returns a list of array indices that match an optional pattern.

  C) returns a list of array indices who's associated values match a pattern.


104) The "array set" command

  A) Returns the intersection of two arrays.

  B) Assigns values to an array where indices match a pattern

  C) Assigns an arrays indices and associated values.


105) What does this script do:

array set xx {a 1 b 2 c 3}

array set yy [array get xx]

  A) Assigns the same values to xx and yy.

  B) Assign "xx" to yy.

  C) set xx(a) to "1" and yy(1) to "a".


106) The "array size" command will

  A) return the largest value in an array.

  B) return the largest index in an array.

  C) return the number of elements in an array.


107) An associative array is useful

  A) to collect related data under a single name.

  B) to simplify your code and reduce potential bugs.

  C) when you don't know the data set your code will work with until run time.

  D) all of the above.

  E) none of the above.


108) Which script will display only books written by Mark Twain:

array set books {

    Twain "Tom Sawyer"

    Twain "Huck Finn"

    Welch "Practical Programming in Tcl/Tk"

    Flynt "Tcl/Tk: A Developer's Guide"}

  A) foreach in [array names books] {puts $books($in)}

  B) foreach in [array names books T*] {puts $books($in)}

  C) foreach in [array names T* books] {puts $books($in)}


109) Which command will display the string "Tom Sawyer"

array set books {

    Twain "Tom Sawyer"

    Twain "Huck Finn"

    Welch "Practical Programming in Tcl/Tk"

    Flynt "Tcl/Tk: A Developer's Guide"}

  A) puts $books(Twain)

  B) puts [lindex $books(Twain) 1]

  C) "Tom Sawyer" cannot be displayed.


110) Use a "foreach" loop to iterate through an array

  A) if all the processing will be done within that loop.

  B) if your code processes the array in multiple procedures.

  C) if the array indices are monotonically increasing integers.


111) Use the startsearch/nextelement/endsearch technique to iterate through an array if

  A) the indices are random strings.

  B) an array has more than 10,000 indices.

  C) you need to have multiple iterations through the array happening at once.


112) How will the indices of an "array names" or "array nextelement" iteration be ordered?

  A) Alphabetically.

  B) In the order they appear in the internal Tcl data structure.

  C) Numerically.


113) Can you control the order in which indices are returned using startsearch/nextelement?

  A) Yes

  B) No


114) Can you control the order in which indices are processed using "array names" and a "foreach" loop?

  A) Sort of, by using lsort on the list returned by "array names".

  B) Yes, by supplying multiple patterns to "array names"

  C) No

:TEXT_EN

D:


115) Tcl can open files

  A) To read only access.

  B) To write only access.

  C) For read only, write only, or read write access.


116) Tcl views files as

  A) blocks of data.

  B) streams of data that can be accessed from an arbitrary location.

  C) streams of data that must be accessed from byte 0 to the end.


117) Once a file is opened in read mode, your script can

  A) read data using the 'read' or 'gets' command.

  B) read data byte-by-byte using the 'gets' command.

  C) only write new data to the end of the file


118) To make your script read a single line from a stream you should


  A) use the read command.

  B) use the puts command.

  C) use the gets command.


119) Data can be sent to a stream with the

  A) puts command.

  B) puts or write commands.

  C) write command.


120) By default, all Tcl I/O is

  A) unbuffered.

  B) buffered.

  C) flushed.


121) What will be the contents of the file "example.txt" after this script is evaluated:

set of [open "example.txt" w]

puts $of "testing"

  A) nothing, because the stream has not been closed.

  B) nothing, because the stream has not been flushed.

  C) nothing, the stream must be flushed or closed to force the write.


122) You can use the "seek" command to

  A) implement block oriented data files.

  B) search for patterns in a file.

  C) measure the seek time of your file system.


123) The "file" and "glob" commands

  A) mimic the behavior of the Unix "file" and "glob" commands.

  B) provide platform independent ways to access a file system.

  C) can only be used under MS Windows.


124) To extract the name of a file from a full file path

  A) use the "file tail" command.

  B) use the "file dirname" command.

  C) use the "file rootname" command.


125) Which code will change the name of "/tmp/foo.text" to "/tmp/foo.txt"

  A) file rename "/tmp/foo.text" [file dirname "/tmp/foo.text"].txt

  B) file rename "/tmp/foo.text" [file base "/tmp/foo.text"].txt

  C) file rename "/tmp/foo.text" [file rootname "/tmp/foo.text"].txt


126) The "file size" command will

  A) Return the number of disk blocks a file consumes.

  B) Return the size of a file in bytes.

  C) Return the size of the file system.


127) What will be the contents of "path" after this line of code is evaluated.

set path [file split "C:/Program Files/Tcl/bin/tclsh"]

  A) C: Program Files Tcl bin tclsh

  B) C: {Program Files} Tcl bin tclsh

  C) C:/Program Files/Tcl/bin/tclsh


128) What will the contents of "folder" be after this script is evaluated:

set folder [file normalize "/tmp/../etc/passwd"]

  A) /etc/passwd

  B) /tmp/etc/passwd

  C) ../etc/passwd


129) The "file mkdir" command will:

  A) Create a new file in a private folder.

  B) Create a temporary folder.

  C) Create a new empty folder.


130) The command "glob X:/DoesNotExist/*.ext" will probably:

  A) return an empty string.

  B) throw a Tcl error.

  C) return the string "No disk X:"


131) The "file tail" command will

  A) return only the name of a file without the rest of the path.

  B) return the file's extension.

  C) return the part of a filename that comes after the last underscore.


132) The "file mtime" and "file atime" commands return

  A) The time as a human readable string.

  B) The number of seconds since Jan 1, 1980.

  C) The number of seconds since Jan 1, 1970.


133) The "exec" command will

  A) execute an operating system level command and return the results.

  B) execute a set of Tcl commands.

  C) invoke the operating systems "executive" layer.


134) The "open" command can

  A) create a new folder.

  B) open a stream connection to a running program.

  C) start a program and open a stream connection to it.


135) The exec command will return results

  A) as they become available.

  B) after the executed program exits.

  C) when the I/O buffer is filled.


136) The "exec" command can

  A) only run a single program.

  B) run multiple programs in a pipeline.

  C) run multiple programs in parallel, each using a separate channel.


137) The "open" command can

  A) run a single program.

  B) run multiple programs in a pipeline.

  C) run multiple programs in parallel, each using a separate channel.

  D) all of the above.


138) If a program being run with the "exec" command generates an exception return

  A) the "exec" command will throw an error.

  B) the Tcl script ignores the return.

  C) a Tk alert is displayed on the screen.


139) The "exec" command will block a Tcl script until the system command is complete unless:

  A) the "exec" argument list includes the "-noblock" flag.

  B) the "exec" argument list ends with "&".

  C) the "exec" argument list starts with "&".


140) The "info commands" command

  A) returns a list of commands the user has defined.

  B) returns a list of all known commands.

  C) returns a list of command defined in the base Tcl interpreter.


141) The "info procs" command returns

  A) a list of commands the user has defined.

  B) a list of commands defined with the "proc" command only.

  C) a list of commands defined in packages.


142) The "info globals" command will return

  A) a list of all defined globals.

  B) a list of all global variables visible from the current scope.

  C) a list of all global variables that have been modified by this script.


143) If you evaluate "info locals" in the global scope it will:

  A) return a list of all global variables.

  B) return an empty string.

  C) generate an error.


144) If a command is displayed with "info commands" but not "info procs" it means

  A) the command was deleted by info commands.

  B) the command is implemented in compiled "C" code.

  C) the command cannot be replaced by a user procedure.


145) The "info patchlevel" and "info tclversion" commands can be used

  A) the number of patches that have been applied to this version of Tcl.

  B) to determine the revision level of a script.

  C) to determine the version of Tcl interpreter evaluating a script.


146) When this script is evaluated it will display:

puts "[file normalize [info script]]"

  A) the full path to the script being evaluated.

  B) the name of the file being evaluated.

  C) the name of the procedure that contains this line.


147) When this procedure is evaluated it will

proc tst {a} {puts [info level [info level]]}

  A) display the name of the procedure.

  B) display "tst a"

  C) display the name of the procedure (tst) and value of the argument.


148) What will be displayed when this script is evaluated:

proc tst {a} {puts "a"}

puts "[info args tst]"

  A) "a"

  B) "args for tst are 'a'"

  C) "tst {a}"


149) The "info body" command:

  A) returns the "C" code that implements a compiled command.

  B) returns the body of a Tcl procedure.

  C) returns the first N lines of a Tcl procedure.


150) To determine if the arguments to a procedure have default values,

  A) use the "info default" command.

  B) use the "info args -default" command.

  C) use the "info procedure -all" command.


151) What will this procedure do:

proc unique {{val 0}} {

  incr val

  proc unique "{val $val}" [info body unique]

  return $val

}

  A) Always return 0

  B) Rewrite itself each time it's evaluated with a new default value.

  C) return the string "$val"


152) The "source" command

  A) will read a file from a network repository of files.

  B) loads and evaluates a Tcl script file.

  C) evaluates one script within another.


153) A file to be sourced:

  A) May contain only one procedure.

  B) May contain multiple procedures and global scope scripts.

  C) May not assign values to global variables.


154) A file being sourced

  A) must be in simple ASCII.

  B) must be in OpenDoc format.

  C) must be a PDF file.


155) If Tcl encounters an error while "source"-ing a file

  A) it resets and starts over.

  B) it continues and returns the number of errors seen.

  C) it aborts immediately and displays an error.


156) You should split code into multiple source files

  A) with one procedure per source file.

  B) with one set of related functionality per source file.

  C) whenever you have more than 23 lines in a procedure.


157) A package can

  A) include only one procedure.

  B) include only Tcl scripts.

  C) include multiple compiled and Tcl script files.


158) Packages are created

  A) with the "pkg_mkIndex" command.

  B) by including the "package provide" command.

  C) by including the "package provide" command and creating a "pkgIndex.tcl" file.


159) A package can be loaded

  A) with the "source" command.

  B) with the "package require" command.

  C) with the "package provide" command.


160) You should use the "source" command instead of "package require"

  A) if the file is unique to this application and will always be in a known location.

  B) under no circumstances.

  C) if you only want one procedure from a package.


161) An application can load a package

  A) with the "unknown" command.

  B) with the "package require" command.

  C) with the "source" command.


162) Packages are

  A) only provided by the Tcl core developers.

  B) always written in "C".

  C) created whenever an application needs a library of related functions.


167) The "pkg_mkIndex" command

  A) will create an index file used by "package require".

  B) copy a set of related files into a package library.

  C) compress a set of Tcl scripts.


168) If you need to convert a list into separate arguments for a procedure

  A) use the {*} operator.

  B) use the {*} operator unless this is a legacy application running on Tcl8.4 or earlier.

  C) use the "split" command.


169) The "eval" command is

  A) useful when writing dynamic code that constructs new commands.

  B) no longer of value.

  C) only used by Domain Specific Language writers.


170) This script will

set i 2

set cmd "i 1"

incr $cmd

  A) syntax error.

  B) change the value of i to 3.

  C) set the value of i to "i 1"


171) What will be the value of lst1 after this script is evaluated:

set lst1 {a b c}

set lst2 {d e f}

lappend lst1 {*}$lst2

  A) a b c {d e f}

  B) a b c d e f

  C) {a b c} {d e f}


172) What will be the value of lst1 after this script is evaluated:

set lst1 {a b c}

set lst2 {d e f}

lappend lst1 $lst2

  A) a b c {d e f}

  B) a b c d e f

  C) {a b c} {d e f}


173) Which command will not generate an error:

  A) puts "two words"

  B) eval puts "two words"

  C) puts two words


174) What will this script print:

set args -nonewline

set args -nonewline

lappend args "this is a test"

puts $args

  A) -nonewline {this is a test}.

  B) "this is a test", with no newline at the end.

  C) nothing - generates an error.


175) The "info complete" command will

  A) return true when a procedure has completed running.

  B) return true when a Tcl command is complete.

  C) returns true when an application has completed execution.


176) The eval command

  A) drops one level of grouping the arguments.

  B) evaluates a Bourne .sh or DOS .bat file.

  C) evaluates an arithmetic expression.


177) The "subst" command

  A) will substitute one variable with another.

  B) will perform repeated substitution passes until all $varNames are replaced.

  C) will perform a substitution pass, replacing $varName with the contents of a variable


178) The "subst" command

  A) can be used to implement indirection.

  B) can be used with puts, but no other commands.

  C) is not used at all.


179) You can use the "subst" command

  A) to replace a variable with it's contents.

  B) to perform multiple passes of substitution before evaluating a command.

  C) to substitute languages.


180) What will this script print

 array set french {I Je speak parlez French Francais}

 set language french

 foreach word {I speak French} {

  if {[info exists ${language}($word)]} {

    puts -nonewline "[subst $${language}($word)] "

  } else {

    puts -nonewline "$word "

  }

}

  A) No output - generates an error.

  B) I speak French

  C) Je parlez Francais


181) A Tcl script executes in the folder

  A) where the file tclsh exists.

  B) where the main script exists.

  C) from which tclsh is invoked.


182) The "pwd" command reports

  A) the current working directory for the script.

  B) the directory where the script was started.

  C) the directory where the libraries reside.


183) The "cd" command

  A) move a script to a new location.

  B) will change the current working directory for a script.

  C) modify the file system.


184) The command "open log.txt w" will

  A) open a file in the log folder.

  B) open a file in the current working directory.

  C) open a file in the folder with the script.


185) The "return" command

  A) only returns a value.

  B) can only be used once in a procedure.

  C) can return a value and one of several status conditions.


186) The "catch" command

  A) will catch errors and return them to the operating system layer.

  B) will catch an error in a script and return a "true" if an error occurred.

  C) can only be used when evaluating procedures.


187) The "error" command

  A) sets an error state which will be returned when the procedure is complete.

  B) generates an error and aborts processing the script.

  C) tests a script to see if it will generate an error when it's run.


188) What will this script print:

puts [catch {expr {2+a}}]

  A) 0

  B) 1

  C) invalid bareword "a"


189) What will be the contents of x after this script is evaluated:

catch {expr {2+1}} x

  A) 1

  B) 0

  C) 3


190) What will this script display:

set input x

if {[catch expr {$input+2} result]} {

  error "Bad value for input"

} else {

  puts "Result: $result"

}


  A) Result: x+2

  B) Bad value for input

  C) syntax error


191) What is a likely contents for $errorInfo after evaluating this script?

set input x

if {[catch expr {$input+2} result]} {

  error "Bad value for input"

} else {

  puts "Result: $result"

}


  A) wrong # args: should be "expr arg ?arg ...?"

  B) invalid bareword "x"

  C) errorInfo will be an empty string.


192) The "trace variable" command can

  A) generate an exception when a variable is written to a log file.

  B) generate an exception if a read-only variable is modified.

  C) evaluate a script when a variable is read.


193) The "trace info variable"

  A) will return the names of variables with traces.

  B) must be called with the name of variable.

  C) will return information about all variables with traces.


194) The "trace delete variable" command

  A) must be called from within the procedure referenced by a "trace add variable".

  B) only deletes traces that have been activated at least once.

  C) will remove one trace from a single variable.


195) What will this script print:

proc traceProc {n i o} {puts "Name: $n Index: $i Operation: $o"}

trace add variable x write traceProc

proc mm {an} {upvar $an z; set z 2}

mm x

  A) Name: x Index:  Operation: write

  B) Name: z Index:  Operation: write

  C) nothing - generates an error.


196) What output will this script generate:

trace add variable qq array traceProc

proc traceProc {n i o} {puts "Name: $n Index: $i Operation: $o"}

set qq(x) y

 A) Name: qq Index:  Operation: array

 B) Name: qq Index: x Operation: array

 C) none - set is not an "array" operation.


197) A script can access the command line variables it was invoked with

  A) using the "argv0" array.

  B) using the "argc" array.

  C) using the "argv" array.


198) The "env" global array

  A) contains all the environment variables set by the operating system.

  B) contains only the environment variables used internally by Tcl.

  C) contains only env indices set within your script.


199) What will this script display:

proc showEnv {} {

  parray env

}

showEnv


  A) Nothing

  B) The contents of the env() array.

  C) The Tcl specific parts of the env() array.


200) The "env" array

  A) is only available when tclsh is running on a Unix system.

  B) is available only on Windows systems.

  C) contains whatever environment variables are defined on any system.


201) The "time" command

  A) returns the time of day in seconds since 1970.

  B) returns the length of time it takes a script to be evaluated in milliseconds.

  C) returns the length of time since the "time start" command was evaluated.


202) You should use the "unset" command

  A) to destroy all variables before a Tcl script exits.

  B) to be certain no variables are left over from a previous invocation of tclsh.

  C) if your script creates variables so large that you may exhaust the system memory.


203) If your script tries to "unset" a variable that has not been defined

  A) "unset" will generate an error.

  B) "unset" will delete the variable if it ever is defined.

  C) "unset" will return the current value of the variable.


204) The "unset" command

  A) should be used for all procedure local variables before the procedure returns.

  B) should be used for all global variables before an application exits.

  C) is not needed for most scripts.


205) The "socket" command

  A) can create both client and server sockets.

  B) only creates client side sockets.

  C) creates sockets that can only read.


206) The "fileevent" command

  A) generates an event on an I/O channel.

  B) allows a script to modify the behavior of a channel.

  C) registers a script to be evaluated when a channel has data to be read.


207) The "vwait" command

  A) waits for a period of time.

  B) returns control to the event loop until a variable is modified.

  C) waits for a variable to be destroyed.


208) What 3 arguments are added when a script registered with the "socket -server" command

is evaluated as a result of a socket being opened.


  A) Channel, IP Address, and Port Number.

  B) Channel, IP Address, and Permissions.

  C) Read Procedure, Write Procedure and Permissions


209) After a socket is created

  A) data can be read with sockread and sent with sockwrite.

  B) data can be read with gets and sent with puts.

  C) it must be configured for read or write access.


210) The "clock seconds" command

  A) returns the number of seconds since 1980

  B) returns the number of seconds since 1970

  C) returns the number of seconds since a operating system-defined date.


211) The "clock scan" command

  A) will try to convert a human readable date/time to seconds.

  B) will scan a timestamp and split it into year, month, day, hour, minute and seconds.

  C) only works for US formatted timestamps.


212) The "clock format" command

  A) will convert US format dates to European format.

  B) will convert a time in seconds to a human readable format.

  C) will convert time in 24 hour clock to 12 hour time with AM/PM.


213) The "fconfigure" command will

  A) generate an event when a channel's configuration is modified.

  B) allow a script to modify the behavior of a channel.

  C) is only supported on Windows.


214) The "fblocked" command will

  A) block input on a channel - useful for spam prevention.

  B) return 1 if there is data available on a channel.

  C) return 1 if a channel has been blacklisted.


215) The "fconfigure" command can

  A) be used to write files with the "operating system normal" line endings.

  B) configure a channel to connect to a file, terminal or socket.

  C) configure a channel to be read-only.


216) Non-Blocked I/O is useful

  A) when an application is using a round-robin approach to load leveling.

  B) for files with very long lines.

  C) for channels that contain binary data.


217) A new "interp"

  A) can be started on a separate computer on the local network.

  B) shares global variables with the primary interpreter.

  C) has it's own global variables and procedures.


218) When an application creates 2 interps and one interp executes an infinite loop

  A) the other interp continues to run.

  B) the other interp is blocked from execution.

  C) the other interp takes control.


219) You can create procedures in a new interpreter

  A) with the "interp create" command.

  B) with the "interp eval" command.

  C) with the "interp proc" command


220) If you create a new interpreter with "interp create -safe"

  A) it will be unable to access the filesystem.

  B) it will not be able to create procedures.

  C) all procedures created in that interpreter will be tested for buffer overruns.


221) You can link selected "unsafe" procedures into a "safe" interpreter

  A) with "interp configure".

  B) with "interp eval".

  C) with "interp alias".


222) A dict

  A) links a key and value but will not retain the order.

  B) links a key and value and retains the order of the elements.

  C) is an ordered list of values.


223) The "dict size" command

  A) returns the size of the largest value in a dict.

  B) returns the number of keys and values in a dict.

  C) returns the number of key/value pairs in a dict.


224) A dict structure

  A) can be nested arbitrarily deep.

  B) contains only one level of key/value pairs.

  C) must be indexed with an integer.


225) To retrieve the value associated with $key from a dict

  A) use "dict get" with $key

  B) use "dict array($key)"

  C) use dict $key


226) To show all the keys in a dict

  A) use the "dict show keys" command.

  B) use the "dict keys" command.

  C) use the "dict configure -keys" command.


227) A dict can include duplicated keys

  A) True

  B) False



228) How many key/value pairs will this script create in dict1?

dict set dict1 a b c d

  A) 2

  B) 1

  C) 4


229) You can iterate through all the contents in a dict with

  A) the "dict for" command

  B) the "dict foreach" command

  C) the "dict loop" command


230) The "dict with" command

  A) will accept a dictionary and create variable named for each key and assign the appropriate value.

  B) will accept a dictionary and an arrayname and create an array in which each key is an index.

  C) will accept a dictionary and return the values with keys that match a glob value.


231) Which is the resulting dict after this command is evaluated?

dict set dict1 a b c d

  A) a b c d

  B) a {b c d}

  C) a {b {c d}}


232) Dictionaries can be nested

  A) two layers deep.

  B) arbitrarily deeply.

  C) to one level of indirection.


233) A dictionary can be used

  A) in place of a Tcl list.

  B) instead of the "string" commands.

  C) to implement complex data structures.


234) When "dict set" is evaluated with a key that is already in the dict

  A) the previous values associated with that key are replaced with new values.

  B) a new copy of that key, with new values is created.

  C) a new, unique key is fabricated by adding "1" to the key.


235) The "dict replace" command will

  A) replace keys and values with new keys and values.

  B) return a new dict with a new value associated with an existing key.

  C) replace a value with a new value and modify the dict.


236) If a key does not exist, "dict replace" will

  A) add that key/value pair to the end of the dictionary.

  B) add that key/value pair to the beginning of the dictionary.

  C) not insert the new key/value pair.


237) The "dict update" command

  A) can modify a key in a dict.

  B) can modify a value in a dict.

  C) can modify both keys and values in a dict.


238) What will be the final values for dict1 after this script is evaluated.

dict set dict1 a b

dict update dict1 a x {set x c}

  A) a c

  B) a b

  C) a x

+++++++++++++++++++++++++++++++++++++++++++++++++