Unicode variable names: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(→‎{{header|Wren}}: Added an alternative using the Var class.)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(5 intermediate revisions by 4 users not shown)
Line 204:
{{out}}
<pre>2</pre>
 
=={{header|C++}}==
The C++ language allows the use of Unicode variable names.
 
For more information visit: https://en.cppreference.com/w/cpp/language/character_literal,
 
https://en.cppreference.com/w/cpp/language/identifiers and https://learnmoderncpp.com/2021/03/24/a-unicode-primer/
<syntaxhighlight lang="c++">
#include <cstdint>
#include <iostream>
#include <string>
 
int main() {
uint32_t Δ = 1;
double π = 3.14159;
std::string 你好 = "Hello";
Δ++;
std::cout << Δ << " :: " << π << " :: " << 你好 << std::endl;
}
</syntaxhighlight>
{{ out }}
<pre>
2 :: 3.14159 :: Hello
</pre>
 
=={{header|Clojure}}==
Line 294 ⟶ 318:
 
=={{header|Elena}}==
ELENA 46.x:
<syntaxhighlight lang="elena">public program()
{
Line 300 ⟶ 324:
Δ := Δ + 1;
console.writeLine:(Δ)
}</syntaxhighlight>
 
Line 384 ⟶ 408:
where δΔ = 1
ψ = δΔ + 1</syntaxhighlight>
 
=={{Header|Insitux}}==
 
<syntaxhighlight lang="insitux">
(let Δ😄 1)
(inc Δ😄)
</syntaxhighlight>
 
{{out}}
 
<pre>
2
</pre>
 
=={{header|J}}==
Line 1,014 ⟶ 1,051:
 
The error description refers to the bytes in the UTF encoding of 'Δ' which can't appear (outside a string) in a Wren script.
<syntaxhighlight lang="ecmascriptwren">var a = 3
var b = 2
var delta = a - b // ok
Line 1,027 ⟶ 1,064:
{{libheader|Wren-trait}}
However, it is possible to simulate Unicode variable names to some extent by using the ''Var'' class in the above module which stores the names (which can be any valid string) in an internal map.
<syntaxhighlight lang="ecmascriptwren">import "./trait" for Var
 
Var["Δ"] = 1
Var["Δ"] = Var["Δ"] + 1
System.print(Var["Δ"])</syntaxhighlight>
 
{{out}}
<pre>
2
</pre>
 
=={{header|Zig}}==
 
'''Works with:''' 0.10.x, 0.11.x, 0.12.0-dev.1594+7048e9366
 
Links here refer to 0.10.1 documentation, but nothing changed in 0.11.0, and 0.12.0 is not released yet at the moment of writing.
 
Source code in Zig must be encoded in UTF-8, see [https://ziglang.org/documentation/0.10.1/#Source-Encoding this] page from language reference.
 
Zig supports non-conforming identifiers (that includes space, use non-English alphabet, shadow reserved keyword etc.) via @"" syntax. See [https://ziglang.org/documentation/0.10.1/#Identifiers this] page from language reference.
 
<syntaxhighlight lang="zig">const std = @import("std");
 
pub fn main() void {
var @"Δ": i32 = 1;
@"Δ" += 1;
std.debug.print("{d}\n", .{@"Δ"});
}</syntaxhighlight>
 
{{out}}
9,477

edits