3 ms·
The only other language like this I can think of is Rust. You can write r#keyword to quote a keyword to be used as an identifier. This solution was devised as
by nextaccountic 3y ago
The only other language like this I can think of is Rust. You can write r#keyword to quote a keyword to be used as an identifier.
This solution was devised as a means to add keywords to new editions of the language without breaking code written in the old edition that named this stuff the same as the keyword (and with full interoperability between code from new editions and old editions)
So if some function in some Rust 2015 library was named async (a new keyword introduced in Rust 2018), you can call it like r#async() in newer versions
- recursive 3y agoIn C# you can prefix with @ to achieve the same thing.
- paulddraper 3y agoIn Scala it's backticks. val `val` = 1
- saled 3y agoIn kotlin you can use backticks to "unkeywordify" a name
- andyferris 3y agoIn Julia you can also use var”any string” to use any string as a variable name
- hexane360 3y agoI'm sure you know this, but this is actually a special case of a much more general rule; in Julia, prefixed string literals are implemented are passed on to macros: https://docs.julialang.org/en/v1/manual/metaprogramming/#meta-non-standard-string-literals https://docs.julialang.org/en/v1/manual/metaprogramming/#met... Such macros can be defined by libraries or the end user to provide special behavior.
- Tiberium 3y agoTo join the other commenters, in Nim you use backticks to allow using Nim keywords - this is important for e.g. nice deserialization where some JSON object has a field like `type` which is a keyword in Nim. https://nim-lang.org/docs/json.html#overview-unmarshalling https://nim-lang.org/docs/json.html#overview-unmarshalling
- asddubs 3y agoin php all variables are prefixed so you don't have to worry about keyword collisions at all