Re: Implicit conversions through purity

2014-04-15 Thread Steve Teale
On Tuesday, 15 April 2014 at 18:02:00 UTC, bearophile wrote: Steve Teale: Since this is D-Learn, I can be indignant, and say that D needs to get its act together, and have a clean definition of 'pure'. What you describe is not only undocumented, but also far too complicated -

Re: Implicit conversions through purity

2014-04-15 Thread Steve Teale
On Tuesday, 15 April 2014 at 09:41:57 UTC, bearophile wrote: Yes, foo2 is weakly pure, but main is not tagged as pure, so main is free to use a global reference. If you mark main pure, your code will not compile even if you comment out the writeln. D is working as designed here. 3) Using a r

Re: Implicit conversions through purity

2014-04-15 Thread Steve Teale
On Monday, 14 April 2014 at 15:16:07 UTC, bearophile wrote: Steven Schveighoffer: For that reason, I would disallow out parameters from casting implicitly. A number of things perplex me here. 1) If I attempt to compile foo2() more or less as presented with 2.065, the compiler tells me: Er

Re: How to hand in a closure variable

2014-04-07 Thread Steve Teale
On Friday, 4 April 2014 at 15:15:55 UTC, bearophile wrote: Bienlein: What I was actually looking for was how to get this to work: immutable int b = if(1 == 1) { return 123; } else { return 456; }; immutable b = (1 == 1) ? 123 : 456; Bye, bearophile You said you did not like ternary expre

Re: Check for presence of function

2014-03-23 Thread Steve Teale
On Sunday, 23 March 2014 at 13:23:58 UTC, Dicebot wrote: On Sunday, 23 March 2014 at 13:03:07 UTC, Adam D. Ruppe wrote: That won't necessarily work in the presence of overloaded functions since getMember only gets one of them. Yeah, forgot to add this part, will make end result a bit less pre

Check for presence of function

2014-03-23 Thread Steve Teale
What's the cool/idiomatic D way to test at compile time if a struct has a member function with a particular signature? Along the lines of: struct Unrelated { ... } template isSomething(T) { enum bool isSomething = is(typeof( (inout int = 0) { T???; // has a function void

Casting an interface to the type that implements it.

2014-03-12 Thread Steve Teale
This might be equivalent to 'How to do multiple inheritance in D'. I have a class ControlSet, that is just a bunch of widgets. I use it in various places to represent the contents of dialogs that are associated with some class. All such classes have to do is define themselves using the CSTar

Re: Linux Dynamic Loading of shared libraries

2014-03-10 Thread Steve Teale
On Sunday, 9 March 2014 at 12:07:22 UTC, Steve Teale wrote: Now suppose that my D shared library contains a class, rather that just module ctors/dtors, how do I go about creating an instance of that class and using its methods? After wandering down several dead-end paths, and help from other

Re: Linux Dynamic Loading of shared libraries

2014-03-09 Thread Steve Teale
On Sunday, 9 March 2014 at 14:09:28 UTC, Tolga Cakiroglu wrote: For this, you create an "Interface" that matches to the method declaration of your class. But notice that instead of defining methods, you will define attributes those types' match to that class's methods. I did this before and

Linux Dynamic Loading of shared libraries

2014-03-09 Thread Steve Teale
Martin Nowak's Gihub druntime Page has module main; import core.runtime, core.thread; void main() { auto lib = Runtime.loadLibrary("./liba.so"); auto thr = new Thread({ auto lib = Runtime.loadLibrary("./liba.so"); Runtime.unloadLibrary(lib); }); thr.start(); t

Re: Compiling D through command line

2014-03-07 Thread Steve Teale
On Friday, 7 March 2014 at 16:59:30 UTC, Bauss wrote: What arguments would I do to compile a d project through command line. Been trying a few things, but can't get it working. I always get "Error: cannot read file x" Read around the net and it most says it's an installation error and that r

Re: Template mixins - why only declarations

2014-03-07 Thread Steve Teale
On Thursday, 6 March 2014 at 18:36:12 UTC, Dejan Lekic wrote: Template mixins can't contain statements, only declarations, because they (template mixins) are a way to inject code into the context. Therefore it makes sense to forbid statements, as they can't appear in ANY context. If I sid

Template mixins - why only declarations

2014-03-06 Thread Steve Teale
Pretty much what the subject says. Why can't template mixins include statements ans so on? Is it just too hard, or is it just too much like C macros? Steve

Re: Nobody understands templates?

2014-03-02 Thread Steve Teale
On Sunday, 2 March 2014 at 15:23:03 UTC, H. S. Teoh wrote: This is a pretty good primer to templates: https://semitwist.com/articles/article/view/template-primer-in-d The trouble is with most of these tutorials that they offer examples that are things you would probably never want to

Re: Nobody understands templates?

2014-03-02 Thread Steve Teale
On Sunday, 2 March 2014 at 10:05:05 UTC, Dicebot wrote: There is nothing wrong about not using templates. Almost any compile-time design can be moved to run-time and expressed in more common OOP form. And using tool you have mastery of is usually more beneficial in practice than following th

Re: Nobody understands templates?

2014-03-01 Thread Steve Teale
On Saturday, 1 March 2014 at 22:16:54 UTC, woh wrote: You probably don't have a good understanding of templates if you have only used 2 in your entire codebase. Or you are talking about a very tiny codebase. That's just what us template-blind people want to hear - confirmation that we are i

Re: Nobody understands templates?

2014-03-01 Thread Steve Teale
On Friday, 28 February 2014 at 19:06:26 UTC, Dicebot wrote: On Friday, 28 February 2014 at 18:42:57 UTC, Steve Teale wrote: Is this typical - libraries use templates, applications don't, or am I just being unimaginative? Steve Also every time you catch yourself doing any sort of

Nobody understands templates?

2014-02-28 Thread Steve Teale
All the D aficionados seem to wet their pants over meta-programming, but I struggle to find a place to use it. IIRC, I used it in a couple of places when I was trying to write library stuff for MySQL, but in my current project, I use it only once. That's when I want to stuff something onto my und

Re: @disable this for structs

2014-02-28 Thread Steve Teale
On Friday, 28 February 2014 at 16:02:26 UTC, Dicebot wrote: ... Mmm, simple question, complicated answer. But the first one was enough for me at this point.

Re: enum abuse

2014-02-28 Thread Steve Teale
On Friday, 28 February 2014 at 11:47:45 UTC, Vladimir Panteleev wrote: A "const" or "immutable" declaration would declare a constant variable - meaning, unless it is optimized out at a later point, it will end up in the data segment and have its own address. An enum declares a manifest consta

@disable this for structs

2014-02-27 Thread Steve Teale
Could someone please explain what you would use this for to an old man rooted in C++, but who loves D. Where does it fit in relative to 42? ;=( Steve

Re: @disable this for structs

2014-02-27 Thread Steve Teale
On Thursday, 27 February 2014 at 18:13:43 UTC, Namespace wrote: On Thursday, 27 February 2014 at 18:10:38 UTC, Steve Teale wrote: Could someone please explain what you would use this for to an old man rooted in C++, but who loves D. Where does it fit in relative to 42? ;=( Steve It'

Re: DUB Error

2014-02-25 Thread Steve Teale
On Wednesday, 26 February 2014 at 03:33:38 UTC, Jesse Phillips wrote: On Tuesday, 25 February 2014 at 14:32:42 UTC, Steve Teale wrote: What does the somewhat cryptic DUB error Trying to append absolute path. mean. By a process of elimination, the offending line in the json file is

DUB Error

2014-02-25 Thread Steve Teale
What does the somewhat cryptic DUB error Trying to append absolute path. mean. By a process of elimination, the offending line in the json file is "importPaths": ["/usr/local/include/d/gtkd-2"] Steve

Re: Treat memory as a file with a name.

2014-02-22 Thread Steve Teale
If it's the same librsvg as below, then it looks like it has an API function which can also load a SVG from memory: https://developer.gnome.org/rsvg/2.40/RsvgHandle.html#rsvg-handle-new-from-data To answer your original question, I think the best way to do this is to create a pipe on the files

Treat memory as a file with a name.

2014-02-21 Thread Steve Teale
This is probably not exactly a D question. The library librsvg expects to get an SVG file filename. I have the data of such a file in memory. How do I dress up that memory as a file with a name so that I can pass the name to the librsvg open function. I've looked at std.mmfile, and played w

Re: 64 bit size_t

2014-02-18 Thread Steve Teale
Rather than change it to int/ulong, just change it to 'size_t len = parent.children.length+1' (or auto instead of size_t). This way it's proper for both 32-bit and 64-bit and you don't need to worry about architecture. If you do need a signed version, you can use ptrdiff_t. Yup, that's what I

Re: 64 bit size_t

2014-02-16 Thread Steve Teale
On Monday, 17 February 2014 at 07:17:06 UTC, Steve Teale wrote: What is size_t for 64 bit? Steve Sorry parent.children is just a straightforward array Sorry again - forget about it. I'd forgotten that D actually says int is 32 bits, and ulong is 64, and size_t for a 64 bit machin

64 bit size_t

2014-02-16 Thread Steve Teale
Why is it that with 32 bit compilation, int is 32 bits, but apparently this convention is not followed in 64 bit compilation. I have not installed the 64 bit compiler yet, but apparently int len = parent.children.length+1; provokes the following error acomp.d(782): Error: cannot implicitly con

Re: 64 bit size_t

2014-02-16 Thread Steve Teale
On Monday, 17 February 2014 at 07:15:20 UTC, Steve Teale wrote: Why is it that with 32 bit compilation, int is 32 bits, but apparently this convention is not followed in 64 bit compilation. I have not installed the 64 bit compiler yet, but apparently int len = parent.children.length+1

Re: Ranges, constantly frustrating

2014-02-11 Thread Steve Teale
On Tuesday, 11 February 2014 at 10:52:40 UTC, Tobias Pankrath wrote: The second naive solution would be to use readText and splitLines. That's the sort of thing I always do because then I understand what's going on, and when there's a bug I can find it easily! But then I'm not writing li

Re: App release build crashes

2014-02-07 Thread Steve Teale
On Friday, 7 February 2014 at 07:43:05 UTC, Steve Teale wrote: I was attempting to to build my app COMPO using a Makefile this morning, and at first this worked to some extent, but after some fiddling with compiler flags to make a release version that then had problems, I reverted to my

App release build crashes

2014-02-06 Thread Steve Teale
I was attempting to to build my app COMPO using a Makefile this morning, and at first this worked to some extent, but after some fiddling with compiler flags to make a release version that then had problems, I reverted to my original makefile as of yesterday. That builds and links the app, but

Re: Is this reasonable?

2013-12-06 Thread Steve Teale
On Thursday, 5 December 2013 at 17:15:39 UTC, Steve Teale wrote: Here I feel like a beginner, but it seems very unfriendly: import std.stdio; struct ABC { double a; int b; bool c; } ABC[20] aabc; void foo(int n) { writefln("n: %d, aabc.length: %d", n, aabc.length)

Is this reasonable?

2013-12-05 Thread Steve Teale
Here I feel like a beginner, but it seems very unfriendly: import std.stdio; struct ABC { double a; int b; bool c; } ABC[20] aabc; void foo(int n) { writefln("n: %d, aabc.length: %d", n, aabc.length); if (n < aabc.length) writeln("A"); else writeln("B"); } void m

scope struct?

2011-10-16 Thread Steve Teale
Is not needed because structs are inherently scope. I'm sure experienced D programmers do this all the time when they want something done on exit from a scope, but I never had, and maybe there are others who haven't, particularly if coming from a C++ 'use classes for everything' background. im

Re: Passing ref through a template chain

2011-10-03 Thread Steve Teale
Works like a charm, and it's so obvious a thing to try that I'm kicking myself. Thanks Steve

Passing ref through a template chain

2011-10-03 Thread Steve Teale
To bind variables, the MySQL api wants their addresses - in my tiny example below, these are represented by the void*[]. If I just use something like setTarget in the example, it works fine, but then when I try to set a bunch of them in one go I'm hosed because I can't get the right addresses thro

Re: std.datetime impenetrable

2011-09-15 Thread Steve Teale
Oh, so it is difficult after all! I thought it was just me. So I am probably going to have to ask. Then the interesting question will be which way around will offend fewest people. I have installed it as ISO, then have to ask US users if they would prefer Letter Size, or the other way round th

std.datetime impenetrable

2011-09-15 Thread Steve Teale
Looking at the documentation makes my head hurt, especially if I have consumed some beer, when I am not pure and immutable. Can anyone help me to understand how to determine what timezone the user has selected to be his/hers. Alternatively, let me explain my desire. When my program first runs, I

Re: Template instantiation without (...)

2010-02-07 Thread Steve Teale
> I suppose it's the part of the spec you're about to write a patch for. Twas at: http://www.digitalmars.com/d/archives/digitalmars/D/ Template_instantiation_syntax_77507.html#N77507

Re: Template instantiation without (...)

2010-02-07 Thread Steve Teale
> I suppose it's the part of the spec you're about to write a patch for. I guess so. It was discussed on one of the forums back in October 2008. I guess it got implemented but never made the documentation.

Template instantiation without (...)

2010-02-07 Thread Steve Teale
Which bit of the spec for template instantiation is it that allows the last two lines of the following to compile and work? import std.stdio; struct A { int a; } template Thingie(T) { static if (is(T == int)) enum Thingie = 1; else enum Thingie = 0; } void main() {

std.array.array extended example to supplement that in std.array

2010-02-07 Thread Steve Teale
import std.array; import std.range; import std.stdio; // A contrived input range struct Sir { string s; int pos; bool empty() { return pos >= s.length; } void popFront() { pos++; } int front() { return s[pos]-'0'; } } int[] da = [1,2,3,4,5]; int[5] sa = [1,2,3,4,5]; void

Re: Creating a logging library and have questions

2010-02-06 Thread Steve Teale
sybrandy Wrote: > On 02/03/2010 12:03 AM, Rainer Deyke wrote: > > sybrandy wrote: > >> 1) I use the current core.thread library and put all my messages in a > >> buffer that the thread checks periodically, pulls off a new message, and > >> then writes it to a file. There will be some work to make

Re: Finding out about D - 102

2009-05-11 Thread Steve Teale
Ary Borenszweig Wrote: > Steve Teale wrote: > > OK, so structs are a different beast in D than they are in C++. This > > results in one of my most common pitfalls. I'll find myself writing: > > > > struct A > > { > >int a; > >int b; >

Finding out about D - 102

2009-05-11 Thread Steve Teale
OK, so structs are a different beast in D than they are in C++. This results in one of my most common pitfalls. I'll find myself writing: struct A { int a; int b; } A[] nameTooLong = ...; foreach (whatever; thingie) { nameTooLong[whatever.whatever].a = whatever.x*3; nameTooLong[what

Re: Finding out about D - 101

2009-05-11 Thread Steve Teale
Steven Schveighoffer Wrote: > > This tells me that a string in D is a sequence of characters (whatever > > that might mean) in memory, prefixed by a size_t length. Of course, > > that's not to say there is no more to it, but the values for 'xtra' > > don't give us much clue. If there was so

Finding out about D - 101

2009-05-11 Thread Steve Teale
OK, so let's find out about strings. D does not have 'string' as a built in type. It is just an alias for invariant(char[]). So what is it? Well, you can find out quite a bit by compiling and running: import std.stdio; struct S { size_t len; void* p; int xtra; } void main() { strin