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]"
}
Am 02.07.2025 um 10:39 schrieb Mark Summerfield:
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]"
}
The name "args" is special in TCL returning all remaining arguments as a list.
As you call:
process1 $argv
The one argument is put in a list. The result is a matrix (list in list).
How to solve:
a) don't use "args":
proc process1 myargs {
set first [lindex $myargs 0]
puts "first='$first' args='$myargs' list? [string is list -strict $myargs]"
set rest [lrange $myargs 1 end]
puts "rest='$rest' list? [string is list -strict $rest]"
}
b) use the delist operator:
process {*}$argv
Hope this helps,
Harald
On Wed, 2 Jul 2025 11:27:54 +0200, Harald Oehlmann wrote:
Am 02.07.2025 um 10:39 schrieb Mark Summerfield:
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]"
}
The name "args" is special in TCL returning all remaining arguments as a
list.
As you call:
process1 $argv
The one argument is put in a list. The result is a matrix (list in list).
How to solve:
a) don't use "args":
proc process1 myargs {
set first [lindex $myargs 0]
puts "first='$first' args='$myargs' list? [string is list -strict
$myargs]"
set rest [lrange $myargs 1 end]
puts "rest='$rest' list? [string is list -strict $rest]"
}
b) use the delist operator:
process {*}$argv
Hope this helps,
Harald
Thanks, I hadn't realised that using `args` would give me a list in a list.
I now just pass the list as-is (and called `rest` to avoid confusion!).
On 7/2/2025 2:34 AM, Mark Summerfield wrote:
Thanks, I hadn't realised that using `args` would give me a list in a list. >> I now just pass the list as-is (and called `rest` to avoid confusion!).
This used to confuse me totally. Now I understand (I think) that
args and {*} are inverses of each other. If you can get your head
around this, then you got it :)
Thanks, I hadn't realised that using `args` would give me a list in a
list.
Thanks, I hadn't realised that using `args` would give me a list in a list.
I now just pass the list as-is (and called `rest` to avoid confusion!).
et99 <et99@rocketship1.me> wrote:
On 7/2/2025 2:34 AM, Mark Summerfield wrote:
Thanks, I hadn't realised that using `args` would give me a list in a list. >>> I now just pass the list as-is (and called `rest` to avoid confusion!).
This used to confuse me totally. Now I understand (I think) that
args and {*} are inverses of each other. If you can get your head
around this, then you got it :)
If you understand what 'xargs' does on a Unix CLI, {*} is essentially a
"Tcl xargs".
It (when used for calling a proc) converts "a list of things" into "individual parameters to the proc".
What it really does is "unwraps" the lists contents. So instead of
having "one list containing 5 things" you end up with the internal "5
things" each individually.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,064 |
Nodes: | 10 (0 / 10) |
Uptime: | 163:56:29 |
Calls: | 13,691 |
Calls today: | 1 |
Files: | 186,936 |
D/L today: |
9,208 files (2,741M bytes) |
Messages: | 2,411,516 |