[swift-evolution] [Idea]Why not get dynamically named variables?

David Sweeris davesweeris at mac.com
Sun Sep 4 13:33:07 CDT 2016


> On Sep 4, 2016, at 10:28, Fayez Hellani via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hey! There should be an option to name variables AND constants dynamically. For e.g. in an app from storing recipes, where the user creates a recipe,the recipe should be stored in a constant (as a structure) with a name “\(TitleTextField.text)_Recipe” (e.g. “Lasagna_Recipe”), so that it gets stored easily and therefore fetched even easier.

I'm not sure I understand... Are you suggesting we be allowed to declare a variable like this?
    var foo = "bar"
    var \(foo) = 42 //is really named `bar`

If so, how do we then interact with it? Having to write
    \(foo) *= 3
doesn't seem any better than
    bar *= 3
Plus, string interpolation could get real tricky to read if someone nests the naming redirections, so to speak, too deep.

At least for "normal" programming, I don't think I get it...

Outside of that, I wonder if this idea might be part of a conceptual basis for some sort of fusion between interpreted code and complied code, or maybe part of the fabled macro system.

- Dave Sweeris


More information about the swift-evolution mailing list