Re: Create alias of same name in inner scope, bug or feature?

2021-08-14 Thread user1234 via Digitalmars-d-learn
On Saturday, 14 August 2021 at 04:09:34 UTC, Tejas wrote: [...] Oh right, the ```.``` operator will reference variable in the _module_ scope, not just the _immediate outer scope_, you can use the module name to disambiguate as well. To extend Mike answer, the general rule is that if you can d

Re: How to extend the string class to return this inside the square bracket?

2021-08-14 Thread user1234 via Digitalmars-d-learn
On Friday, 13 August 2021 at 23:33:05 UTC, Paul Backus wrote: On Friday, 13 August 2021 at 23:23:55 UTC, Marcone wrote: writeln("Hello World!"[x.indexOf("e")..x.indexOf("r")]); indexOf()is just a simple example, not the goal. I want handle literal inside [] like it bellow, but in literal: s

partial initialization of fixed size ("static") arrays

2021-08-14 Thread kdevel via Digitalmars-d-learn
Today I stumbled across three issues with partial initialization of "static" arrays: ~~~i1.d void main () { char [7] b = [ 1: 'x' ]; // okay char [7] a = [ 0: 'x' ]; // i1.d(4): Error: mismatched array lengths, 7 and 1 } ~~~ ~~~i2.d import std.stdio; void main () { char [7] c7 = [ 1

Re: Create alias of same name in inner scope, bug or feature?

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 08:23:20 UTC, user1234 wrote: On Saturday, 14 August 2021 at 04:09:34 UTC, Tejas wrote: [...] Oh right, the ```.``` operator will reference variable in the _module_ scope, not just the _immediate outer scope_, you can use the module name to disambiguate as well.

Drawbacks of exceptions being globally allocated

2021-08-14 Thread Tejas via Digitalmars-d-learn
What is the drawback of the following "simple" ```@nogc``` exception creation technique? ```d import std; void main()@nogc { try{ __gshared a = new Exception("help"); scope b = a; throw b; } catch(Exception e){ printf("caught"); } } ```

Re: partial initialization of fixed size ("static") arrays

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 09:40:54 UTC, kdevel wrote: Today I stumbled across three issues with partial initialization of "static" arrays: ~~~i1.d void main () { char [7] b = [ 1: 'x' ]; // okay char [7] a = [ 0: 'x' ]; // i1.d(4): Error: mismatched array lengths, 7 and 1 } ~~~ ~~

Re: partial initialization of fixed size ("static") arrays

2021-08-14 Thread frame via Digitalmars-d-learn
On Saturday, 14 August 2021 at 09:40:54 UTC, kdevel wrote: Shall I file them to bugzilla? I would say case 2 and 3 are not bugs. It's just the element type conversion and mismatched lengths of the ranges. Not sure about the first one.

Re: partial initialization of fixed size ("static") arrays

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 13:01:13 UTC, frame wrote: On Saturday, 14 August 2021 at 09:40:54 UTC, kdevel wrote: Shall I file them to bugzilla? I would say case 2 and 3 are not bugs. It's just the element type conversion and mismatched lengths of the ranges. Not sure about the first on

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 11:41:36 UTC, Tejas wrote: What is the drawback of the following "simple" ```@nogc``` exception creation technique? ```d import std; void main()@nogc { try{ __gshared a = new Exception("help"); scope b = a; throw b; } catch(Exce

Re: partial initialization of fixed size ("static") arrays

2021-08-14 Thread kdevel via Digitalmars-d-learn
On Saturday, 14 August 2021 at 13:01:13 UTC, frame wrote: I would say case [...] 3 is not [a bug]. It's just the element type conversion and mismatched lengths of the ranges. ~~~ char [7] d7 = "x"; // okay string s = "x"; char [7] c7 = s; // throws RangeError ~~~ What justifies that

Re: partial initialization of fixed size ("static") arrays

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 14:04:47 UTC, kdevel wrote: On Saturday, 14 August 2021 at 13:01:13 UTC, frame wrote: I would say case [...] 3 is not [a bug]. It's just the element type conversion and mismatched lengths of the ranges. ~~~ char [7] d7 = "x"; // okay string s = "x"; cha

Re: partial initialization of fixed size ("static") arrays

2021-08-14 Thread kdevel via Digitalmars-d-learn
On Saturday, 14 August 2021 at 14:18:57 UTC, Tejas wrote: On Saturday, 14 August 2021 at 14:04:47 UTC, kdevel wrote: On Saturday, 14 August 2021 at 13:01:13 UTC, frame wrote: I would say case [...] 3 is not [a bug]. It's just the element type conversion and mismatched lengths of the ranges. ~

Re: partial initialization of fixed size ("static") arrays

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 14:33:42 UTC, kdevel wrote: On Saturday, 14 August 2021 at 14:18:57 UTC, Tejas wrote: On Saturday, 14 August 2021 at 14:04:47 UTC, kdevel wrote: On Saturday, 14 August 2021 at 13:01:13 UTC, frame wrote: I would say case [...] 3 is not [a bug]. It's just the eleme

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Alexandru Ermicioi via Digitalmars-d-learn
On Saturday, 14 August 2021 at 13:24:22 UTC, Tejas wrote: ... I don't think there are any gotchas here. The problem with this technique, is when your exceptions aren't just simple labels but also carry some additional data, say for example specific error type, and subject that, caused this.

Re: How to extend the string class to return this inside the square bracket?

2021-08-14 Thread Marcone via Digitalmars-d-learn
On Saturday, 14 August 2021 at 08:24:41 UTC, user1234 wrote: On Friday, 13 August 2021 at 23:33:05 UTC, Paul Backus wrote: On Friday, 13 August 2021 at 23:23:55 UTC, Marcone wrote: writeln("Hello World!"[x.indexOf("e")..x.indexOf("r")]); indexOf()is just a simple example, not the goal. I want

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 15:28:36 UTC, Alexandru Ermicioi wrote: On Saturday, 14 August 2021 at 13:24:22 UTC, Tejas wrote: ... I don't think there are any gotchas here. The problem with this technique, is when your exceptions aren't just simple labels but also carry some additional dat

Re: partial initialization of fixed size ("static") arrays

2021-08-14 Thread frame via Digitalmars-d-learn
On Saturday, 14 August 2021 at 14:04:47 UTC, kdevel wrote: On Saturday, 14 August 2021 at 13:01:13 UTC, frame wrote: I would say case [...] 3 is not [a bug]. It's just the element type conversion and mismatched lengths of the ranges. ~~~ char [7] d7 = "x"; // okay string s = "x"; cha

Looping over Template Types ... possible?

2021-08-14 Thread james.p.leblanc via Digitalmars-d-learn
Good Evening/Day, Suppose I have a number of function templates that each take two types, say S and T. I would like to exercise my routines over the combinations of types: set of all S: ( double[], float[], Complex!double[], Complex!float[]) set of all T: ( double, float) Is something alon

Re: Looping over Template Types ... possible?

2021-08-14 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 14 August 2021 at 20:07:21 UTC, james.p.leblanc wrote: Good Evening/Day, Suppose I have a number of function templates that each take two types, say S and T. I would like to exercise my routines over the combinations of types: set of all S: ( double[], float[], Complex!double[],

Re: Looping over Template Types ... possible?

2021-08-14 Thread james.p.leblanc via Digitalmars-d-learn
On Saturday, 14 August 2021 at 20:20:01 UTC, Stefan Koch wrote: On Saturday, 14 August 2021 at 20:07:21 UTC, james.p.leblanc wrote: mes it is possible look for `AliasSeq` in `std.meta` foreach(T; AliasSeq!(float, double)) { ... } Stefan, Thanks very much for your help here ... I had no

Re: Anyway to achieve the following

2021-08-14 Thread Carl Sturtivant via Digitalmars-d-learn
``` struct S { int x = 1234; } void main() { import std.stdio; S s; //construction of a using &(s.x) auto a = Ref!(int)(&s.x); writeln(a); //displays 1234 s.x += 1; writeln(a); //displays 1235 a += 1; writeln(s.x); //displays 1236 } struct Ref(T) { T* ptr; this(T*

Re: partial initialization of fixed size ("static") arrays

2021-08-14 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 14 August 2021 at 14:04:47 UTC, kdevel wrote: ~~~ char [7] d7 = "x"; // okay string s = "x"; char [7] c7 = s; // throws RangeError ~~~ What justifies that the compiler behaves differently on two terms ('s', '"x"') which are of equal size, type, length and value? Litera

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 14 August 2021 at 15:58:17 UTC, Tejas wrote: If you're willing to help further, would you please tell me why there is a GC allocation in the code below that uses ```emplace```? Will such code truly work if GC is never linked in the program? https://run.dlang.io/is/XEc2WJ ``` onl

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Ali Çehreli via Digitalmars-d-learn
On 8/14/21 4:41 AM, Tejas wrote: > What is the drawback of the following "simple" ```@nogc``` exception > creation technique? > > ```d > import std; > void main()@nogc > { > try{ > __gshared a = new Exception("help"); > scope b = a; > throw b; > } > catch

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 23:14:51 UTC, Paul Backus wrote: On Saturday, 14 August 2021 at 15:58:17 UTC, Tejas wrote: If you're willing to help further, would you please tell me why there is a GC allocation in the code below that uses ```emplace```? Will such code truly work if GC is never

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 00:15:32 UTC, Ali Çehreli wrote: On 8/14/21 4:41 AM, Tejas wrote: > [...] exception > [...] So, there would be many exception objects one for each place that an exception can be thrown. Functions like enforce() would have to take a reference to the exception objec

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 02:09:08 UTC, Tejas wrote: On Sunday, 15 August 2021 at 00:15:32 UTC, Ali Çehreli wrote: On 8/14/21 4:41 AM, Tejas wrote: > [...] exception > [...] So, there would be many exception objects one for each place that an exception can be thrown. Functions like enforce

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Mathias LANG via Digitalmars-d-learn
On Sunday, 15 August 2021 at 02:09:08 UTC, Tejas wrote: On Sunday, 15 August 2021 at 00:15:32 UTC, Ali Çehreli wrote: On 8/14/21 4:41 AM, Tejas wrote: > [...] exception > [...] So, there would be many exception objects one for each place that an exception can be thrown. Functions like enforce

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 03:45:07 UTC, Mathias LANG wrote: On Sunday, 15 August 2021 at 02:09:08 UTC, Tejas wrote: [...] You can't really have `@nogc` allocated Exception without circumventing the type system. Personally I gave up on `@nogc` just because of how inconvenient it is. [...

What exactly are the String literrals in D and how they work?

2021-08-14 Thread rempas via Digitalmars-d-learn
So when I'm doing something like the following: `string name = "John";` Then what's the actual type of the literal `"John"`? In the chapter [Calling C functions](https://dlang.org/spec/interfaceToC.html#calling_c_functions) in the "Interfacing with C" page, the following is said: Strings are not