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

2020-09-14 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 15 September 2020 at 02:23:31 UTC, Paul Backus wrote: 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 m

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

2020-09-14 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 14, 2020 at 09:49:13PM -0400, James Blachly via Digitalmars-d-learn 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

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

2020-09-14 Thread Paul Backus 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.

Why is BOM required to use unicode in tokens?

2020-09-14 Thread James Blachly via Digitalmars-d-learn
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. It is not apparently easy to insert such marks (AFAICT no common tool

Re: default arguments for const ref parameters in extern C++ functions

2020-09-14 Thread Mathias LANG via Digitalmars-d-learn
On Monday, 14 September 2020 at 18:58:44 UTC, 60rntogo wrote: On Monday, 14 September 2020 at 17:11:59 UTC, k2aj wrote: AFAIK the only way to have default ref arguments is to use a global variable: --- extern(C++) struct Foo { int x; } immutable foo1 = Foo(1); extern(C++) void fun(const ref F

Re: default arguments for const ref parameters in extern C++ functions

2020-09-14 Thread 60rntogo via Digitalmars-d-learn
On Monday, 14 September 2020 at 17:11:59 UTC, k2aj wrote: AFAIK the only way to have default ref arguments is to use a global variable: --- extern(C++) struct Foo { int x; } immutable foo1 = Foo(1); extern(C++) void fun(const ref Foo foo = foo1); --- Thanks. This appears to work, but feels l

Re: default arguments for const ref parameters in extern C++ functions

2020-09-14 Thread k2aj via Digitalmars-d-learn
On Monday, 14 September 2020 at 12:44:34 UTC, 60rntogo wrote: I'm trying to use a C++ library that has a function declared like this: --- struct Foo { int x; }; void fun(const Foo& foo = Foo(1)); --- I have translated this to a D declaration: --- struct Foo { int x; } extern(C++) void f

Re: Newbie question: Return a locally allocated variable

2020-09-14 Thread Fitz via Digitalmars-d-learn
On Monday, 14 September 2020 at 16:44:14 UTC, Adam D. Ruppe wrote: This is a common mistake with people coming from C++. A D class is more like a Java class - it is automatically a reference. So your class Bob here in D would actually be represented as `Bob*` in C++. Thus when you define `B

Re: Newbie question: Return a locally allocated variable

2020-09-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 14 September 2020 at 16:29:11 UTC, Fitz wrote: I expect the following code below to create 10 items with 10 different addresses, instead they all have the same address? You are taking the address of the local variable holding reference, not the reference itself. class Bob { } Bo

Newbie question: Return a locally allocated variable

2020-09-14 Thread Fitz via Digitalmars-d-learn
I expect the following code below to create 10 items with 10 different addresses, instead they all have the same address? import std.stdio; class Bob { } void main() { for (auto i = 0; i < 10; i++) { auto pBob = bobFactory(); writefln("bob @ %x\n", pBob); } } Bob *bobF

Re: Red-Black Gauss-seidel with mir

2020-09-14 Thread 9il via Digitalmars-d-learn
On Monday, 14 September 2020 at 09:50:16 UTC, Christoph wrote: Hi Ilya, On Sunday, 13 September 2020 at 19:29:31 UTC, 9il wrote: [...] I have tested it with dmd and ldc and called them just with $ dub build --compiler=ldc(dmd) with no more configurations in the dub.json file. [...] On Mond

Re: default arguments for const ref parameters in extern C++ functions

2020-09-14 Thread 60rntogo via Digitalmars-d-learn
On Monday, 14 September 2020 at 12:44:34 UTC, 60rntogo wrote: --- struct Foo { int x; } extern(C++) void fun(const ref Foo foo = Foo(1)); --- I suppose this should have been: --- extern(C++): struct Foo { int x; } void fun(const ref Foo foo = Foo(1)); --- Not that it changes the questi

default arguments for const ref parameters in extern C++ functions

2020-09-14 Thread 60rntogo via Digitalmars-d-learn
I'm trying to use a C++ library that has a function declared like this: --- struct Foo { int x; }; void fun(const Foo& foo = Foo(1)); --- I have translated this to a D declaration: --- struct Foo { int x; } extern(C++) void fun(const ref Foo foo = Foo(1)); --- This yields an error: "Foo

Re: A function to split a range into several ranges of different chunks

2020-09-14 Thread Andrej Mitrovic via Digitalmars-d-learn
On Monday, 14 September 2020 at 09:08:01 UTC, Seb wrote: You likely want to get involved / raise your support here: https://github.com/dlang/phobos/pull/7600 Oh this is great, thank you!

Re: Get enum value name as string at compile time?

2020-09-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/14/20 2:25 AM, Simen Kjærås wrote: On Monday, 14 September 2020 at 03:48:51 UTC, Steven Schveighoffer wrote: Consider the enum: enum Foo { a, b } Foo.a.stringof => "a" enum x = Foo.a; x.stringof => "cast(Foo)0" Is there another way I can take an enum value that's known at compile time (

Re: Red-Black Gauss-seidel with mir

2020-09-14 Thread Christoph via Digitalmars-d-learn
Hi Ilya, On Sunday, 13 September 2020 at 19:29:31 UTC, 9il wrote: More details are required. What compiler and command line has been used? I have tested it with dmd and ldc and called them just with $ dub build --compiler=ldc(dmd) with no more configurations in the dub.json file. I have compa

Re: A function to split a range into several ranges of different chunks

2020-09-14 Thread Seb via Digitalmars-d-learn
On Monday, 14 September 2020 at 07:49:31 UTC, Andrej Mitrovic wrote: - import std.range; import std.stdio; void main () { auto range = sequence!((a, n) => n); // works, but the chunks are all the same length auto rngs = range.chunks(4); writeln(rngs[0]); writeln(rngs[1])

A function to split a range into several ranges of different chunks

2020-09-14 Thread Andrej Mitrovic via Digitalmars-d-learn
- import std.range; import std.stdio; void main () { auto range = sequence!((a, n) => n); // works, but the chunks are all the same length auto rngs = range.chunks(4); writeln(rngs[0]); writeln(rngs[1]); writeln(rngs[2]); // want this auto ranges = range.???(