Non-English characters in code - "character 0x2212 is not a valid token"

Andrea Fontana via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jan 28 05:26:27 PST 2016


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;

       }


More information about the Digitalmars-d-learn mailing list