Re: isSame/TemplateOf bug?
On 02/19/2019 03:21 PM, SrMordred wrote: > On Tuesday, 19 February 2019 at 23:03:37 UTC, Paul Backus wrote: >> Inside a templated struct, the name of the template, by itself, >> actually refers to the current instantiation. So when you write `Test` >> in your __traits(isSame) test, the compiler interprets it as `Test!T`. > > True! > writeln(Test.stringof) inside the struct give me Test!int. > > Thanks! > > Little unexpected D dark corner :P For reference, it is the same in C++. Ali
Re: How to create a class-valued variable?
On Tuesday, 19 February 2019 at 22:04:58 UTC, Victor Porton wrote: What is the right way to store in a structure a class (not an instance) derived from a given interface(s)? What are you trying to do with the "class"? If you just want a static "reference" to it you can use an `alias`: class A {} struct B { alias C = A; } new B.C(); If you want dynamic information on the type you can use TypeInfo: class A {} struct B { TypeInfo i; } B b; b.i = typeid(A); b.i.factory(); Or more simply if you just want to construct instances, just use a delegate: interface I {} class A : I {} struct B { I delegate() factory; } B b; b.factory = () => new A(); b.factory(); You *can't* do something like the following because types need to be validated at compile time: struct A { Class cls; } A a; a.cls b; b.run();
What is the impact of Tark wallet on global payments?
In the new era of rapid economic development, people's pursuit of quality of life is constantly improving. More and more people are beginning to pay attention to their quality of life. How to live better is also the goal of happiness that people pursue. At a time of rapid change, many new technologies are affecting people's quality of life. More and more new technologies have penetrated into people's daily lives, and gradually change people's lives. Among many of these new technologies, there is one technology that people are most concerned about and have the most promising development prospects. That is, blockchain technology, Tark wallet based on blockchain 4.0 technology to subvert people's modes of payment, today Let's look at how Tark Wallet contribute to global mobile payments. In recent years, with the continuous development of mobile payment, the traditional global payment in the actual sense has gradually moved away from people's lives, but global payments such as Alipay global payment, WeChat global payment, etc. have also emerged in every aspect of people's life one after another. But global payments on mobile payments are also realized through phisical currencies. Compared to these traditional global payments, the functions of blockchain's global payment and settlement system are unique. Tark Wallet is based on some applications of global payment projects in the development system of smart contract which based on blockchain 4.0 technology, constantly sprouting new vitality, breaking the traditional sense of global payment. Tark wallet breaks the traditional channel in the global payment system, enabling both parties to bypass the traditional banking system, establish a blockchain node between the major banks, and integrate the nodes, the global intelligent payment can be achieved more quickly and conveniently. Global payment of Tark wallet will be a timely and convenient new payment mode, and the open and efficient cross-border payment are no longer a problem.
AXC——Grasp the change of token market pattern of 2019
2017 is the most crazy year in the token market, and the price is so high that one coin is hard to get. However, such a good phenomenon has gradually declined in 2018 and even fluctuated and affected with the collapse of Bitcoin! At the same time, with the frequent problems of security risks arising from various countries’ token trading platform, these have caused a lot of negative impact on the token market! Many people have begun to panic about all kinds of tokens. In a flash, 2019 has come, can it become the turning point of the token market? And whether it can create a new opportunity for the coin circle and blockchain circle, time is the best witness! 2019 is a year that many people are optimistic about. Whether for the development of the token market or the regulation of the coin circle, we all think it is a new hope! After the token passing through one wave after another of great waves, it seems that there is the overall economic downturn, but neither the coin circle nor the blockchain circle is as scary as imagined. I can only say that ICO died in this baptism, but the token and blockchain did not die. I believe that after the clamour, everything will eventually return to the routine, and often the routine gives birth to value. Just as the once-noisy Internet did not fall completely after entering the "whirlpool of silence", a group of outstanding giants emerged, such as Google, Amazon and Yahoo. Therefore, the development of the token is still with full of expectations! AXC is a leader born in the downturn of the token market! AXC is based on the fourth-generation blockchain technology and has reached a new level in the development of the industry. Relying on the world-leading AtoX public blockchain system, the atomic cross-exchange technology is realized, and the security protocol for value exchange between different blockchains can be completed. The lightning network technology can be realized, and an infinite high-speed transaction can be realized on one blockchain; The technology of first entering database and then consensus is realized, the transaction of the database table is pre-executed in the database, and then sent to the blockchain network for consensus. Unlike Bitcoin's “mining” issuance mechanism, AXC uses the manner of delivery and purchase. AXC has the role of preventing malicious attacks and exchange media in AtoX. AtoX requires each account to have a certain amount of AXC. Each time a transaction is executed, 1/10 of AXC will be destroyed, which will increase the cost of the transaction to create massive false account for malicious attacks and prevent malicious attacks. In addition, any currency can be exchanged with AXC, and AXC has become a medium of exchange between currencies. In cross-border settlement applications, the AtoX network enables multi-currency cross-border payments through market maker mechanisms or AXC. Under the market maker mechanism, the market maker provides the currency exchange service for cross-border transfer through the account opened in the receiving and paying bank. AtoX will automatically select the lowest quotation among the many market makers in the network to minimize the cost of capital conversion. In addition, AXC as a medium currency, when the parties to the payment can not find a suitable market maker to complete the transaction, the currency can be converted into AXC for transaction, and the instant transfer can be realized. In 2019, there will be a new pattern in the token market, and AXC is a new hope for the majority of users to seize the opportunity of wealth!
Re: Error with matplotlib
On Tuesday, 19 February 2019 at 11:57:00 UTC, Andre Pany wrote: The python script generates a list of available functions in the python package. This list will be used to generate D coding at compilation time. That is the reason, the error occurs in a mixin. Unfortunately one function had the same name as a D keyword (it was the keyword deprecated). The fix was to exclude this function from the list. I think this is the only dub package working this way, as it might be the only package which wrapping python code. Thanks again for all of your help and explanations, Andre!
Re: isSame/TemplateOf bug?
On Tuesday, 19 February 2019 at 23:03:37 UTC, Paul Backus wrote: On Tuesday, 19 February 2019 at 22:43:25 UTC, SrMordred wrote: import std.traits; import std.stdio; struct Test(T) { this(T)( auto ref T value ) { writeln( TemplateOf!(typeof(value)).stringof); writeln( __traits(isSame, TemplateOf!(typeof(value)), Test) ); } } void main(){ auto value = Test!int(Test!int()); writeln( TemplateOf!(typeof(value)).stringof); writeln( __traits(isSame, TemplateOf!(typeof(value)), Test) ); } //output: Test(T) false Test(T) true Inside a templated struct, the name of the template, by itself, actually refers to the current instantiation. So when you write `Test` in your __traits(isSame) test, the compiler interprets it as `Test!T`. True! writeln(Test.stringof) inside the struct give me Test!int. Thanks! Little unexpected D dark corner :P
Re: isSame/TemplateOf bug?
On Tuesday, 19 February 2019 at 22:43:25 UTC, SrMordred wrote: import std.traits; import std.stdio; struct Test(T) { this(T)( auto ref T value ) { writeln( TemplateOf!(typeof(value)).stringof); writeln( __traits(isSame, TemplateOf!(typeof(value)), Test) ); } } void main(){ auto value = Test!int(Test!int()); writeln( TemplateOf!(typeof(value)).stringof); writeln( __traits(isSame, TemplateOf!(typeof(value)), Test) ); } //output: Test(T) false Test(T) true Inside a templated struct, the name of the template, by itself, actually refers to the current instantiation. So when you write `Test` in your __traits(isSame) test, the compiler interprets it as `Test!T`.
isSame/TemplateOf bug?
import std.traits; import std.stdio; struct Test(T) { this(T)( auto ref T value ) { writeln( TemplateOf!(typeof(value)).stringof); writeln( __traits(isSame, TemplateOf!(typeof(value)), Test) ); } } void main(){ auto value = Test!int(Test!int()); writeln( TemplateOf!(typeof(value)).stringof); writeln( __traits(isSame, TemplateOf!(typeof(value)), Test) ); } //output: Test(T) false Test(T) true
How to create a class-valued variable?
What is the right way to store in a structure a class (not an instance) derived from a given interface(s)?
Re: Windows Defender won't let me install DMD
On Monday, 18 February 2019 at 16:32:26 UTC, belkin wrote: Additional question as a beginner. What do I need to install to get started. Obviously I need a compiler (which one is best ). But I also want an IDE and so far it seems Visual D would be a best choice. Ideas? Visual D works well, as does Visual Studio Code with code-d plugin.
Re: Generators in D
On Tuesday, 19 February 2019 at 18:56:01 UTC, Paul Backus wrote: On Tuesday, 19 February 2019 at 18:37:22 UTC, Matthew_Blake wrote: Hi there, is the concept of generators (like in Python, using yield) available in D? If so, where can I find information? Regards Generally speaking, things that are generators in Python are implemented as ranges [1] in D. If ranges aren't a good fit for your problem, though, you can also use opApply [2] and std.concurrency.Generator [3]. [1] https://tour.dlang.org/tour/en/basics/ranges [2] https://dlang.org/spec/statement.html#foreach_over_struct_and_classes [3] https://dlang.org/phobos/std_concurrency.html#.Generator Thank you both! I'll look into it
Re: Generators in D
On Tuesday, 19 February 2019 at 18:37:22 UTC, Matthew_Blake wrote: Hi there, is the concept of generators (like in Python, using yield) available in D? If so, where can I find information? Regards Generally speaking, things that are generators in Python are implemented as ranges [1] in D. If ranges aren't a good fit for your problem, though, you can also use opApply [2] and std.concurrency.Generator [3]. [1] https://tour.dlang.org/tour/en/basics/ranges [2] https://dlang.org/spec/statement.html#foreach_over_struct_and_classes [3] https://dlang.org/phobos/std_concurrency.html#.Generator
Re: Generators in D
On Tuesday, 19 February 2019 at 18:37:22 UTC, Matthew_Blake wrote: Hi there, is the concept of generators (like in Python, using yield) available in D? If so, where can I find information? Regards I do not know python well, but do you search for this one? http://ddili.org/ders/d.en/fibers.html Kind regards Andre
Generators in D
Hi there, is the concept of generators (like in Python, using yield) available in D? If so, where can I find information? Regards
Re: How to convert `std.datetime.Duration` to seconds of floating point type?
19.02.2019 19:55, Alex пишет: On Tuesday, 19 February 2019 at 16:44:23 UTC, drug wrote: On 19.02.2019 19:35, Alex wrote: On Tuesday, 19 February 2019 at 16:26:33 UTC, drug wrote: Well, I understand that using floating point values to represent time internally is a bad idea and I totally agree. But some convenient API to convert Duration to floating point and vice versa would be useful because in mechanics for example you often need to express time in seconds with fractional part. In this regard std::chrono is more expressive (the only one though, in general std.datetime is much more powerful than std::chrono). If you need a real (double, float) parameter, just use it. Transport the units separately... Could you elaborate what you mean? ``` auto point = vec3(1.0, 2.0, 3.0); vec3 velocity = ...; auto t = dur!"msecs"(500); ... auto new_point = point + velocity * t.total!"msecs"/1e3; ``` How can I use a real parameter and transport units separately here? like ´´´ import std.datetime; void main() { import std.stdio; auto d = Data!"msecs"(); writeln(d.point); writeln(d.t); } struct Data(string units) { real[3] point = [1.0, 2.0, 3.0]; real[3] velocity = ...; auto t = dur!units(500); } ´´´ Well, your code is more heavy and less flexible than just using `total!"msecs"/1e3`. Sorry, but it's loosely coupled with my question.
Re: How to convert `std.datetime.Duration` to seconds of floating point type?
On Tuesday, 19 February 2019 at 16:44:23 UTC, drug wrote: On 19.02.2019 19:35, Alex wrote: On Tuesday, 19 February 2019 at 16:26:33 UTC, drug wrote: Well, I understand that using floating point values to represent time internally is a bad idea and I totally agree. But some convenient API to convert Duration to floating point and vice versa would be useful because in mechanics for example you often need to express time in seconds with fractional part. In this regard std::chrono is more expressive (the only one though, in general std.datetime is much more powerful than std::chrono). If you need a real (double, float) parameter, just use it. Transport the units separately... Could you elaborate what you mean? ``` auto point = vec3(1.0, 2.0, 3.0); vec3 velocity = ...; auto t = dur!"msecs"(500); ... auto new_point = point + velocity * t.total!"msecs"/1e3; ``` How can I use a real parameter and transport units separately here? like ´´´ import std.datetime; void main() { import std.stdio; auto d = Data!"msecs"(); writeln(d.point); writeln(d.t); } struct Data(string units) { real[3] point = [1.0, 2.0, 3.0]; real[3] velocity = ...; auto t = dur!units(500); } ´´´
Re: How to convert `std.datetime.Duration` to seconds of floating point type?
On 19.02.2019 19:35, Alex wrote: On Tuesday, 19 February 2019 at 16:26:33 UTC, drug wrote: Well, I understand that using floating point values to represent time internally is a bad idea and I totally agree. But some convenient API to convert Duration to floating point and vice versa would be useful because in mechanics for example you often need to express time in seconds with fractional part. In this regard std::chrono is more expressive (the only one though, in general std.datetime is much more powerful than std::chrono). If you need a real (double, float) parameter, just use it. Transport the units separately... Could you elaborate what you mean? ``` auto point = vec3(1.0, 2.0, 3.0); vec3 velocity = ...; auto t = dur!"msecs"(500); ... auto new_point = point + velocity * t.total!"msecs"/1e3; ``` How can I use a real parameter and transport units separately here?
Re: Best practices of using const
On 19.02.2019 19:19, Kagamin wrote: On Tuesday, 19 February 2019 at 15:30:22 UTC, Atila Neves wrote: I keep hearing how const is nigh unusable in D, and except for ranges I litter my code with const everywhere, pretty much just as often as I used in C++. I once spent a good amount of effort to annotate my code with pure and inout only to find a compiler bug, then I realized that annotations aren't really needed, because the collection is inherently mutable anyway (appender). I use const all over the place too. And I made PR to other libraries to add const qualifier. Yes, it sometimes forces me to make a copy of data to mutate it - but I'm pretty sure this is the purpose of the qualifier. This helps me to catch/prevent bug. So I don't agree with people who do not use const at all. Definitely const qualifier in D is usable and is useful. The same I can say about properties - for example I use them in meta programming to detect what to serialize/process - I skip methods but serialize properties and for me this is a nice language feature.
Re: How to convert `std.datetime.Duration` to seconds of floating point type?
On Tuesday, 19 February 2019 at 16:26:33 UTC, drug wrote: Well, I understand that using floating point values to represent time internally is a bad idea and I totally agree. But some convenient API to convert Duration to floating point and vice versa would be useful because in mechanics for example you often need to express time in seconds with fractional part. In this regard std::chrono is more expressive (the only one though, in general std.datetime is much more powerful than std::chrono). If you need a real (double, float) parameter, just use it. Transport the units separately...
Re: How to convert `std.datetime.Duration` to seconds of floating point type?
On 19.02.2019 18:07, Dennis wrote: On Tuesday, 19 February 2019 at 14:34:09 UTC, drug wrote: Now I do it this way (https://run.dlang.io/is/8kVibT): ``` auto some_duration = dur!"msecs"(500); auto seconds = some_duration.total!"hnsecs" / 10_000_000.0; assert(seconds.approxEqual(0.5)); ``` is there better way to do it? What you're doing now is the way to do it. This is by design, as Jonathan M. Davis explains: "In general, using floating point values with time is an incredibly bad idea. It can certainly make sense when printing stuff out, but using it in calculations is just asking for trouble given all of the unnecessary imprecision that it adds. So, Duration does not directly support floating point values at all, and that's very much on purpose. (...) And if you're just trying to print out the a duration as a floating point value, because it's nice to view that way, then that's fine, but you'll need to do the conversion yourself. And it's not that hard." https://forum.dlang.org/post/mailman.3711.1453121204.22025.digitalmars-d-le...@puremagic.com Well, I understand that using floating point values to represent time internally is a bad idea and I totally agree. But some convenient API to convert Duration to floating point and vice versa would be useful because in mechanics for example you often need to express time in seconds with fractional part. In this regard std::chrono is more expressive (the only one though, in general std.datetime is much more powerful than std::chrono).
Re: Best practices of using const
On Tuesday, 19 February 2019 at 15:30:22 UTC, Atila Neves wrote: I keep hearing how const is nigh unusable in D, and except for ranges I litter my code with const everywhere, pretty much just as often as I used in C++. I once spent a good amount of effort to annotate my code with pure and inout only to find a compiler bug, then I realized that annotations aren't really needed, because the collection is inherently mutable anyway (appender).
Re: Best practices of using const
On Wednesday, 13 February 2019 at 16:40:18 UTC, H. S. Teoh wrote: On Wed, Feb 13, 2019 at 11:32:46AM +, envoid via Digitalmars-d-learn wrote: [...] Const in D is very restrictive because it's supposed to provide real compiler guarantees, i.e., it's statically verifiable that the data cannot be changed. [...] I keep hearing how const is nigh unusable in D, and except for ranges I litter my code with const everywhere, pretty much just as often as I used in C++. I normally only use `auto` for return types and input ranges, and nearly all of my function parameters are `in`. It's true that a lot of people don't use `const` because I keep finding and filing bugs in dub libraries as soon as I try using them, but other than that: const is fine.
Re: How to convert `std.datetime.Duration` to seconds of floating point type?
On Tuesday, 19 February 2019 at 14:34:09 UTC, drug wrote: Now I do it this way (https://run.dlang.io/is/8kVibT): ``` auto some_duration = dur!"msecs"(500); auto seconds = some_duration.total!"hnsecs" / 10_000_000.0; assert(seconds.approxEqual(0.5)); ``` is there better way to do it? What you're doing now is the way to do it. This is by design, as Jonathan M. Davis explains: "In general, using floating point values with time is an incredibly bad idea. It can certainly make sense when printing stuff out, but using it in calculations is just asking for trouble given all of the unnecessary imprecision that it adds. So, Duration does not directly support floating point values at all, and that's very much on purpose. (...) And if you're just trying to print out the a duration as a floating point value, because it's nice to view that way, then that's fine, but you'll need to do the conversion yourself. And it's not that hard." https://forum.dlang.org/post/mailman.3711.1453121204.22025.digitalmars-d-le...@puremagic.com
How to convert `std.datetime.Duration` to seconds of floating point type?
Now I do it this way (https://run.dlang.io/is/8kVibT): ``` auto some_duration = dur!"msecs"(500); auto seconds = some_duration.total!"hnsecs" / 10_000_000.0; assert(seconds.approxEqual(0.5)); ``` is there better way to do it? Thanks in advance
Re: When to prefer formatValue over formattedWrite?
On Tuesday, 19 February 2019 at 11:40:09 UTC, Per Nordlöw wrote: Is `formatValue` more lightweight to the compiler? I already posted a very similar question at https://forum.dlang.org/post/xsovipkjyjyumtyzm...@forum.dlang.org but in this thread I'm interested in knowing if is there is any significant difference in compilation-speed and if formatValue and/or formattedWrite needs to allocate using the GC when we are writing a array of `char`s or a long, directly to standard output. In theory the string could be written directly to stdout without an extra memory buffer and the `long` could be formatted to a temporarily (stack) allocated array of `char`s before written to standard output.
Re: Error with matplotlib
On Tuesday, 19 February 2019 at 00:05:46 UTC, Samir wrote: On Monday, 18 February 2019 at 21:50:25 UTC, Andre Pany wrote: In the meantime you could adapt the python script on your local file system in the dub packages cache folder as described here https://github.com/koji-kojiro/matplotlib-d/pull/11/files Andre, Thank you very much for your help today! I copied the version of prebuild.py located here[1] and replaced the version located at /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/python locally on my machine after which the program ran. I guess I still have the question as to why does the error message refer to issues in /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot.d-mixin-41 when the solution was changing /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/python/prebuild.py? Apologies for all of the questions -- I'm just trying to better understand how to incorporate other packages in my simple programs. Samir [1] https://github.com/koji-kojiro/matplotlib-d/blob/master/python/prebuild.py The python script generates a list of available functions in the python package. This list will be used to generate D coding at compilation time. That is the reason, the error occurs in a mixin. Unfortunately one function had the same name as a D keyword (it was the keyword deprecated). The fix was to exclude this function from the list. I think this is the only dub package working this way, as it might be the only package which wrapping python code. Kind regards André
When to prefer formatValue over formattedWrite?
Is `formatValue` also preferred over `formattedWrite` when writing a single value? Code example: import std.array : appender; auto writer1 = appender!string(); writer1.formattedWrite("%08b", 42); auto writer2 = appender!string(); auto f = singleSpec("%08b"); writer2.formatValue(42, f); Is `formatValue` more lightweight to the compiler?
Re: Windows Defender won't let me install DMD
On Monday, 18 February 2019 at 19:34:31 UTC, Seb wrote: On Monday, 18 February 2019 at 16:32:26 UTC, belkin wrote: I am trying to install the compiler and get started on learning D again ( attempted and stopped way back ) This is the error message I am getting. I am on Windows 10. Windows Defender SmartScreen prevented an unrecognized app from starting. Running this app might put your PC at risk. App: dmd-2.084.1.exe Publisher: Unknown publisher There was a error/oversight with the 2.084.1 release. It accidentally didn't get signed, you can try 2.084.0 if you are afraid of the warning. The next release (2.085.0) should be signed again. Works. Thanks