On Mar 16, 3:34 am, DrS <
drscr...@gmail.com> wrote:
> On 3/15/2012 9:56 PM, Alexander Rast wrote:
>
>
>
> > Hi, new troubles, now related to using arguments in a proc.
>
> > I have:
>
> > proc setGroupParams {args} {
>
> > if {$args ==<empty list>} {
> > set params<default-params>
> > } elseif {$args ==<single dictionary>} {
> > <set required params to those specified in the dictionary>
> > } else {
> > <set required params using the first dictionary, other
> > params using other dictionaries>
> > }
> > }
>
> > The critical thing here is that setGroupParams may receive as args
> > either an empty list, a single dictionary, or a list of dictionaries.
> > This seems to create a problem in detecting the empty list case.
> > Nothing I've tried for the test seems to work. The obvious answer:
>
> args is always a list. If you are receiving a list of one element which
> turns out to be an empty list, look to the caller to find out why and
> fix it if needed.
>
> Also, why are you using "args"? As you state, if the input is always a
> single element (be it a list, a dictionary or a list of dictionaries),
> just use a named argument and your troubles would go away.
What I was saying is, by the process whereby "args" in the proc is
turned into a list, (as you say "args is always a list") the actual
arguments passed in are made into lists. What's going on is that the
proc is being fed from the output of another (not readily changed
because it sits in a package with standard interfaces) proc whose
output may be one of 3 possible cases. It may output an empty string,
it may output a dictionary, or it may output multiple dictionaries.
Thus when input into the proc these are transformed, respectively,
into a list consisting of an empty element, a list of a single
dictionary, or a list of dictionaries. The case where the output of
the lower-level proc is an empty string is not an error or
misbehaviour on the part of the low-level proc. The lower level proc
reads in lines from an input file that specifies, in this case, a
neural network. Generally, each specification line has a list of
parameters. The difficult bit is that the line may actually have no
parameters, which indicates in fact that all parameters are to be set
to certain system default values. In that case the low-level proc
returns the empty string.
> If you simply want to get rid of empty elements, a quick and dirty way is:
> % set new_args [eval concat $args]
>
> However, be careful that this will also flatten lists in the arguments.
Which is what I need it to NOT do, because this will bung together
lists of dictionaries.
Also Harald Oehlmann said:
>To test for an empty list in a clean way, please use:
>if { 0 == [llength $args] }
That was one of the things I tried, but it didn't work because
[llength $args} reports 1 for the first case, namely args == {}
From what's been posted so far, I get the distinct impression that the
answer is "there's no easy way to do this". In fact, the problem of
"fall-through defaults" is proving overall to be an astonishingly
difficult one to solve.