Re: Why is BOM required to use unicode in tokens?

2020-09-16 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 00:22:15 UTC, Steven Schveighoffer wrote: Someone should verify that the character you want to use for a symbol name is actually considered a letter or not. Using phobos to prove this is kind of self-defeating, as I'm pretty sure it would be in league with

Why does compose from std.functional return a templated function

2020-09-16 Thread Jan Hönig via Digitalmars-d-learn
I have toyed with the compose template in std.functional and ran into some problems. rikki_cattermole on discord helped me a lot to solve my problem. However, what still remains (for me) to understand is why. Source code for `compose`:

Re: get element index when using each!(x)

2020-09-16 Thread dangbinghoo via Digitalmars-d-learn
On Thursday, 17 September 2020 at 03:16:42 UTC, Paul Backus wrote: On Thursday, 17 September 2020 at 03:14:08 UTC, JG wrote: Perhaps there are other ways, but you can use enumerate. For example --- import std.algorithm; import std.range; import std.stdio; void main() { string s =

Re: Why does compose from std.functional return a templated function

2020-09-16 Thread Daniel Kozak via Digitalmars-d-learn
On Wed, Sep 16, 2020 at 12:00 PM Jan Hönig via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > ... > > My main question is why? Is there something, which I am missing, > that explains, why it is beneficial to return a templated > function? > > (maybe, because I might want to

Re: Why does compose from std.functional return a templated function

2020-09-16 Thread Jan Hönig via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 10:50:06 UTC, Daniel Kozak wrote: On Wed, Sep 16, 2020 at 12:00 PM Jan Hönig via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: ... My main question is why? Is there something, which I am missing, that explains, why it is beneficial to

Re: Why does compose from std.functional return a templated function

2020-09-16 Thread Daniel Kozak via Digitalmars-d-learn
On Wed, Sep 16, 2020 at 12:50 PM Daniel Kozak wrote: > > > On Wed, Sep 16, 2020 at 12:00 PM Jan Hönig via Digitalmars-d-learn < > digitalmars-d-learn@puremagic.com> wrote: > >> ... >> >> My main question is why? Is there something, which I am missing, >> that explains, why it is beneficial to

Re: Why does compose from std.functional return a templated function

2020-09-16 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 09:59:59 UTC, Jan Hönig wrote: I have toyed with the compose template in std.functional and ran into some problems. rikki_cattermole on discord helped me a lot to solve my problem. However, what still remains (for me) to understand is why. Source code for

Re: importing a symbol without specifying a subpackage name

2020-09-16 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 13:30:57 UTC, 60rntogo wrote: then saying "import foo : Bar;" yields an error "module foo is in file 'foo.d' which cannot be read". I'm curious, how is this behavior achieved in the standard library? To expand on Adam's reply:

Re: importing a symbol without specifying a subpackage name

2020-09-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 13:36:22 UTC, 60rntogo wrote: except that I tried doing this in foo.d and then the compiler yelled at me. Yeah, this is the one case where the compiler is picky about the directory structure and filename. It *must* be package.d. (blargh.)

Re: Why is BOM required to use unicode in tokens?

2020-09-16 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 07:38:26 UTC, Dominikus Dittes Scherkl wrote: We only need to define which properties a character need to be allowed in an identifier. I think the following change in the grammar would be sufficient: Identifier: IdentifierStart IdentifierStart

Re: importing a symbol without specifying a subpackage name

2020-09-16 Thread 60rntogo via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 13:33:34 UTC, Adam D. Ruppe wrote: They define an additional file std/package.d Thanks for a quick answer. I suspected it must have been something like that, except that I tried doing this in foo.d and then the compiler yelled at me.

Re: Why is BOM required to use unicode in tokens?

2020-09-16 Thread wjoe via Digitalmars-d-learn
On Tuesday, 15 September 2020 at 01:49:13 UTC, James Blachly wrote: I wish to write a function including ∂x and ∂y (these are trivial to type with appropriate keyboard shortcuts - alt+d on Mac), but without a unicode byte order mark at the beginning of the file, the lexer rejects the tokens.

Re: importing a symbol without specifying a subpackage name

2020-09-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 13:30:57 UTC, 60rntogo wrote: I'm curious, how is this behavior achieved in the standard library? They define an additional file std/package.d (and std/algorithm/package.d btw) that lists off module std; public import std.algorithm; public import

importing a symbol without specifying a subpackage name

2020-09-16 Thread 60rntogo via Digitalmars-d-learn
I have noticed that if I want to import std.algorithm.searching.find, each of the following will work: --- import std.algorithm.searching : find; import std.algorithm : find; import std : find; --- (Although, the last one is probably not the greatest idea.) However, if I write my own module:

Re: Building LDC runtime for a microcontroller

2020-09-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 17:59:41 UTC, Remi wrote: I tried to modify the hello.d example from your blog post. It works without changes but when I tried to do a string concatenation Yeah, concatenation is one of the features that uses druntime, and specifically, it is done through

Neater "not version (...)" ?

2020-09-16 Thread Vladimirs Nordholm via Digitalmars-d-learn
Hello. I wonder if there is a better way to compile something if the current operating system is _not_ a specific platform. For example, I only want some code to compile if the operating system is not Windows. Currently I do this: version (Windows) { } else { //

Re: Neater "not version (...)" ?

2020-09-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-16 19:53, Vladimirs Nordholm wrote: Hello. I wonder if there is a better way to compile something if the current operating system is _not_ a specific platform. For example, I only want some code to compile if the operating system is not Windows. Currently I do this:    

Re: Neater "not version (...)" ?

2020-09-16 Thread Dennis via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 19:04:24 UTC, Vladimirs Nordholm wrote: Ah, I guess it boils down to this then. Doesn't really make it "neater", but thank you for the tip! IMO, just keep it as `version(Windows) {} else { ... }` if you HAVE to instead of one of the workarounds people

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 17:12:47 UTC, Cecil Ward wrote: then is there any downside to just using enum all the time? For a non-string array, enum may give runtime allocations that static immutable won't. Generally think of enum as being replaced with the literal representation

Re: Neater "not version (...)" ?

2020-09-16 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 19:04:24 UTC, Vladimirs Nordholm wrote: On Wednesday, 16 September 2020 at 18:54:45 UTC, Jacob Carlborg wrote: version (Windows) enum windows = true; else enum windows = false; static if (!windows) { // ... my code } Ah, I guess it boils down to

Re: Neater "not version (...)" ?

2020-09-16 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 17:53:31 UTC, Vladimirs Nordholm wrote: Hello. I wonder if there is a better way to compile something if the current operating system is _not_ a specific platform. For example, I only want some code to compile if the operating system is not Windows.

enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-16 Thread Cecil Ward via Digitalmars-d-learn
A really stupid question, I fear. If I have some kind of declaration of some ‘variable’ whose value is strictly known at compile time and I do one of the following (rough syntax) either enum foo = bar; or const foo = bar; or immutable foo = bar; then is there any downside to just

Re: Building LDC runtime for a microcontroller

2020-09-16 Thread Remi via Digitalmars-d-learn
On Monday, 7 September 2020 at 22:13:20 UTC, Adam D. Ruppe wrote: On Monday, 7 September 2020 at 20:55:54 UTC, IGotD- wrote: I guess this was written before betterC existed. Well, -betterC existed even then, but it was *completely* useless. It didn't become useful until 2016 or 2017. But

Re: Neater "not version (...)" ?

2020-09-16 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 18:54:45 UTC, Jacob Carlborg wrote: On 2020-09-16 19:53, Vladimirs Nordholm wrote: Hello. I wonder if there is a better way to compile something if the current operating system is _not_ a specific platform. For example, I only want some code to compile if

Re: Neater "not version (...)" ?

2020-09-16 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 18:07:25 UTC, Ferhat Kurtulmuş wrote: On Wednesday, 16 September 2020 at 17:53:31 UTC, Vladimirs Nordholm wrote: Hello. I wonder if there is a better way to compile something if the current operating system is _not_ a specific platform. For example, I only

get element index when using each!(x)

2020-09-16 Thread dangbinghoo via Digitalmars-d-learn
hi, is there any way to get the index for an element when iteration using each!(x)? I know I can do this using foreach statement, but I prefer using the each template. --- string s = "hello"; foreach(i, c; s) { } -- how can I get to ? Thanks! binghoo dang

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-16 Thread Cecil Ward via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 17:19:13 UTC, Adam D. Ruppe wrote: On Wednesday, 16 September 2020 at 17:12:47 UTC, Cecil Ward wrote: then is there any downside to just using enum all the time? For a non-string array, enum may give runtime allocations that static immutable won't.

Re: get element index when using each!(x)

2020-09-16 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 17 September 2020 at 03:14:08 UTC, JG wrote: Perhaps there are other ways, but you can use enumerate. For example --- import std.algorithm; import std.range; import std.stdio; void main() { string s = "hello"; s.enumerate.each!(x=>writeln(x[0],":",x[1])); } Worth

Re: What kind of mangling has the LDC2 -X JsonFile "deco" field?

2020-09-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 17 September 2020 at 03:06:45 UTC, realhet wrote: I'm trying to get information from the JsonFile produced by LDC2, but having no clue how to decode this: For example: header: KeywordCat kwCatOf(int k) "deco" : "FAyaZE3het8keywords10KeywordCat", That's a D mangle but just of

Re: What kind of mangling has the LDC2 -X JsonFile "deco" field?

2020-09-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 17 September 2020 at 03:06:45 UTC, realhet wrote: Anyone can help me telling how to decode these please? so here's a cool trick to get hte other demanglers to help. Just prepend _D4name to the string. so like: $ ./ddemangle _D4nameFAyaZE3het8keywords10KeywordCat

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-16 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 17 September 2020 at 00:32:40 UTC, Cecil Ward So can the result of declaring certain things with enum ever have an _address_ then? (According to legit D code that is, never mind the underlying implementation details, which may not be observable) No. Think of it as a named

Re: get element index when using each!(x)

2020-09-16 Thread JG via Digitalmars-d-learn
On Thursday, 17 September 2020 at 00:51:54 UTC, dangbinghoo wrote: hi, is there any way to get the index for an element when iteration using each!(x)? I know I can do this using foreach statement, but I prefer using the each template. --- string s = "hello"; foreach(i, c; s) { }

What kind of mangling has the LDC2 -X JsonFile "deco" field?

2020-09-16 Thread realhet via Digitalmars-d-learn
Hello, I'm trying to get information from the JsonFile produced by LDC2, but having no clue how to decode this: For example: header: KeywordCat kwCatOf(int k) "deco" : "FAyaZE3het8keywords10KeywordCat", The "deco" field contains the full name of the return type het.keywords.KeywordCat,