| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
I'm open to changing this syntax, but I view it as essential to aim for a single consistent capture syntax that works the same in all the places we do capture, where "capture" means "take an expression in this context and store a copy of its current value for use later."
Here are four places this comes up, the first three of which are currently implemented in cppfront:
Local functions (aka lambdas): :(i:_) = i + offset$; -- capture a copy of offset on closure creation for use later each time the closure is invoked
Postconditions: [[post: v.size() == v.size()$ + 1]] -- capture a copy of v.size() on function entry for use later when the whole postcondition is evaluated on function exit
String interpolation: "My name is (name)$" -- capture a copy of name on string construction for use later when the string value is referred to
Note: I realize this interpolation syntax is the reverse order of most other languages which put the "paste" character first. JavaScript would be "My name is $(name)". Swift would be "My name is \(name)". Python would be "My name is {name}".
I'm not opposed to making the $ a prefix, or switching to { }. Some side by side examples:
For switching to prefix $, a minor concern would be that it will generally mean needing more parens in the usual kinds of expressions places where they're needed today for prefix operators.
For switching to just { }, two things I considered are:
To consider changing to the capture syntax I'd like to have some additional evidence, including experience actually trying out this syntax and learning whether there's a problem that needs to be solved, or experience from other languages that a given syntax really didn't work well for them (e.g., did using $ cause known interference with other tools).
| Back | FazBrowse Home | New Git URL |