[GRASS-dev] Re: [GRASS-CVS] michael: grass6/gui/tcltk/gis.m
mapcanvas.tcl, 1.52, 1.53
Glynn Clements
glynn at gclements.plus.com
Thu Nov 30 18:09:36 EST 2006
Hamish wrote:
> oh, and FWIW I figured out why my tcl exec solution was failing with:
> ERROR: region <> not found
> It was trying to run `g.region ""` (expands to `g.region region=""`)
>
> It's redundant now, but for the record adding a "concat" fixed it:
>
> -set regcmd [list exec "g.region" "-ug" $args]
> +set regcmd [list exec "g.region" [concat "-ug " $args]]
> set retval [catch $regcmd result]
This is bogus. It will fail if $args isn't empty:
% set args {foo bar baz}
% set regcmd [list exec "g.region" [concat "-ug " $args]]
% puts $regcmd
exec g.region {-ug foo bar baz}
% set args foo
% set regcmd [list exec "g.region" [concat "-ug " $args]]
% puts $regcmd
exec g.region {-ug foo}
IOW, the entire list of arguments (including the "-ug") will be passed
to g.region as a single argument.
I'm guessing that you're focusing on the case where $args is empty:
% set args ""
% set regcmd [list exec "g.region" "-ug" $args]
% puts $regcmd
exec g.region -ug {}
% set args ""
% set regcmd [list exec "g.region" [concat "-ug " $args]]
% puts $regcmd
exec g.region -ug
If so, the correct fix is:
set regcmd [concat exec g.region -ug $args]
E.g.:
% set args ""
% set regcmd [concat exec g.region -ug $args]
% puts $regcmd
exec g.region -ug
% set args foo
% set regcmd [concat exec g.region -ug $args]
% puts $regcmd
exec g.region -ug foo
% set args {foo bar baz}
% set regcmd [concat exec g.region -ug $args]
% puts $regcmd
exec g.region -ug foo bar baz
NOTE: if a procedure's last formal argument is named "args", it is
treated specially: $args will be a list containing all of the
remaining arguments. This allows variadic procedures to be
implemented.
If you are passing a list of arguments as a list (rather than as
individual arguments), use a name other than "args". Otherwise, the
list will get "wrapped" inside another list.
Only use "args" as an argument variable if the procedure is supposed
to be variadic.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list