Why not extend do to allow unicode in ID's?

Bert Bert at gmail.com
Sun Jun 30 23:27:56 UTC 2019


On Sunday, 30 June 2019 at 10:10:41 UTC, Dennis wrote:
> On Saturday, 29 June 2019 at 22:38:06 UTC, Bert wrote:
>> Imagine being able to write proper mathematical formula ID's:
>
> Currently D allows "universal alphas" in identifiers, so Greek 
> letters are allowed already. See: 
> https://dlang.org/spec/lex.html#identifiers
>
>> or using valid mathematical operators:
>
> In D you can't add operators, but if you want math notation on 
> existing ones, you might be interested in fonts with 
> programming ligatures such as:
> https://github.com/tonsky/FiraCode
>
>> or when you write a card game:
>
> Custom literals can be added with templates, for example:
> octal!377
> (https://github.com/dlang/phobos/blob/d57be4690fc923a1974a4ef4d8b84a951131d219/std/conv.d#L4062)
> tok!"if"
> (https://github.com/dlang-community/libdparse/blob/5270739bcd1962418784c7760773e24d28b6009b/src/dparse/lexer.d#L115)
>
> Since in strings any Unicode is allowed, you can do something 
> similar:
> suit!"♥"
>
>> I don't write any code that anyone else reads so let me make 
>> the choice for myself rather than create arbitrary rules that 
>> limit expressiveness.
>
> If it's only for yourself, you can add a build step that 
> substitutes your custom symbols with valid identifiers before 
> compiling. Or use your own fork of the compiler, you probably 
> only need to remove this line:
> https://github.com/dlang/dmd/blob/2599559d624275bfcff298b3a8b31f9d82ae534f/src/dmd/lexer.d#L524
>

Thanks. I guess I could create a small routine that hacks the 
binary that reverses the if check. This would be easiest to 
maintain as I woudln't have to recompile dmd every release, just 
install the new one and patch.

> Finally, if you truly long for ultimate freedom in how you 
> write code, then Nim might be the right language for you since 
> it aligns more with your "putting full trust in the programmer" 
> view than D. In Nim, any non-ascii character is valid for 
> identifiers, so even invalid Unicode characters are allowed.
> https://nim-lang.org/docs/manual.html#lexical-analysis-identifiers-amp-keywords


I've heard of nim but never really looked in to it much.... but 
every time I hear about it I am more and more enticed.

It seems well put together but the syntax is a little off 
putting. I'm sure I could get used to it.

I have a few questions:

1. There doesn't seem to be good IDE support. I mainly use Visual 
Studio and I see a nim for VSC which I don't use ;/  Is there any 
really good IDE support?

2. How does meta programming of Nim compare to D's? The main 
reason I use D is it's meta programming.

3. Nim seems to be have somewhat of a strong categorical and 
functional foundation. Is it more like Haskell than D? (In the 
sense of catering to strongly structured programming(functors, 
natural transformations, etc))



I'll try to read over the manual. Maybe my next program will be 
in Nim.


More information about the Digitalmars-d mailing list