tcl

why we cannot define dict as Argument defination in tcl?


I have a proc which takes two dicts as required arguments

set myDict1 {a {1 2 3} b {4 5 6}}
set myDict2 {c {5 6} d {6 7}}
proc myProc {args} {
  set output [miscProc $myDict1 $myDict2]
  return $output
}

when i treid to define the args like below it throws an error

Argument definition "dict {-inp1} {define first dict} {} 1 1" of command "myProc" does not contain a valid argument type. The valid argument types are "int float bool string enum ternary point alias box point_list db_object redirect_operator string enum_list object tcl_obj box_list polygon "

define_proc_arguments myProc \
  -info "perform something" \
  -define_args {
      {-inp1    "define first dict" "" dict {required}}
      {-inp2   "define second dict" ""  dict {required}}
    }

what i am missing here should i define them as list / array ?


Solution

  • The issue is that whoever wrote define_proc_arguments didn't include an option for validating dictionaries (or general lists). I can't find anything to let me guess what the source to that might be (nothing at all in the Tcl source tree, on Github, or on the Tcler's Wiki) so guessing how to fix it is difficult.

    If you want to validate a value as a dictionary, first accept it as a string (which won't apply any validation in define_proc_arguments) and then check it yourself with string is dict.