imports and a data structure (any critique welcome)

Jonathan jdgall84 at gmail.com
Thu Dec 26 20:54:56 PST 2013


Thanks to everyone that has replied.

@Timon Gehr:
Thank you.  In reply to [1]: that is an interesting issue that I 
don't really understand right now.  Can you explain exactly where 
I invoke undefined behavior?  It was my understanding that 
structs are passed and returned by value, and the assignment
   x = some struct
makes a copy of some struct and stores it in x.  Perhaps I don't 
understand the type system of D?  If a function returns T where T 
is some struct, does the function result in a struct?  I am 
having trouble finding these subtleties in the documentation (but 
I also acknowledge that this is probably my fault and not the 
documentation's).

Does auto do a simple type inference to find out that Term* 
should be there?  Is there an advantage to using auto?

I can't seem to put @safe: at the top of the file -- is it the 
same as compiling with -safe.  Is there a way to add this as a 
source annotation?

Is ! an operator in e.g. ADT!q ...

What is the mixin bit doing?  Can you point me towards any 
tutorials, or should I buy the book?

@bearophile:
Thank you for the welcome.  That is odd; I find that D shares a 
philosophy closer to Haskell than many of the "lower level" 
languages like C.

So let me just say, I really do need to build a structure that 
can have a shared reference to a substructure.  I will be 
rewriting these terms, and the problem is that e.g.

     f(t) -> g(t,t)

I don't want to copy t, but store a reference to t, so that if t 
can be re-written, it will only be rewritten once.  However, this 
is really *not* an algebraic type since sharing is not algebraic, 
so I figured that this would not be a good solution.

The object oriented approach would be really nice.  Since objects 
are passed by reference, I should get sharing for free.  The only 
reason I didn't use an object oriented approach off the bat is 
that I don't think I completely understand when to use a struct 
versus an object.  Using structs seem to fit the story better, 
because the structure isn't really emitting any functionality, I 
just want to perform some functions to it.  So using structs feel 
like a better fit.  Feel free to correct me here.  What are some 
of the drawbacks to using object.  How much more time overhead is 
there once the object is created?

You are right, I probably look like an idiomless noob!  I totally 
am!  Hopefully an understanding of the appropriate keywords to 
use and where will come (there is quite a lot of syntax in D).  
For now, can you tell me what I could do better about the switch 
statement and what is wrong with (*term).node?


More information about the Digitalmars-d-learn mailing list