confused about lists and strings...

Liste des GroupesRevenir à cl tcl 
Sujet : confused about lists and strings...
De : m.n.summerfield (at) *nospam* gmail.com (Mark Summerfield)
Groupes : comp.lang.tcl
Date : 02. Jul 2025, 09:39:27
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <1042r7u$3dr0l$1@dont-email.me>
User-Agent : Pan/0.154 (Izium; 517acf4)
Given this test.tcl code:

proc main {} {
    set argv [lrange $::argv 1 end]
    process1 $argv
    process2 $argv
    process3 $argv
}

proc process1 args {
    set first [lindex $args 0]
    puts "first='$first' args='$args' list? [string is list -strict $args]"
    set rest [lrange $args 1 end]
    puts "rest='$rest' list? [string is list -strict $rest]"
}

proc process2 args {
    set first [lindex $args 0 0]
    puts "first='$first' args='$args' list? [string is list -strict $args]"
    set rest [lrange $args 1 end]
    puts "rest='$rest' list? [string is list -strict $rest]"
}

proc process3 args {
    set args {*}[lrange $args 0 end]
    set first [lindex $args 0]
    puts "first='$first' args='$args' list? [string is list -strict $args]"
    set rest [lrange $args 1 end]
    puts "rest='$rest' list? [string is list -strict $rest]"
}

main

I get the following output:

$ ./passlist.tcl ignored a b c d
first='a b c d' args='{a b c d}' list? 1
rest='' list? 1
first='a' args='{a b c d}' list? 1
rest='' list? 1
first='a' args='a b c d' list? 1
rest='b c d' list? 1

Only process3 works as I expect, but it seems a bit clumsy having
to use the line
    set args {*}[lrange $args 0 end]
although it does have the virtue of doing what I want.

What am I misunderstanding about process1 and process2?

Date Sujet#  Auteur
2 Jul 25 * confused about lists and strings...8Mark Summerfield
2 Jul 25 `* Re: confused about lists and strings...7Harald Oehlmann
2 Jul 25  `* Re: confused about lists and strings...6Mark Summerfield
2 Jul 25   +* Re: confused about lists and strings...3et99
2 Jul 25   i`* Re: confused about lists and strings...2Rich
2 Jul 25   i `- Re: confused about lists and strings...1et99
2 Jul 25   +- Re: confused about lists and strings...1Rich
2 Jul 25   `- Re: confused about lists and strings...1Christian Gollwitzer

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal