Re: misunderstaning of switch command

Liste des GroupesRevenir à cl tcl 
Sujet : Re: misunderstaning of switch command
De : nospam (at) *nospam* wanadoo.nl (Schelte)
Groupes : comp.lang.tcl
Date : 24. Jun 2025, 11:53:57
Autres entêtes
Organisation : KPN B.V.
Message-ID : <nnd$5b777162$1a6eec73@9195abc3fb33f9cc>
References : 1
User-Agent : Mozilla Thunderbird
On 24/06/2025 10:23, Mark Summerfield wrote:
I have a switch command which is doing something I don't expect but I
don't understand what I've done wrong. In this example the default is
always executed but I expect the case before that to be executed.
      const UNCOMPRESSED U
     const ZLIB_COMPRESSED Z
     const SAME_AS_PREV =
     set filename somefile.txt
     set action "added"
     set kind Z
     switch $kind {
         $::SAME_AS_PREV { puts "unchanged \"$filename\"" }
         $::UNCOMPRESSED { puts "$action \"$filename\"" }
         $::ZLIB_COMPRESSED { puts "$action \"$filename\" (zlib
compressed)" }
         default { puts "!!!!!!!! UNEXPECTED !!!!!!!!" }
     }
 What am I doing wrong?
Switch allows for two different ways to specify the pattern/body pairs: As as a single argument or as individual arguments. If you want the patterns to be in variables (or consts) you may prefer the latter method. This can be written as:
switch $kind \
   $::SAME_AS_PREV {
     puts "unchanged \"$filename\""
} $::UNCOMPRESSED {
     puts "$action \"$filename\""
} $::ZLIB_COMPRESSED {
     puts "$action \"$filename\" (zlib compressed)"
} default {
     puts "!!!!!!!! UNEXPECTED !!!!!!!!"
}
Schelte.

Date Sujet#  Auteur
24 Jun 25 * misunderstaning of switch command10Mark Summerfield
24 Jun 25 +* Re: misunderstaning of switch command6Harald Oehlmann
24 Jun 25 i`* Re: misunderstaning of switch command5Mark Summerfield
24 Jun 25 i +* Re: misunderstaning of switch command3Harald Oehlmann
24 Jun 25 i i`* Re: misunderstaning of switch command2Harald Oehlmann
24 Jun 25 i i `- Re: misunderstaning of switch command1Alan Grunwald
24 Jun 25 i `- Re: misunderstaning of switch command1Robert Heller
24 Jun 25 +* Re: misunderstaning of switch command2Schelte
24 Jun 25 i`- Re: misunderstaning of switch command1Harald Oehlmann
24 Jun 25 `- Re: misunderstaning of switch command1Robert Heller

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal