Non-English characters in code - "character 0x2212 is not a valid token"
sigod via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jan 28 06:39:46 PST 2016
On Thursday, 28 January 2016 at 13:26:27 UTC, Andrea Fontana
wrote:
> On Thursday, 28 January 2016 at 13:18:55 UTC, pineapple wrote:
>> I experimented with using the character 'ħ' in a variable
>> name, and wasn't terribly surprised when the compiler didn't
>> like it. What did surprise me is that I still got a compile
>> error even when the character was in a comment. Is there any
>> way to make dmd not get fussy about unicode?
>
> Hmmm it's strange: I think d should support unicode on both
> comment and vars name.
>
> This code works for me ;)
>
> float distance(T)(T from, T to)
> {
> import std.math;
>
> auto toRadians = (float dec) => dec/180.0f*PI;
>
> auto R = 6371;
> auto φ1 = toRadians(from.lat);
> auto φ2 = toRadians(to.lat);
> auto Δφ = toRadians(to.lat-from.lat);
> auto Δλ = toRadians(to.lng-from.lng);
>
> float a = sin(Δφ/2) * sin(Δφ/2) + cos(φ1) * cos(φ2) *
> sin(Δλ/2) * sin(Δλ/2);
> float c = 2 * atan2(sqrt(a), sqrt(1-a));
>
> return R * c;
>
> }
What compiler version do you use?
I tried to compile your code on dpaste (2.070.0) and got this:
/d213/f100.d(8): Error: character '\' is not a valid token
/d213/f100.d(9): Error: character '\' is not a valid token
/d213/f100.d(10): Error: character '\' is not a valid token
/d213/f100.d(10): Error: character '\' is not a valid token
/d213/f100.d(11): Error: character '\' is not a valid token
/d213/f100.d(11): Error: character '\' is not a valid token
/d213/f100.d(13): Error: character '\' is not a valid token
/d213/f100.d(13): Error: character '\' is not a valid token
/d213/f100.d(13): Error: found 'u03c6' when expecting ','
/d213/f100.d(13): Error: expression expected, not '/'
/d213/f100.d(13): Error: found '2' when expecting ','
/d213/f100.d(13): Error: character '\' is not a valid token
/d213/f100.d(13): Error: character '\' is not a valid token
/d213/f100.d(13): Error: found 'u03c6' when expecting ','
/d213/f100.d(13): Error: expression expected, not '/'
/d213/f100.d(13): Error: found '2' when expecting ','
/d213/f100.d(13): Error: character '\' is not a valid token
/d213/f100.d(13): Error: character '\' is not a valid token
/d213/f100.d(13): Error: character '\' is not a valid token
/d213/f100.d(13): Error: character '\' is not a valid token
More information about the Digitalmars-d-learn
mailing list