Re: Simple code sample of Nesting Structures. I'm I doing something illegal here?

2014-11-22 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Saturday, 22 November 2014 at 20:57:07 UTC, WhatMeWorry wrote: auto bottom = NestedBottom(2, ['d','o','g']); That 'auto' is the problem. You want 'this.bottom = ...' instead.

Re: Recursive template

2014-11-15 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
Slightly simpler: struct SomeType(K, V) {} alias X(V) = V; alias X(V, K...) = SomeType!(K[0], X!(V, K[1 .. $])); That's a recurring pattern to get used to: aliasing away to one of the parameters in a terminal and/or degenerate case. Also: that an empty tuple matches no parameter

Re: Code fails with linker error. Why?

2014-10-04 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
In the original you are casting an int to a pointer type, which is legitimate (although rarely a good idea). The other side of the matter is simply precedence. cast(T)a.b; Is really the same as: cast(T)(a.b);

Re: Novice web developer trying to learn D

2014-09-07 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
There's Adam Ruppe's excellent D Cookbook available here: https://www.packtpub.com/application-development/d-cookbook And since you specifically said web developer I hope you're looking at vibe.d: http://vibed.org/

Re: Auto-add static field when inherit // mixins, templates?

2014-08-22 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
class A { string getName(this Klass)() { return Klass.stringof; } } class B : A {} void main() { import std.stdio; auto a = new A; auto b = new B; writeln(a.getName()); writeln(b.getName()); } ## This

Re: delegates GC allocations

2014-08-20 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 15:17:52 UTC, Ola Fosheim Gr wrote: non-static nested functions are effectively delegates as it needs a context pointer to parent stack frame. Only if it is recursive. Or if it refers to any state of the parent function.

Re: Enum type deduction inside templates is not working

2014-06-27 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Friday, 27 June 2014 at 07:43:27 UTC, Uranuz wrote: I don't know why I use D enough long but I did not remember this fact. Sometimes we get spoiled by all the amazing/nifty things that do work, and expect comparable things like this to Just Work. To be honest, at first I didn't see any

Re: Enum type deduction inside templates is not working

2014-06-27 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Friday, 27 June 2014 at 14:27:46 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Try this: Get out of my head!

Re: import except one?

2014-06-27 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Friday, 27 June 2014 at 05:26:09 UTC, Puming wrote: On Thursday, 26 June 2014 at 08:02:24 UTC, bearophile wrote: Puming: I'm using scriptlike, which imports everything from std.process for convienience, but I also need to import another module, which contains a class `Config`, it

Re: close program by code

2014-06-26 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Thursday, 26 June 2014 at 11:07:37 UTC, Rene Zwanenburg wrote: They won't. Same for module destructors. If you need those to work, another option is to throw some custom Exception type which is only caught in main. I really wish this wasn't the answer, but for some programs I've had to

Re: Using attributes inside template instantiation

2014-06-25 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
UDA's are compile-time metadata associated with a specific declaration. So in something like: @foo int x; The @foo is attached to x, but is not part of the type.

Re: Using two flags in conditonal compilation (version)

2014-06-25 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
version(DigitalMars) version = DMDAsm; version(LDC) version = DMDAsm; version(DMDAsm) asm { //dmd/ldc asm here } version(GDC) asm { //gdc asm here } http://dlang.org/version.html#VersionSpecification

Re: Using attributes inside template instantiation

2014-06-25 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Wednesday, 25 June 2014 at 17:21:21 UTC, H. S. Teoh via Digitalmars-d-learn wrote: The term attribute is a bit confusing, especially since property is also used in the language to refer to something completely different. A better term is perhaps annotation. The @foo is an annotation on x,

Re: next!T

2014-06-06 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Saturday, 7 June 2014 at 02:23:18 UTC, Andrew Edwards wrote: This function now works for all types except dstring. This remains a problem I cannot figure out. The error code is as follows: $ rdmd -unittest textnext /usr/share/dmd/src/phobos/std/conv.d(3293): Error: cannot modify

Re: Creating new types from tuples.

2014-06-06 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Friday, 6 June 2014 at 23:44:04 UTC, Evan Davis wrote: Hello, I'm looking to use the Tuple type as a way of generating types to represent data in a send recieve connection pair. I created a template to try this: template s_to_c(UDP packetType) { static if (packetType ==

Re: next!T

2014-06-06 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Saturday, 7 June 2014 at 03:21:49 UTC, Andrew Edwards wrote: Wow. Sometimes you really cannot see the things you type no matter how long you stare at it. Thank you soo much. No problem. I only noticed when I re-typed it by hand to study the flow, and instinctively added the else out of

Re: enums

2014-06-01 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Saturday, 31 May 2014 at 22:45:32 UTC, bearophile wrote: Chris Nicholson-Sauls: Good... I was starting to fear I was the only one. In general you can't fix the names in a language because you always find someone that likes the ones present :) I think enum is a bad name for the purpose

Re: support for unicode in identifiers

2014-06-01 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Sunday, 1 June 2014 at 22:26:42 UTC, Vlad Levenfeld wrote: I was pretty happy to find that I could use mu and sigma when writing statistical routines, but I've found that for more obscure non-ascii characters the support is hit or miss. For example, none of the subscripts are valid

Re: enums

2014-05-31 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Saturday, 31 May 2014 at 22:13:35 UTC, monarch_dodra wrote: On Saturday, 31 May 2014 at 21:21:59 UTC, Paul D Anderson wrote: 'enum' as a manifest constant keyword has been an unpopular decision from its introduction. Everybody agrees that it should be changed. Everybody but Walter I find

Re: Empty array and AA literals

2014-04-06 Thread Chris Nicholson-Sauls
On Sunday, 6 April 2014 at 03:28:50 UTC, dnspies wrote: On Sunday, 6 April 2014 at 03:23:17 UTC, Adam D. Ruppe wrote: You can just set it to null. Then, next time you add anything to it, a new one will be automatically created. What about if I have a 2D array (ie int[][]) and I want to

Re: How to do a checked cast from base-type to enum-type

2014-04-05 Thread Chris Nicholson-Sauls
On Sunday, 6 April 2014 at 02:21:35 UTC, dnspies wrote: Is there a way to do a checked cast from a base type to an enum-type (so that an exception is thrown if it fails)? ie something like enum x : dchar { A : 'a', B : 'b', C : 'c' }; x get_x() { dchar r = get_char(); return cast(x)r;

Re: How do you overload opEquals?

2013-11-19 Thread Chris Nicholson-Sauls
On Tuesday, 19 November 2013 at 20:59:31 UTC, Dale Matthews wrote: I'm brand new to D and I'm taking on a project. In the midst, I've overloaded a whole load of operators for my Vec3 class. Most seem to be working (I haven't tested them all yet) but opEquals is refusing to be called. I've

Re: Enum with base type string and switch

2013-11-19 Thread Chris Nicholson-Sauls
This was a bug and has since been fixed, so the solution is simply to update your compiler. If there is some reason you can't (company required version, etc) then your cast() is sadly probably the only way.

Re: Variable arguments with file and line information?

2013-11-17 Thread Chris Nicholson-Sauls
On Saturday, 16 November 2013 at 23:55:47 UTC, Jonathan M Davis wrote: If you're dealing with variadic arguments, then making the file and line number be template arguments is really your only solution. However, I must warn you that that will result in a new template instantation _every_

Re: interface and class inheritance

2013-11-17 Thread Chris Nicholson-Sauls
I had thought the pattern alias B.funcA funcA; was supposed to solve things like this, but it does not work. Any reason it couldn't be made to? Or, for that matter, why inherited members are not considered by interfaces in the first place? In related news, if you simply leave A out

Re: Conditional compilation

2013-06-09 Thread Chris Nicholson-Sauls
There is the aforementioned extern(system), which is probably your best bet. But I'm wondering if your design could seperate the connection to IUnknown for non-Windows builds? Something like this: version(Windows) interface _Inter_ : IUnknown {} else interface _Inter_ {} // later

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread Chris Nicholson-Sauls
On Tuesday, 14 August 2012 at 22:31:16 UTC, bearophile wrote: http://www.reddit.com/r/cpp/comments/y6gwk/norvigs_python_sudoku_solver_ported_to_c11/ http://nonchalantlytyped.net/blog/2012/08/13/sudoku-solver-in-c11/ His C++11 port is 316 lines long: https://gist.github.com/3345676 How many

Re: something weird about polymorphism

2009-11-15 Thread Chris Nicholson-Sauls
on the advantages side of using non-virtual interfaces. -- Chris Nicholson-Sauls

Re: Compilation constants

2009-11-12 Thread Chris Nicholson-Sauls
right-click the message header, and there will be a Cancel Message command way down toward the bottom. -- Chris Nicholson-Sauls

Re: Mixins output handling

2009-10-31 Thread Chris Nicholson-Sauls
Nicholson-Sauls

Re: Sorry, I just love templates, AAs and mixins :)

2009-10-18 Thread Chris Nicholson-Sauls
( key, elems ; sandbox ) { writeln(`[`, key, `] `, elems); } } // END CODE -- Chris Nicholson-Sauls

Object.factory

2009-09-29 Thread Chris Nicholson-Sauls
Nicholson-Sauls

Re: Reuse of variables referencing const objects

2009-03-09 Thread Chris Nicholson-Sauls
Sergey Kovrov wrote: On 3/9/2009 8:50 PM, Chris Nicholson-Sauls wrote: While not strictly intuitive, you could do this: auto var = Rebindable!(const Foo)(new Foo); assert(var.opDot !is null); As 'opDot' returns the wrapped object (with const intact). The downside to that, however

Re: Unicode problems?

2009-02-16 Thread Chris Nicholson-Sauls
occasionally. In cases where I specifically expect/encourage multilingual support/use, it can simplify matters greatly, where those otherwise inefficient operations become common. -- Chris Nicholson-Sauls

Re: Pointers

2009-02-14 Thread Chris Nicholson-Sauls
to Classes? Not in the common case, no, but it can be useful at times. (Although, most of the cases where I would use them involve parameter passing, so I just use 'ref' arguments.) -- Chris Nicholson-Sauls

Re: A array bug?

2009-02-05 Thread Chris Nicholson-Sauls
Stewart Gordon wrote: Chris Nicholson-Sauls wrote: snip Suggest: Array operation 'OP' not implemented for type T[]. Where OP is here '+' and T is here char. It doesn't quite work like that. AIUI the only supported way of using array operations is assigning the result to an array slice

Re: Some performance questions

2009-02-03 Thread Chris Nicholson-Sauls
*'. I'm a physicist, not a computer scientist. :) Which is a good thing, since D could use more experience from non-programmers who need to program. That's a demographic that occasionally (but never completely!) gets forgotten. I'm not exactly a thirty-years guru, myself. -- Chris Nicholson

Re: Some performance questions

2009-02-03 Thread Chris Nicholson-Sauls
Jarrett Billingsley wrote: On Tue, Feb 3, 2009 at 3:44 PM, Chris Nicholson-Sauls ibisbase...@gmail.com wrote: The second reason, is that before every allocation the garbage collector will perform a collection run. This can actually be disabled (at least in theory) if you plan on doing several

Re: Some performance questions

2009-02-02 Thread Chris Nicholson-Sauls
(?,X) a million times, the cost of allocating one object is amortized into nearly nothing.) -- Chris Nicholson-Sauls

Re: array initialization problem

2009-01-20 Thread Chris Nicholson-Sauls
a was resized in place or not. Which is why slicing, albeit a fantastically useful feature, has to be handled with care. -- Chris Nicholson-Sauls ibisbasenji @ Google Mail