Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Terminology question: nested vs. recursive

May
572
4
This question is inspired by a recent note by Samintz, where Scott said,
I typically use setdos /X-4 to disable nested variable expansion. If
nested variable expansion is disabled (X-4), each variable is expanded
once, but variables containing the names of other variables are not
expanded further.
I had never used that before, and prior to seeing this description, I had thought that nested variable expansion meant expanding something like
Code:
set x=4
set x4=four
echo %[x%x]
I found that with SETDOS /X-4 and with SETDOS /X4 (or /X0) the result of the above code fragment is "four", and SETDOS /X-4 does not disable this. This is what I thought nested variables were.

Well it turns out that what SETDOS /X-4 affects is the expansion of a variable whose resultant string contains a % sign. I would have called that recursive or iterative variable expansion.

I would like to see the distinction between these two different cases made clear in the help, especially in the SETDOS /X help, and perhaps some index entry in the help file to find the section on the %[x%x] form. (I'm sure it's there, but I couldn't find an index entry to find it.)

(I was thinking of asking for a way to disable the %[x%x] form in SETDOS /X, but I can't think of what good that would do anybody.)

Compare nested variable expansion to nested function evaluation.

Nested function: %@eval[3 + %@date[1980-1-1]] Yes.
Nested variable? %[x%x] No.
 

Similar threads

Back
Top