language: Tcl (tclsh 8.5.7)
date: 153 days 1 hour ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
set cards [list "Queen of Hearts" "3 of Clubs" "9 of Spades" \
"Ace of Hearts" "5 of Diamonds"]
# Ask user for what to search
puts -nonewline "Card for which to search (such as King, Spade, or 9): "
flush stdout
gets stdin card
# Loop until user inputs a matching card
while {[set index [lsearch $cards *[string totitle $card]*]] < 0} {
puts "No such card. Please try again."
puts -nonewline "Card for which to search (such as King, Spade, or 9): "
flush stdout gets stdin card
}
# Show the match
puts "Matched the [lindex $cards $index]"
  • upload with new input
  • result: Runtime error     time: 0.03s    memory: 5272 kB     signal: -1

    king
    Card for which to search (such as King, Spade, or 9): No such card. Please try again.
    Card for which to search (such as King, Spade, or 9): 
    wrong # args: should be "flush channelId"
        while executing
    "flush stdout gets stdin card"
        ("while" body line 4)
        invoked from within
    "while {[set index [lsearch $cards *[string totitle $card]*]] < 0} {
    puts "No such card. Please try again."
    puts -nonewline "Card for which to search (..."
        (file "prog.tcl" line 8)