Undo in D

2018-06-22 Thread DigitalDesigns via Digitalmars-d-learn
Is there any idiomatic undo designs in D that give a more natural implementation than the standard techniques?

Re: typeof on protected field

2018-06-17 Thread DigitalDesigns via Digitalmars-d-learn
On Sunday, 17 June 2018 at 02:29:12 UTC, Adam D. Ruppe wrote: On Saturday, 16 June 2018 at 08:32:38 UTC, DigitalDesigns wrote: I need to get the protected and private members for serialization. This breaks encapsulation. A better design would be to have a class know how to serialize itself

Re: How do you test whether a variable is static or not?

2018-06-16 Thread DigitalDesigns via Digitalmars-d-learn
On Saturday, 16 June 2018 at 21:41:37 UTC, Jonathan M Davis wrote: On Saturday, June 16, 2018 14:55:51 Steven Schveighoffer via Digitalmars-d- learn wrote: On 7/30/16 8:47 AM, Jonathan M Davis via Digitalmars-d-learn wrote: > I'm writing some serialization code where I need to skip > static

Re: How do you test whether a variable is static or not?

2018-06-16 Thread DigitalDesigns via Digitalmars-d-learn
On Saturday, 30 July 2016 at 13:04:56 UTC, Ali Çehreli wrote: On 07/30/2016 05:47 AM, Jonathan M Davis via Digitalmars-d-learn wrote: > I'm writing some serialization code where I need to skip static variables. > So, I have a symbol from a struct, and I'd like to test whether it's static > or

typeof on protected field

2018-06-16 Thread DigitalDesigns via Digitalmars-d-learn
mixin(`foo!(typeof(T.`~m~`)); gives me an error about m being protected. Error: class `X` member `name` is not accessible. this also happens when using __traits(getMember, T, m); X is in another module. Works fine when X is in the same module. I need to get the protected and private members

Re: Get static fields!

2018-06-16 Thread DigitalDesigns via Digitalmars-d-learn
On Saturday, 16 June 2018 at 07:56:22 UTC, Bauss wrote: On Saturday, 16 June 2018 at 05:05:19 UTC, DigitalDesigns wrote: tupleof does not return static fields as does not Fields. Currently the only method seems to be use allMembers, but that returns members requiring filtering, which there is

Get static fields!

2018-06-15 Thread DigitalDesigns via Digitalmars-d-learn
tupleof does not return static fields as does not Fields. Currently the only method seems to be use allMembers, but that returns members requiring filtering, which there is no good filtering checks. I'd simply like to get all the fields of a type, static and non-static.

Storing temp for later use with ranges

2018-06-15 Thread DigitalDesigns via Digitalmars-d-learn
Does ranges have the ability to store a temp value in a "range like way" that can be used later? The idea is to avoid having to create temp variables. A sort of range with "memory"

returning to thrown

2018-06-12 Thread DigitalDesigns via Digitalmars-d-learn
I have to modify preexisting code. As of now, the code fails and throws an exception at some point. I need to prevent the code from throwing(easy) but signal to the user of the code some notification(hard). It would be cool if I could throw an exception as if the code yielded and it could be

Re: Orange check failling all of a sudden

2018-06-12 Thread DigitalDesigns via Digitalmars-d-learn
Also, is there any way to have a field as optional? Right now when I update a filed in a serialized type the app crashes because it can't find the field in the serialized data(since it was just added in the code). This requires either regenerating the data or manually adding the serialized

Re: Orange check failling all of a sudden

2018-06-11 Thread DigitalDesigns via Digitalmars-d-learn
I also get a lot of inout's attached to key names. Seems excessive but inout(inout(double)[]) /> Maybe they are necessary but seems like they are redundant.

Orange check failling all of a sudden

2018-06-11 Thread DigitalDesigns via Digitalmars-d-learn
Changed some things in my app but unrelated to serialization and now my app fails when trying to read the xml that was generated at the output of the previous run. Where it is failing is here: void checkSpace(ref string s) @safe pure // rule 3 { import std.algorithm.searching

Re: Orange check failling all of a sudden

2018-06-11 Thread DigitalDesigns via Digitalmars-d-learn
and if I completely remove the check then everything works fine. */ class DocumentParser : ElementParser { string xmlText; /** * Constructs a DocumentParser. * * The input to this function MUST be valid XML. * This is enforced by the function's in

Re: WTF! new in class is static?!?!

2018-06-07 Thread DigitalDesigns via Digitalmars-d-learn
On Thursday, 7 June 2018 at 23:08:22 UTC, Steven Schveighoffer wrote: On 6/7/18 6:58 PM, DigitalDesigns wrote: On Thursday, 7 June 2018 at 21:57:17 UTC, Steven Schveighoffer wrote: On 6/7/18 5:07 PM, DigitalDesigns wrote: class A; class B {     A a = new A(); } auto b1 = new B(); auto b2 =

Re: WTF! new in class is static?!?!

2018-06-07 Thread DigitalDesigns via Digitalmars-d-learn
On Thursday, 7 June 2018 at 21:57:17 UTC, Steven Schveighoffer wrote: On 6/7/18 5:07 PM, DigitalDesigns wrote: class A; class B {    A a = new A(); } auto b1 = new B(); auto b2 = new B(); assert(b1.a == b2.a)!! Yep, long-standing issue: https://issues.dlang.org/show_bug.cgi?id=2947

WTF! new in class is static?!?!

2018-06-07 Thread DigitalDesigns via Digitalmars-d-learn
class A; class B { A a = new A(); } auto b1 = new B(); auto b2 = new B(); assert(b1.a == b2.a)!! I'm glad I finally found this out! This is not typical behavior in most languages is it? I'd expect it to be translated to something like class B { A a; this() { a = new

Re: New programming paradigm

2018-06-03 Thread DigitalDesigns via Digitalmars-d-learn
On Sunday, 3 June 2018 at 16:36:52 UTC, Simen Kjærås wrote: On Sunday, 3 June 2018 at 14:57:37 UTC, DigitalDesigns wrote: On Sunday, 3 June 2018 at 09:52:01 UTC, Malte wrote: You might want to have a look at https://wiki.dlang.org/Dynamic_typing This sounds very similar to what you are doing.

pipeProcess failing

2018-06-03 Thread DigitalDesigns via Digitalmars-d-learn
I'm calling pipe process using pipeProcess([AliasSeq!args], Redirect.stdout | Redirect.stdin); where args is a tuple. Everything works when I pass each argument individually. If I combine any args using a space it fails or if I pass an argument with "". So I guess something like this

Re: New programming paradigm

2018-06-03 Thread DigitalDesigns via Digitalmars-d-learn
On Sunday, 3 June 2018 at 09:52:01 UTC, Malte wrote: On Saturday, 2 June 2018 at 23:12:46 UTC, DigitalDesigns wrote: On Thursday, 7 September 2017 at 22:53:31 UTC, Biotronic wrote: [...] I use something similar where I use structs behaving like enums. Each field in the struct is an "enum

Re: New programming paradigm

2018-06-02 Thread DigitalDesigns via Digitalmars-d-learn
On Thursday, 7 September 2017 at 22:53:31 UTC, Biotronic wrote: On Thursday, 7 September 2017 at 16:55:02 UTC, EntangledQuanta wrote: Sorry, I think you missed the point completely... or I didn't explain things very well. I don't think I did - your new explanation didn't change my

Re: Setter chaining

2018-05-30 Thread DigitalDesigns via Digitalmars-d-learn
The above idea can be emulated in code, abiet ugly and useless: https://dpaste.dzfl.pl/bd118bc1910c import std.stdio; struct CT(A,B) { A v; B t; alias v this; B opUnary(string s)() if (s == "~") { return t; } A opUnary(string s)() if

Re: Setter chaining

2018-05-30 Thread DigitalDesigns via Digitalmars-d-learn
On Wednesday, 30 May 2018 at 15:46:36 UTC, Steven Schveighoffer wrote: On 5/30/18 10:49 AM, DigitalDesigns wrote: Does it sound good? class X {    double x;    @property X foo(double y) { x = y; return this; }    @property X bar(double y) { x = y + 5; return this; } } void main() { X

Setter chaining

2018-05-30 Thread DigitalDesigns via Digitalmars-d-learn
Does it sound good? class X { double x; @property X foo(double y) { x = y; return this; } @property X bar(double y) { x = y + 5; return this; } } void main() { X x = new X(); x.foo(3).bar(4); } It sort of emulates UFCS but I'm not sure if it's more trouble than it's

Re: Build interface from abstract class

2018-05-30 Thread DigitalDesigns via Digitalmars-d-learn
On Wednesday, 30 May 2018 at 10:31:27 UTC, Simen Kjærås wrote: On Monday, 28 May 2018 at 20:13:49 UTC, DigitalDesigns wrote: I do not think this is a problem in D. Infinite recursion can always be terminated with appropriate means. 1. Use attributes. methods in class A should be marked as

Re: Build interface from abstract class

2018-05-29 Thread DigitalDesigns via Digitalmars-d-learn
On Wednesday, 30 May 2018 at 01:46:30 UTC, Chameleon wrote: On Monday, 28 May 2018 at 20:13:49 UTC, DigitalDesigns wrote: Here is my solution that does not solve problem 2: import std.stdio; [...] this is not programming. this is witchcraft! Just call me Dandalf the D Slayer! At

Re: Build interface from abstract class

2018-05-29 Thread DigitalDesigns via Digitalmars-d-learn
On Tuesday, 29 May 2018 at 20:53:14 UTC, DigitalDesigns wrote: On Tuesday, 29 May 2018 at 20:26:52 UTC, arturg wrote: On Tuesday, 29 May 2018 at 19:06:24 UTC, DigitalDesigns wrote: On Monday, 28 May 2018 at 22:15:40 UTC, arturg wrote: this might help you, https://dpaste.dzfl.pl/2cf844a11e3f

Re: full path to source file __FILE__

2018-05-29 Thread DigitalDesigns via Digitalmars-d-learn
On Tuesday, 29 May 2018 at 21:41:37 UTC, Ali Çehreli wrote: On 05/29/2018 02:34 PM, DigitalDesigns wrote: > auto x(string fp = __FULL_FILE_PATH__)() {    pragma(msg, fp); } ? __FILE_FULL_PATH__ https://dlang.org/spec/expression#specialkeywords Ali Lol, thanks:

Re: full path to source file __FILE__

2018-05-29 Thread DigitalDesigns via Digitalmars-d-learn
On Wednesday, 27 July 2016 at 13:58:22 UTC, Jonathan Marler wrote: On Thursday, 21 July 2016 at 19:54:34 UTC, Jonathan Marler wrote: Is there a way to get the full path of the current source file? Something like: __FILE_FULL_PATH__ I'm asking because I'm rewriting a batch script in D, meant

string mixin output works when directly used but when generator is used D fails

2018-05-29 Thread DigitalDesigns via Digitalmars-d-learn
https://dpaste.dzfl.pl/67691db19ce8 Just delete 9 to 29 for the code to work. Note that none of the code effects the output but D gives strange errors. In my code it says the interface members are not implemented(which they are) foreach (member; __traits(allMembers, T))

Re: Build interface from abstract class

2018-05-29 Thread DigitalDesigns via Digitalmars-d-learn
On Tuesday, 29 May 2018 at 20:26:52 UTC, arturg wrote: On Tuesday, 29 May 2018 at 19:06:24 UTC, DigitalDesigns wrote: On Monday, 28 May 2018 at 22:15:40 UTC, arturg wrote: this might help you, https://dpaste.dzfl.pl/2cf844a11e3f you can use them to generate the functions as strings. Thanks,

Re: Build interface from abstract class

2018-05-29 Thread DigitalDesigns via Digitalmars-d-learn
On Monday, 28 May 2018 at 22:15:40 UTC, arturg wrote: this might help you, https://dpaste.dzfl.pl/2cf844a11e3f you can use them to generate the functions as strings. Thanks, So, the problem I'm having is that I cannot use the generated interface for the abstract class because the abstract

Re: Build interface from abstract class

2018-05-28 Thread DigitalDesigns via Digitalmars-d-learn
On Monday, 28 May 2018 at 11:51:20 UTC, Simen Kjærås wrote: On Monday, 28 May 2018 at 09:59:50 UTC, DigitalDesigns wrote: Implementing interfaces can be a pain but are necessary. I like to use abstract classes and provide a base implementation. It would be cool if I could use D's awesome

Build interface from abstract class

2018-05-28 Thread DigitalDesigns via Digitalmars-d-learn
Implementing interfaces can be a pain but are necessary. I like to use abstract classes and provide a base implementation. It would be cool if I could use D's awesome meta features to extract the interface from the abstract class then build it. This requires some funky stuff which I'm not