Subject: Re: [Boost-build] What is _message_
Date: 2016-06-03 10:24:22
> How does the syntax:
> apply to a Boost Build variable ? I thought Boost Build variables (
> which are list of strings ) had to use [n] to access a string in the list.
The Jam language doesn't have a specific data structure for something
like a hashmap (dicationary, associative array, etc), so it's a common
convention to use "variable variables" to facilitate the same functionality.
variable-name = x ;
# this sets the variable named "x"
$(variable-name) = some list of values ;
# now, read from the variable named "x"
echo $(x) ;
# outputs: some list of values
The use of variable variables is often used for caching expensive
rule my-expensive-rule ( targets * )
# it is conventional to prefix the variable variable with
# a string literal so that it's easy to search for where the
# variable variable is being used.
local key = $(.my-expensive-rule-cache-$(targets)) ;
# this checks to see if the variable name exists in the current
# module's namespace. if the variable has never been declared
# then the expansion evaluates to a null-like value.
if ! $(key)
# note that the variable name stored in "key" is
# creating a variable that is global here
$(key) = [ my-expensive-rule-really $(targets) ] ;
# note the double dollar signs here: $(key) returns the name
# of the variable and $($(key)) returns the value of the variable
# name stored in "key"
return $($(key)) ;
Hope that helps,
Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk