x
x
x


Do so in a way which:

 does not involve string manipulation of the input source code
 is plausibly extensible to a runtime-chosen set of bindings rather than just x
 does not make x a global variable


or note that these are impossible.



See also

 For more general examples and language-specific details, see Eval.
 Dynamic variable names is a similar task.


eval_with_x() {
	set -- "`x=$2; eval "$1"`" "`x=$3; eval "$1"`"
	expr "$2" - "$1"
}
 
eval_with_x '
	# compute 2 ** $x
	p=1
	while test $x -gt 0; do
		p=`expr $p \* 2`
		x=`expr $x - 1`
	done
	echo $p
' 3 5
# Prints '24'