Re: What is difference between struct and class?

2019-06-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, June 2, 2019 9:40:43 PM MDT Rnd via Digitalmars-d-learn wrote: > On Monday, 3 June 2019 at 00:47:27 UTC, Adam D. Ruppe wrote: > > On Monday, 3 June 2019 at 00:17:08 UTC, Rnd wrote: > >> What additional features do classes offer in D? > > > > Classes support built-in runtime polymorphism

Re: What is difference between struct and class?

2019-06-02 Thread Rnd via Digitalmars-d-learn
On Monday, 3 June 2019 at 00:47:27 UTC, Adam D. Ruppe wrote: On Monday, 3 June 2019 at 00:17:08 UTC, Rnd wrote: What additional features do classes offer in D? Classes support built-in runtime polymorphism through inheritance. structs don't. As a result of this, classes are a little bit hea

Re: What is difference between struct and class?

2019-06-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 3 June 2019 at 00:17:08 UTC, Rnd wrote: What additional features do classes offer in D? Classes support built-in runtime polymorphism through inheritance. structs don't. As a result of this, classes are a little bit heavier resource-wise and are semantically always object referen

What is difference between struct and class?

2019-06-02 Thread Rnd via Digitalmars-d-learn
I see that struct can have data as well as member functions and instances can be created. So they sound like classes only. What additional features do classes offer in D?

Re: import and call

2019-06-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 2 June 2019 at 19:38:11 UTC, Amex wrote: I thought importing single functions were suppose to be faster. Am I wrong? That is wrong. Importing is always done of the whole module. All the `: func` thing does is limit the things introduced to the namespace.

Re: Very simple null reference escape

2019-06-02 Thread Basile B. via Digitalmars-d-learn
On Sunday, 2 June 2019 at 07:55:27 UTC, Amex wrote: A.B If A is null, crash. A?.B : writeln("HAHA"); No crash, ignored, equivalent to if (A is null) writeln("HAHA"); else A.B; safeAccess from iz does this : https://github.com/Basile-z/iz/blob/master/import/iz/sugar.d#L1666

Re: import and call

2019-06-02 Thread Basile B. via Digitalmars-d-learn
On Sunday, 2 June 2019 at 19:38:11 UTC, Amex wrote: Tired of having to import a single function to call it. Since mod.foo(x); doesn't work since mod is not defined. we have to do import mod : foo; foo(x); Why not mod:foo(x)? or mod#foo(x) or mod@foo(x) or whatever Reduces 50% of the

Re: 'version'-based code selection

2019-06-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, June 2, 2019 11:43:09 AM MDT Anonymouse via Digitalmars-d-learn wrote: > On Saturday, 1 June 2019 at 07:46:40 UTC, Jonathan M Davis wrote: > > For the most part though, you don't declare your own version > > identifiers. It sometimes makes sense, but usually, version > > identifiers are

Re: Very simple null reference escape

2019-06-02 Thread Amex via Digitalmars-d-learn
On Sunday, 2 June 2019 at 14:37:48 UTC, Paul Backus wrote: On Sunday, 2 June 2019 at 07:55:27 UTC, Amex wrote: A.B If A is null, crash. A?.B : writeln("HAHA"); No crash, ignored, equivalent to if (A is null) writeln("HAHA"); else A.B; The "optional" package on dub [1] has a .dispatch metho

Error: module `M.Q` from file M\Q.d conflicts with another module Q from file M\Q.d

2019-06-02 Thread Amex via Digitalmars-d-learn
main.d(217): Error: module `M.Q` from file M\Q.d conflicts with another module Q from file M\Q.d the line is simply import Q : foo; the problem is that it should have been import M.Q : foo; There is no module Q. The error message is in error! There is no other module. the module is named

import and call

2019-06-02 Thread Amex via Digitalmars-d-learn
Tired of having to import a single function to call it. Since mod.foo(x); doesn't work since mod is not defined. we have to do import mod : foo; foo(x); Why not mod:foo(x)? or mod#foo(x) or mod@foo(x) or whatever Reduces 50% of the lines and reduces the import symbol. I realize tha

Re: hasElaborateCopyConstructor bug?

2019-06-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, June 2, 2019 1:29:22 PM MDT Jonathan M Davis via Digitalmars-d- learn wrote: > On Sunday, June 2, 2019 8:32:16 AM MDT Paul Backus via Digitalmars-d-learn > wrote: > > On Sunday, 2 June 2019 at 06:59:02 UTC, Jonathan M Davis wrote: > > > Almost certainly, hasElaborateCopyConstructor shoul

Re: hasElaborateCopyConstructor bug?

2019-06-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, June 2, 2019 8:32:16 AM MDT Paul Backus via Digitalmars-d-learn wrote: > On Sunday, 2 June 2019 at 06:59:02 UTC, Jonathan M Davis wrote: > > Almost certainly, hasElaborateCopyConstructor should be updated > > to test for both postblit constructors and copy constructors, > > since its pu

Re: What does ! Stand for in map! and filter! function calls?

2019-06-02 Thread Dennis via Digitalmars-d-learn
On Sunday, 2 June 2019 at 16:39:57 UTC, Rnd wrote: Is it not possible in the language to have template map function also to called as map(x=>... ? That would be slower, and std.algorithm generally disallows easy but slow functions. In Java, you can sort a linked list. In D, sort requires an

Re: 'version'-based code selection

2019-06-02 Thread Anonymouse via Digitalmars-d-learn
On Saturday, 1 June 2019 at 07:46:40 UTC, Jonathan M Davis wrote: For the most part though, you don't declare your own version identifiers. It sometimes makes sense, but usually, version identifiers are used for versioning code based on the platform or architecture that it's compiled on. They'r

Re: What does ! Stand for in map! and filter! function calls?

2019-06-02 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 2 June 2019 at 16:39:57 UTC, Rnd wrote: Is it not possible in the language to have template map function also to called as map(x=>... ? This will reduce complexity which will attract more people to this language. Easy languages have great mass appeal as has been shown with Ruby

Re: What does ! Stand for in map! and filter! function calls?

2019-06-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 2 June 2019 at 16:39:57 UTC, Rnd wrote: Is it not possible in the language to have template map function also to called as map(x=>... ? It could be done pretty easily, but you will have to learn what template arguments are eventually anyway. You'll see this pattern all over, like `

Re: What does ! Stand for in map! and filter! function calls?

2019-06-02 Thread Rnd via Digitalmars-d-learn
On Sunday, 2 June 2019 at 15:55:46 UTC, Paul Backus wrote: On Sunday, 2 June 2019 at 15:48:54 UTC, Rnd wrote: I have recently started using Dlang, hence this basic question. Thanks for your insight. map and filter are templates in D, and !(...) is D's syntax for passing arguments to templates

Re: What does ! Stand for in map! and filter! function calls?

2019-06-02 Thread Cym13 via Digitalmars-d-learn
On Sunday, 2 June 2019 at 15:48:54 UTC, Rnd wrote: I have recently started using Dlang, hence this basic question. Thanks for your insight. To know more about D you should take the time to do the D tour [1] which provides you with general knowledge of most of D's functionalities and vocabular

Re: What does ! Stand for in map! and filter! function calls?

2019-06-02 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 2 June 2019 at 15:48:54 UTC, Rnd wrote: I have recently started using Dlang, hence this basic question. Thanks for your insight. map and filter are templates in D, and !(...) is D's syntax for passing arguments to templates: map!(x => x*x)([1, 2, 3, 4, 5]) ^ ^ |

What does ! Stand for in map! and filter! function calls?

2019-06-02 Thread Rnd via Digitalmars-d-learn
I have recently started using Dlang, hence this basic question. Thanks for your insight.

Re: hasElaborateCopyConstructor bug?

2019-06-02 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 2 June 2019 at 14:44:47 UTC, H. S. Teoh wrote: On Sun, Jun 02, 2019 at 02:32:16PM +, Paul Backus via Digitalmars-d-learn wrote: [...] If std.v2 ever materializes, we'll have an opportunity to fix papercuts like this. Until then, my preferred workaround is to use a renaming import

Re: hasElaborateCopyConstructor bug?

2019-06-02 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jun 02, 2019 at 02:32:16PM +, Paul Backus via Digitalmars-d-learn wrote: [...] > If std.v2 ever materializes, we'll have an opportunity to fix > papercuts like this. Until then, my preferred workaround is to use a > renaming import: > > import std.traits: hasNontrivialCopy = hasElabor

Re: Very simple null reference escape

2019-06-02 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 2 June 2019 at 07:55:27 UTC, Amex wrote: A.B If A is null, crash. A?.B : writeln("HAHA"); No crash, ignored, equivalent to if (A is null) writeln("HAHA"); else A.B; The "optional" package on dub [1] has a .dispatch method that does this: auto d = some(A()); // Dispatc

Re: hasElaborateCopyConstructor bug?

2019-06-02 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 2 June 2019 at 06:59:02 UTC, Jonathan M Davis wrote: Almost certainly, hasElaborateCopyConstructor should be updated to test for both postblit constructors and copy constructors, since its purpose is to test for whether the type has a user-defined copying function [...] Whether hasE

Re: Reading .pem files for secured

2019-06-02 Thread Dukc via Digitalmars-d-learn
On Friday, 31 May 2019 at 12:17:14 UTC, Sebastiaan Koppe wrote: Just base64 decode the PEM data (without the ) and feed it to RSA.this(ubyte[] publicKey). Ought to be that simple. I assume the same should apply with private key and private key constructor (along with a random password of c

Re: Reading .pem files for secured

2019-06-02 Thread Dukc via Digitalmars-d-learn
On Friday, 31 May 2019 at 12:17:14 UTC, Sebastiaan Koppe wrote: Just base64 decode the PEM data (without the ) and feed it to RSA.this(ubyte[] publicKey). Ought to be that simple. That's logic of SSL? Okay, I'll try that first.

Re: How to create an overwriteable struct that is always const?

2019-06-02 Thread David Zhang via Digitalmars-d-learn
Ah, fair enough.

Re: 'version'-based code selection

2019-06-02 Thread Yatheendra via Digitalmars-d-learn
On Saturday, 1 June 2019 at 07:46:40 UTC, Jonathan M Davis wrote: Like static ifs, version statements are completely a compile-time construct and having nothing to do with runtime beyond how they affect the code that's generated. ... - Jonathan M Davis Thanks for taking the time. That's it

Re: How to create an overwriteable struct that is always const?

2019-06-02 Thread ag0aep6g via Digitalmars-d-learn
On 02.06.19 04:22, David Zhang wrote: On Saturday, 1 June 2019 at 13:00:50 UTC, ag0aep6g wrote: How is setting/replacing different from modifying? e.g.:     S s;     this() { s = ...; }     update(S s) { this.s = s; }     mod(int i) { s.i = i; } // illegal Kinda like how strings can

Very simple null reference escape

2019-06-02 Thread Amex via Digitalmars-d-learn
A.B If A is null, crash. A?.B : writeln("HAHA"); No crash, ignored, equivalent to if (A is null) writeln("HAHA"); else A.B;

Re: hasElaborateCopyConstructor bug?

2019-06-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, June 1, 2019 5:29:08 PM MDT SrMordred via Digitalmars-d-learn wrote: > On Saturday, 1 June 2019 at 21:39:33 UTC, SImen Kjærås wrote: > > On Saturday, 1 June 2019 at 21:05:32 UTC, SrMordred wrote: > > > > hasElaborateCopyConstructor checks if the type defines a > > postblit[0]. > > Y