modern Tcl and correct quoting

Poor Yorick org.macosforge.lists.macports-dev at pooryorick.com
Wed Jun 12 19:53:41 PDT 2013


On Wed, Jun 12, 2013 at 10:17:10PM -0400, Lawrence Velázquez wrote:
> On Jun 12, 2013, at 6:18 PM, Poor Yorick <org.macosforge.lists.macports-dev at pooryorick.com> wrote:
> 
> > [eval] concatenates its arguments and passes them through the interpreter again
> > to be parsed and executed as a script.  This results in double substitution.
> > Here's an example from the patch:
> > 
> >    $workername eval "package ifneeded $pkgName $pkgVers {$pkgLoadScript}"
> > 
> > The first issue with this is that if, e.g., $pkgName contained a space, the
> > constructed script would no longer be syntactically correct, as it would pass
> > too many arguments to [package ifneeded].  The second issue is that simply
> > putting braces around a substituted variable like $pkgLoadScript is not
> > guaranteed to result in a well-formed single value.  If $pkgLoadScript contains
> > a left or right curly bracket, or if it ends in a backslash, the script will be
> > corrupted.  .  The robust way to write the line above is like this:
> > 
> > 	$workername eval [list package ifneeded $pkgName $pkgVers $pkgLoadScript]
> > 
> > http://wiki.tcl.tk/1535 has more details.
> 
> 
> Is there a material difference between using list here and doing something like this?
> 
>     $workername eval {package ifneeded $pkgName $pkgVers $pkgLoadScript}
> 

Yes, in the first case, the variables are resolved in the current scope before
[$workername eval ...] is invoked, and in the second, they are resolved in the
scope ofthe $workername interpreter during the execution or [$workername eval
...], and those are two entirely different namespaces.

-- 
Poor Yorick


More information about the macports-dev mailing list