I wanted to include "parray" output in a report (on stdout),
but I needed it indented by a given string before each line.
The trick was rather simple in hindsight:
proc ind_parray {ind arr} {
upvar 1 $arr "$ind$arr"; parray "$ind$arr"
}
It works well for pure whitespace-indentations, and probably
most others as long as $ind doesn't contain "::" .
Just thought I'd share.
I wanted to include "parray" output in a report (on stdout),
but I needed it indented by a given string before each line.
The trick was rather simple in hindsight:
proc ind_parray {ind arr} {
upvar 1 $arr "$ind$arr"; parray "$ind$arr"
}
It works well for pure whitespace-indentations, and probably
most others as long as $ind doesn't contain "::" .
Just thought I'd share.
Andreas Leitgeb <[email protected]> writes:
I wanted to include "parray" output in a report (on stdout),
but I needed it indented by a given string before each line.
The trick was rather simple in hindsight:
proc ind_parray {ind arr} {
upvar 1 $arr "$ind$arr"; parray "$ind$arr"
}
It works well for pure whitespace-indentations, and probably
most others as long as $ind doesn't contain "::" .
Just thought I'd share.
But .. I don't get it? Could you please elaborate a bit more what do you
do here?
I wanted to include "parray" output in a report (on stdout),Andreas,
but I needed it indented by a given string before each line.
The trick was rather simple in hindsight:
proc ind_parray {ind arr} {
upvar 1 $arr "$ind$arr"; parray "$ind$arr"
}
It works well for pure whitespace-indentations, and probably
most others as long as $ind doesn't contain "::" .
Just thought I'd share.
Rolf Ade <[email protected]> wrote:
Andreas Leitgeb <[email protected]> writes:
I wanted to include "parray" output in a report (on stdout),But .. I don't get it? Could you please elaborate a bit more what do you
but I needed it indented by a given string before each line.
The trick was rather simple in hindsight:
proc ind_parray {ind arr} {
upvar 1 $arr "$ind$arr"; parray "$ind$arr"
}
It works well for pure whitespace-indentations, and probably
most others as long as $ind doesn't contain "::" .
do here?
Indent string can be just about anything, other than containing a :: or
[] sequence:
% ind_parray " { } [ ] $ " tcl_platform
{ } $ tcl_platform(byteOrder) = littleEndian
I too often use parray, and since it's easily modified (it's
autoloaded and found in tcl86/lib along with a few other commands) I
change it to use a -dictionary sort by default. I find that works
better when the indices are numerical, and alpha when not.
I wrote up a ticket once, since IMHO it is an oversight not to use a dictionary sort
and found a TIP to be a bit overkill.
My modified version changes the arglist to:
proc parray {a {pattern *} {type -dictionary}} {
and the lsort to:
set names [lsort {*}$type [array names array $pattern]]
which then allows for such things as -ascii or {-ascii -decreasing}
at the small cost of requiring the * if you still want that.
et99 <[email protected]> wrote:
I too often use parray, and since it's easily modified (it's
autoloaded and found in tcl86/lib along with a few other commands) I
change it to use a -dictionary sort by default. I find that works
better when the indices are numerical, and alpha when not.
I wrote up a ticket once, since IMHO it is an oversight not to use a
dictionary sort
I agree.
Purely integral array indices are probably quite common in practice.
and found a TIP to be a bit overkill.
I disagree. At least it's not overkill for the following
extended suggestion:
My modified version changes the arglist to:
proc parray {a {pattern *} {type -dictionary}} {
and the lsort to:
set names [lsort {*}$type [array names array $pattern]]
which then allows for such things as -ascii or {-ascii -decreasing}
at the small cost of requiring the * if you still want that.
and I'd also welcome another option for indentation ;-)
On 12/02/2023 16:04, Andreas Leitgeb wrote:
et99 wrote:
I too often use parray, and since it's easily modified (it's
autoloaded and found in tcl86/lib along with a few other commands) I
change it to use a -dictionary sort by default. I find that works
better when the indices are numerical, and alpha when not.
I wrote up a ticket once, since IMHO it is an oversight not to use a
dictionary sort
I agree.
Purely integral array indices are probably quite common in practice.
and found a TIP to be a bit overkill.
I disagree. At least it's not overkill for the following
extended suggestion:
My modified version changes the arglist to:
proc parray {a {pattern *} {type -dictionary}} {
and the lsort to:
set names [lsort {*}$type [array names array $pattern]]
which then allows for such things as -ascii or {-ascii -decreasing}
at the small cost of requiring the * if you still want that.
and I'd also welcome another option for indentation ;-)
If you're putting together a TIP, I'd welcome an argument to specify an output script, making the calling sequence
proc parray {a {pattern *} {type -dictionary} {script {puts stdout}}}
On 2/13/2023 7:41 AM, Alan Grunwald wrote:
If you're putting together a TIP, I'd welcome an argument to specify
an output script, making the calling sequence
proc parray {a {pattern *} {type -dictionary} {script {puts stdout}}}
Not mentioned yet but for me a major inconvenience with parray is that
it is not copy-paste ready. If you are using parray, most likely you are interested in the contents of an element or a list. And almost always
you'd want to update it with some changes. Here comes the trouble: you
need to type "set ", copy-paste the array variable name, skip over the [....]
If you're putting together a TIP, I'd welcome an argument to specify an output script, making the calling sequence
proc parray {a {pattern *} {type -dictionary} {script {puts stdout}}}
Use tkcon. Then you say "edit <varname>" and a window pops up with an editable version. By choosing "Send to slave" from the menu, it will be updated in the interpreter. The nice thing is that it works with procs, arrays and ordinary variables.
On 2/13/2023 1:14 PM, Christian Gollwitzer wrote:
Use tkcon. Then you say "edit <varname>" and a window pops up with an editable version. By choosing "Send to slave" from the menu, it will be updated in the interpreter. The nice thing is that it works with procs, arrays and ordinary variables.
Nice! It still requires editing if you need to change one item only but I can see it being quite useful.
On Monday, February 13, 2023 at 1:41:20 PM UTC+1, Alan Grunwald wrote:I agree that many optional parameters is a Bad Idea, and have no
On 12/02/2023 16:04, Andreas Leitgeb wrote:
et99 wrote:If you're putting together a TIP, I'd welcome an argument to specify an
I too often use parray, and since it's easily modified (it's
autoloaded and found in tcl86/lib along with a few other commands) I
change it to use a -dictionary sort by default. I find that works
better when the indices are numerical, and alpha when not.
I wrote up a ticket once, since IMHO it is an oversight not to use a
dictionary sort
I agree.
Purely integral array indices are probably quite common in practice.
and found a TIP to be a bit overkill.
I disagree. At least it's not overkill for the following
extended suggestion:
My modified version changes the arglist to:
proc parray {a {pattern *} {type -dictionary}} {
and the lsort to:
set names [lsort {*}$type [array names array $pattern]]
which then allows for such things as -ascii or {-ascii -decreasing}
at the small cost of requiring the * if you still want that.
and I'd also welcome another option for indentation ;-)
output script, making the calling sequence
proc parray {a {pattern *} {type -dictionary} {script {puts stdout}}}
Looking to balance cost for effort, isn't that asking for a wrapper to the example of the array command?
foreach {color count} [array get colorcount] {
puts "Color: $color Count: $count"
}
I'd understand optional {channelId stdout} - and I would still warn about bad experience with this many optional positional parameters, i.e. I'd prefer switches.
parray -dictionary -format {Color: %10s Count: %10s} -chan stderr colorcount
I'm afraid, I think this thread has gone a bit "out of control"...
I don't think, "parray" itself ought to be turned into a swiss army
knife tool, but maybe some parray-on-steroids could be added to tcllib...
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 148:43:54 |
| Calls: | 12,091 |
| Calls today: | 4 |
| Files: | 15,000 |
| Messages: | 6,517,560 |