let var1 = val_of_var1 ;
print ( var1 ) ; // val_of_var1
let var2 = val_of_var2 ;
print ( var2 ) ; // val_of_var2
let var1var2 = val_of_var1var2 ;
print ( var1var2 ) ; // val_of_var1var2
////// here !!!!! something like that !!!!
let build_var1 = var + 1 ;
let build_var2 = "var" + "2" ;
let build_var1var2 = var1 + var2 ;
print ( build_var1 ) ; // val_of_var1
print ( build_var2 ) ; // val_of_var2
print ( build_var1var2 ) ; // val_of_var1var2
It seems some old langues can manipulate variable names as values.
It is no problem, just for fun.. and studying
No, this isn't possible. The names of your variables don't even exist in the executable anymore when you have compiled it.
You can only do such things at compile time in macros. E. g. there's the unstable API concat_idents in the standard library; otherwise the paste crate is quite useful, as I can do the same kind of thing and more. Feel free to look at the documentation I linked for both of these for more information and illustrative examples.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.