Looking for a cure for weird scope/memory of variables

Joshua Root jmr at macports.org
Tue Jul 23 19:16:58 PDT 2013


On 2013-7-24 00:47 , Mojca Miklavec wrote:
> After seeing all the different semi-confusing options I noticed
> something really simple. While this fails:
> 
>     foreach {foo.version foo.string} ${foo.versions} {
>         subport foo-${foo.version} {
>             pre-fetch {
>                 system "echo ${foo.version}"
>             }
>         }
>     }
> 
> the following works just fine:
> 
>     foreach {foo.version foo.string} ${foo.versions} {
>         subport foo-${foo.version} {
>             set foo.versionx ${foo.version}
>             pre-fetch {
>                 system "echo ${foo.versionx}"
>             }
>         }
>     }
> 
> I believe that this is more readable and easier to understand than the
> map/eval trickery.

Yes, using variables in a procedure rather than splicing their values
into the procedure's definition is generally good practice. :-)

- Josh


More information about the macports-dev mailing list