extern and opaque structs

2012-05-02 Thread James Miller
pecting an full struct. Adding __gshared doesn't help. I assume this is bug, since usage of extern means that I don't need to know the size, since it will be allocated in the C code, not the D code. -- James Miller

Re: FormatSpec struct

2012-04-13 Thread James Miller
* James Miller [2012-04-13 19:16:48 +1200]: > * Paul D. Anderson > [2012-04-13 07:50:31 +0200]: > > I'm trying to add formatted output to my decimal arithmetic module. > > Decimals should format like floating point, using 'E', 'F' and 'G',

Re: FormatSpec struct

2012-04-13 Thread James Miller
l > > Hey Paul, so some investigation has led me to believe that FormatSpec is really just for internal usage. The documentation is a bit misleading (to the point of being possibly completely false). FormatSpec, AFAICT, is essentially just a parser for the standard format specifier, but its not very clear as to proper usage. I'm going to try to improve it and submit a pull request, until then looking at the source code for std.format should give you some idea of how to best use it. -- James Miller

Re: Sampling algorithms for D

2012-04-12 Thread James Miller
uniform!("[]")(a,b); You can also do "()" and "(]" to obtain the other two intervals -- James Miller

Re: Passing function as values and returning functions

2012-04-12 Thread James Miller
* James Miller [2012-04-13 02:49:03 +1200]: > Glad you got help Xan, but for future reference can you please keep > questions to D.learn? It is somewhat frustrating to see the question > "How do I do that?" on this list, since it is for discussion, and > high-level question

Re: Passing function as values and returning functions

2012-04-12 Thread James Miller
quot;How do I do that?" on this list, since it is for discussion, and high-level questions, not for people that are learning D. (High level questions being along the lines of "What changes need to be made in dmd to support the new AA implementation?") -- James Miller

Re: Multiple %s format specifiers with a single argument

2012-04-11 Thread James Miller
) seem to handle replying well, setting the correct headers to indicate things. But I've seen some odd postings from people posting using things like Windows Live Mail. And it seems that Outlook Express is better at mailing lists than Outlook, which is strange... -- James Miller

Re: Operator Overloading with class template

2012-04-09 Thread James Miller
as I'm aware) the compiler emits a template instantiation of opBinary("/") for the type. That means that you can add on more template arguments. 3. Using `auto` means that the compiler works out the type, so you don't have to add extra template arguments to calculate the correct type. Hope that helps. -- James Miller

Re: making args global

2012-04-03 Thread James Miller
On 4 April 2012 10:32, jicman wrote: > How can I make args global? > > thanks, In D, technically the only way is to use Runtime, as Andrej mentioned. As an aside, it is worth noting there is no global scope in D, module is as high as you go.

Custom Allocators

2012-04-02 Thread James Miller
?)? - Would it be possible to use custom allocators to write a completely GC-free application (using ref-counting instead for example)? Or would the GC still be used anyway? If I'm way off base on anything, feel free to say so, memory management and garbage collection aren't exactly my strong suits. Thanks -- James Miller

Re: Equivalents to policy classes in D

2012-04-02 Thread James Miller
of your situation, you could also use conditional compilation in conjunction with templates to implement your policies, often interfaces aren't needed when you only want/need a minor change, I only use them for polymorphism in D. -- James Miller

Re: Add Element to list not Working

2012-04-01 Thread James Miller
se > it works fine for arrays but apperantly not for lists. > > How do I add an element to a list? opAppend (or whatever it is) isn't defined for alot of types that it probably should be. There should be an append method that you can use though. -- James Miller

Re: std.typecons.Ref(T).opImplicitCastTo()

2012-04-01 Thread James Miller
On 31 March 2012 06:28, Jonathan M Davis wrote: > it also has > opDot, which is being removed from the language. Out of curiosity, what was opDot? -- James Miller

Re: UFCS for types?

2012-04-01 Thread James Miller
ons, not templates, or rather its Uniform Function-Call Syntax, not Uniform Template-Instantiation Syntax (UTIS?). Because even ext(T)(); is just sugar for: template ext(T) { void ext(); } -- James Miller

Re: std.conv length=0

2012-03-28 Thread James Miller
On 29 March 2012 17:05, Jesse Phillips wrote: > On Thursday, 29 March 2012 at 03:40:55 UTC, James Miller wrote: > >> I award thee the "Necromancer" badge, for reviving a long-dead thread. >> >> -- >> James Miller > > > I find the distaste of rev

Re: std.conv length=0

2012-03-28 Thread James Miller
e like I did): I award thee the "Necromancer" badge, for reviving a long-dead thread. -- James Miller

Re: Get indexes of character in array

2012-03-27 Thread James Miller
On 28 March 2012 19:35, Andrej Mitrovic wrote: > I'd like to get a list of indexes into an array that matches a character. > E.g.: > > "a foo a bar a".indexes("a") == [0, 6, 12] > > Anything like that in Phobos? std.regex might be able to produce something like it. -- James Miller

Re: How to remove element from an SList?

2012-03-27 Thread James Miller
s an odd beast, and I might do some more investigation. However, all you need to know is that in order to remove, say the 5th element from a SList, you need to do this: SList!int s = [1,2,3,4,5,6,7,8,9,0]; auto r = s[0..4]; auto r1 = take(1, r); s.linearRemove(r1) Not the most intuitive way in the world... -- James Miller

Re: opDispatch(string name, E...) (E e) question.

2012-03-25 Thread James Miller
t fits into that properly, but it shouldn't be too hard. Also, remember that opDispatch takes the name of the function as the last parameter, so watch out for that. -- James Miller

Re: opDispatch(string name, E...) (E e) question.

2012-03-25 Thread James Miller
e on `@property`s). > fm.list = (1, "abc", 4L, 3.33); I'm hoping you mean `fm.list = [1, "abc", 4L, 3.33];` I think that using the right template parameters, you can use the same code for (T...)(T el) and (T)(T[]), I just can't remember what that is... > Another question : > How do I bring in : > > opDispatch(string name, T) (T[] t) -- James Miller

Re: Vector operations optimization.

2012-03-22 Thread James Miller
ne comment on this? The flags you want are -O2, -inline -release. If you don't have those, then that might explain some of the slow down on slicing, since -release drops a ton of runtime checks. Otherwise, I'm not sure why its so much slower, the druntime array ops are written using SIMD instructions where available, so it should be fast. -- James Miller

Re: regex issue

2012-03-20 Thread James Miller
en usages of strings, no strange other usages of the same escape sequence... -- James Miller

Re: Comparison issue

2012-03-19 Thread James Miller
On Mar 20, 2012 1:50 AM, "bearophile" wrote: > > James Miller: > > > writeln(v1 == 1); //false > > writeln(v1 == 1.0); //false > > writeln(v1 == 1.0f); //false > > writeln(v1+1 == 2.0f); //true > > Maybe I'd l

Comparison issue

2012-03-19 Thread James Miller
and can show that the type of `v1` is `float`, as you'd expect. And the last one passes fine, as does doing `(v1+1)-1 == 1`. I'm not sure what could be causing this. I believe it may be a bug, but I would like to see if I'm just wrong instead. -- James Miller

Re: Confused about github rebasing

2012-03-15 Thread James Miller
d it made me misread the last phrase as "threatening to > eat your face". :-P That too -- James Miller

Re: Confused about github rebasing

2012-03-15 Thread James Miller
moment it is peacful and helpful, the next it is scary and threatening to eat your files. Also, git-svn isn't actually that bad... -- James Miller

Re: Parse issue

2012-03-11 Thread James Miller
assert(parse!uint(s2, 16) == 0xff); // fail, it's 0 > } > > I think parse should pop the first two characters if the string starts with > 0x. > > > Side-note, it would be nice if std.string.isNumeric took a radix. :) I agree, seems like a bug to me. -- James Miller

Re: Remarks on std.container

2012-03-08 Thread James Miller
On 8 March 2012 23:16, Matthias Walter wrote: > On 03/08/2012 10:48 AM, James Miller wrote: >> On Thursday, March 08, 2012 10:21:48 Matthias Walter wrote: >>> but the following did not work: >>> >>> std.algorithm.swap(arrayInstance[i], arrayInstance[j]);

Re: [Inline assembler] Sequential `asm` blocks and return via EAX

2012-03-08 Thread James Miller
eturn a value is used here and there in > http://dlang.org/iasm.html For 1. I'd say that it would probably work, but you can't necessarily rely on that, you may have to live with a bit of code duplication. For 2. It seems that it should be fine, I can't check it right now, but I would be surprised if it didn't compile and run. -- James Miller

Re: Remarks on std.container

2012-03-08 Thread James Miller
On Thursday, March 08, 2012 10:21:48 Matthias Walter wrote: >but the following did not work: > >std.algorithm.swap(arrayInstance[i], arrayInstance[j]); What error did you get exactly? Since that exact call should work. "It didn't work" doesn't help. -- James Miller

Re: Can I do an or in a version block?

2012-03-07 Thread James Miller
a static if somehow? I don't think there is an 'elseif' for versions, probably because you are normally checking mutually exclusive version descriptions. Otherwise, its probably a good idea to keep the syntax as is, since it stops people from abusing the mechanic. -- James Miller

Re: 0 < negative loop condition bug or misunderstanding on my part

2012-03-07 Thread James Miller
ned integer? > > I really don't get it... > > It's like déjà-vu all the time in this newsgroup. Its the semantics in C/C++ and D explicitly tries to have the same semantics as them. From what I remember its to aid people moving from those language to D. -- James Miller

Re: 0 < negative loop condition bug or misunderstanding on my part

2012-03-07 Thread James Miller
owing negatives is clearly >> > better and more intuitive. Because you don't describe things as -5 metres tall, so you don't describe things as -1024 bytes long. size_t makes sense unsigned because negatives make no sense for size. However, if you cast array.length to an int, it may work, haven't tested it. -- James Miller

Re: Is there a wrapper for libuv?

2012-03-06 Thread James Miller
On 7 March 2012 14:47, Tyler Jameson Little wrote: > >> You shouldn't have to do anything with them, just write bindings for >> the api, with all the correct types. >> >> -- >> James Miller > > > Thanks! I guess I got a little over-zealous in portin

Re: Is there a wrapper for libuv?

2012-03-06 Thread James Miller
x27;t > find: > > sys/types.h > netinet/in.h > > Do these already exist? sys/types is part of the C runtime if I remember correctly, and netinet/in.h is part of the Unix networking interface. You shouldn't have to do anything with them, just write bindings for the api, with all the correct types. -- James Miller

Re: Cocoa bindings?

2012-03-01 Thread James Miller
On 2 March 2012 18:52, Alex Rønne Petersen wrote: > Hi, > > Are there any actively-maintained Cocoa bindings for D? > > -- > - Alex Not as far as I know. You should make some! -- James Miller

Re: Why do bitfields throw exceptions instead of wrapping?

2012-02-29 Thread James Miller
available is missing the point. Hell bitfields are provided by templates, so they aren't even a part of the language, they are just a library feature. Hope that helps -- James Miller

Re: Regarding std.array.Appender

2012-02-29 Thread James Miller
At some point, you have to concede design purity to convenience, otherwise you have a language that is actively hostile to changing designs. *In best "nagging wife" voice* "You should have used an Appender from the start. Now you have to go change all that code. Its your own fault really."... -- James Miller

Re: how to use raw sockets

2012-02-29 Thread James Miller
Obviously you need to do a reasonable job, but it is only writing function prototypes, so there's not much that can go wrong. -- James Miller

Re: passing a string with the & character as an argument

2012-02-28 Thread James Miller
On 29 February 2012 20:21, Jos van Uden wrote: > On 29-2-2012 7:06, James Miller wrote: >> >> On 29 February 2012 18:51, jic  wrote: >>> >>> >>> Greetings! >>> >>> I have this program, >>> >>> import std.process : s

Re: Random behavior using a wrapped C library

2012-02-28 Thread James Miller
> Yes. Tested on x32, and it works just fine. I'll use ia32libs and -m32 for > the time being then. > > A strange thing is that memory consumption went _up_ when everything was > compiled as x32. I don't know much, but wouldn't bigger register sizes mean that less data needs shuffled in and out of memory? Resulting in less instructions and therefore less memory usage? I'm just guessing though -- James Miller

Re: passing a string with the & character as an argument

2012-02-28 Thread James Miller
ror on your shell, saying that it cannot find the command 4#. Its because '&' is a special character used to fork a process into the background, useful for gui programs and the like. I have tried your code, using a *nix shell, and using 3\& works. If you are on Windows, then I don't know why this is happening. -- James Miller

Re: Reflection

2012-02-27 Thread James Miller
t;class template" etc... > Not really, there might be, but not an obvious one. Its because templates can hold multiple types of declarations, not just functions or classes. The "eponymous template" pattern you see normally is not mandatory. -- James Miller

Re: class templates and static if

2012-02-26 Thread James Miller
n functionality to the base class, then add specific functionality to the individual classes. It also allows for more reflection, which is easier and probably more powerful than conditional compilation. -- James Miller

Re: produced binary is quite big

2012-02-26 Thread James Miller
On 26 February 2012 21:28, Jabba Laci wrote: > Hi, > > I'm new to D. I tried the basic Hello World program ("dmd hello.d") > but it produced a 316 KB big binary. The same thing with C ("gcc > hello.c") is about 9 KB. Is there a way to reduce the size of the > produced binary? > > Thanks, > > Laszl

Re: 2.058 broke my build. Is this a bug?

2012-02-24 Thread James Miller
On Feb 25, 2012 12:16 PM, "Caligo" wrote: > > That was a typo, and it doesn't change anything. Here is a shorter version: > > 8<8< > import std.datetime; > import std.stdio; > > struct A{ > > auto fun(A a){ return 0; } > } > > void bench(alias fun)

Re: mixin template FAIL

2012-02-24 Thread James Miller
7;t. You're right. I guess I have a long way to go to learn these things. > > Thank you. Even at my primitive level, though, I can see how awesome these things could be once you know how to program them. Does any other language come close to D in terms of generics? I don't know, I'm just asking? > > Zach Lisp macros. But that's not a fair comparison, Lisp's object system was built using their macros... -- James Miller

Re: Adding overloaded methods

2012-02-23 Thread James Miller
On 24 February 2012 12:06, H. S. Teoh wrote: > On Fri, Feb 24, 2012 at 04:06:52AM +1300, James Miller wrote: >> On 23 February 2012 13:15, BLM wrote: >> > After messing around for a while, I figured out what is making DMD choke >> > on my >> > file. The me

Re: Linking with d3d11.dll/lib

2012-02-23 Thread James Miller
implib.html and has this: /s[ystem] - Prepend '_' to exported internal names. Used to create import library from Windows NT system DLLs (for example, kernel32.dll). Note that this switch is not available via the ID I hope that helps, I don't actually do any windows programming so I can't test this at all -- James Miller

Re: D runtime Garbage Collector details

2012-02-23 Thread James Miller
)? I don't know the answers to 1 or 2, but I know that there is a GC class with a bunch of methods on it for controlling the GC, including enabling and disabling it and getting GC-allocated memory. Whether that helps you write GC predictable code - I don't know, garbage collection is mostly a black art to me :-) -- James Miller

Re: D, Derelict2, and OpenGL

2012-02-23 Thread James Miller
I find that when learning a complicated system or library, the best way is to write out the code examples, compile them, then change things until they break, fix it, then make more changes. Eventually you end up with the worst code ever known to man and a thorough understanding of the system at han

Re: Adding overloaded methods

2012-02-23 Thread James Miller
ases > are all in the same piece of code :) And the award for "Most Meta Code" goes too... -- James Miller

Re: Wrapping c variadic functions

2012-02-23 Thread James Miller
On 23 February 2012 23:35, simendsjo wrote: > Say i have a c function (didn't include first format argument for > simplicity) > > void print(...); > I wrap it up: > extern(System) void print(...); > > And then I try to wrap it up in some safer D way: > void print(Args...)(Args args) > { >    print

Re: Weird opEquals Problem

2012-02-23 Thread James Miller
to learn the language in more depth :) > > We don't mind. :-) > > > T > > -- > Truth, Sir, is a cow which will give [skeptics] no more milk, and so > they are gone to milk the bull. -- Sam. Johnson Just don't start asking too stupid questions (like how does 1+1 work?) :P. -- James Miller

Re: inout problems

2012-02-21 Thread James Miller
On 22 February 2012 17:01, Andrej Mitrovic wrote: > class Foo > { >    this(int) inout >    { } > >    Foo makeFoo() { return new Foo(1); } > } > > void main() { } > > test.d(8): Error: cannot implicitly convert expression (new Foo(1)) of > type inout(Foo) to test.Foo > > Is this a bug? I have no

Re: std.regex named matches

2012-02-21 Thread James Miller
On 22 February 2012 04:45, Dmitry Olshansky wrote: > On 21.02.2012 7:34, James Miller wrote: >> >> On 20 February 2012 21:34, Dmitry Olshansky  wrote: >>> >>> 08.02.2012 13:07, James Miller пишет: >>> >>>> >>>> Hi, >>>

Re: Removing items from an Array

2012-02-20 Thread James Miller
On 18 February 2012 05:30, Jonathan M Davis wrote: > On Friday, February 17, 2012 14:44:42 Mars wrote: >> On Friday, 17 February 2012 at 13:33:25 UTC, James Miller wrote: >> > AAs don't keep the key order, so when you delete something out >> > of it, >> &

Re: std.regex named matches

2012-02-20 Thread James Miller
On 20 February 2012 21:34, Dmitry Olshansky wrote: > 08.02.2012 13:07, James Miller пишет: >> >> Hi, >> >> I am using std.regex and using the named matches. I would like to be >> able to get at the names that have matched, since this is library >> code. >

Re: vim tips for D development

2012-02-19 Thread James Miller
I use vim, and I find that just vanilla vim does the job fine for me. I don't tend to use autocomplete unless its really smart (like using clang-complete for C/C++), and I should probably grab the latest D syntax file. mostly just judicious use of "/" and "gg" gets me most places.

Re: Removing items from an Array

2012-02-17 Thread James Miller
AAs don't keep the key order, so when you delete something out of it, what ever system iterates to the next pointer gets confused. Its generally a bad idea to modify an array as you loop through it. -- James Miller

Re: Anti-OOP... stupid?

2012-02-14 Thread James Miller
On 15 February 2012 12:12, H. S. Teoh wrote: > On Tue, Feb 14, 2012 at 11:47:52PM +0100, Timon Gehr wrote: >> [...] >> It does not hurt at all if your code base is more flexible than >> necessary. > [...] > > This needs to be taken in moderation, though. > > I've had to work with code that was unn

Re: Chatting with a server

2012-02-14 Thread James Miller
data flow. The advantage of event-based systems is that you can be waiting for data from the server and for user input at the same time, meaning that a slow server doesn't break your client or render it unusable. If the code works for you, then its probably fine. James Miller

Re: Arrays - Inserting and moving data

2012-02-13 Thread James Miller
On 14 February 2012 12:45, Ali Çehreli wrote: > On 02/13/2012 03:34 PM, James Miller wrote: > >> Saying "it is not quicksort as much as it may conceptually resemble >> quicksort" is kinda odd, its like saying "it is not a car, as much as >> it may conceptu

Re: Instance-specific unittests

2012-02-13 Thread James Miller
On 14 February 2012 12:26, Jonathan M Davis wrote: > On Monday, February 13, 2012 15:12:15 H. S. Teoh wrote: >> I discovered something really cool today, and I thought I'd share it >> with my fellow learners: >> >> The unittest block is used for inserting unit tests that are executed at >> runtime

Re: Arrays - Inserting and moving data

2012-02-13 Thread James Miller
On 14 February 2012 06:25, Timon Gehr wrote: > On 02/13/2012 03:19 PM, James Miller wrote: >> >> On 11 February 2012 10:45, Jonathan M Davis  wrote: >>> >>> On Friday, February 10, 2012 13:32:56 Marco Leise wrote: >>> >>>> I know that fe

Re: Arrays - Inserting and moving data

2012-02-13 Thread James Miller
On 11 February 2012 10:45, Jonathan M Davis wrote: > On Friday, February 10, 2012 13:32:56 Marco Leise wrote: >> I know that feeling. I had no exposure to functional programming and >> options like chain never come to my head. Although "map" is a concept that >> I made friends with early. > > It w

std.regex named matches

2012-02-08 Thread James Miller
.captures.names; or something similar. I've looked at the library and I can't find anything of the sort, and you can't even use `foreach` to get at them that way, I'm guessing because you can have both integer and string indexes for the matches. Thanks James Miller

Re: How to reverse char[]?

2012-02-07 Thread James Miller
char_array:\t%s", to!string(hasSwappableElements!(typeof(char_array; writefln("hasSwappableElements ubyte_array:\t%s", to!string(hasSwappableElements!(typeof(ubyte_array; } The output is isBidirectonalRange char_array: true isBidirectonalRange ubyte_array:true hasSwappableElements char_array:false hasSwappableElements ubyte_array: true So if just just need an array of bytes and the `char' semantics are unimportant, then you can just use a ubyte instead. However Timon is correct that there should probably be a narrow string version of `reverse'. James Miller