Re: Read non-UTF8 file

2011-02-21 Thread Stewart Gordon
What compiler version/platform are you using? I had to fix some errors before it would compile on mine (1.066/2.051 Windows). On 19/02/2011 13:42, Nrgyzer wrote: Now... and with writefln("%s", cast(ubyte[]) convertToUTF8(f.readLine())); I get the following: [195, 131, 164] [195, 131, 182] [

Re: Win7 64-bit

2011-03-06 Thread Stewart Gordon
On 01/03/2011 23:19, Dan McLeran wrote: never mind, i got it. i had to pass the switches: -D -unittest -cov life is hard. it's even harder when you're dumb. Would you care to enlighten the rest of us on what code you were using that requires those extra switches? Stewart.

Re: Win7 64-bit

2011-03-07 Thread Stewart Gordon
On 07/03/2011 02:10, Jonathan M Davis wrote: If you're using -cov, you probably want -unittest, I disagree: - Most of the time I use -cov, it's to check the normal flow of program logic, rather than the unittests. It's true that it *can* be used to check that the unittests cover all cases

Re: Writing an integer to a file

2011-03-07 Thread Stewart Gordon
On 07/03/2011 12:11, %u wrote: this is part of the code: Posting the whole code (or even better, a minimal, complete program that shows the problem) helps a lot. void WritePushPop(cmd command, string segment, int index) { string temp = "TextFile.Asm"

Re: Read file/stream

2011-03-11 Thread Stewart Gordon
On 11/03/2011 18:46, Steven Schveighoffer wrote: I am not sure what facilities Phobos provides for reading/writing integers in network order (i.e. Big Endian), but I'm sure there's something. http://www.digitalmars.com/d/1.0/phobos/std_stream.html EndianStream I haven't experimented with it.

Re: Read file/stream

2011-03-11 Thread Stewart Gordon
On 11/03/2011 19:50, Ali Çehreli wrote: There is also std.intrinsic.bswap Well spotted. I don't tend to look at std.intrinsic much. Presumably there's a reason that it's been provided for uint but not ushort or ulong Stewart.

Re: Read file/stream

2011-03-11 Thread Stewart Gordon
On 11/03/2011 21:51, Steven Schveighoffer wrote: Presumably there's a reason that it's been provided for uint but not ushort or ulong I think things in std.intrinsic are functions that tie directly to CPU features, True, but... so presumably, the CPU only provides the possibility for

Re: Unicode -> Windows 1252

2011-03-18 Thread Stewart Gordon
On 16/03/2011 22:17, Tom wrote: I have a D2 code that writes some stuff to the screen (usually runs in cmd.exe pseudo-console). When I print spanish characters they show wrong (gibberish symbols and so, wich corresponds to CP-1252 encoding). Is there a way to convert all outputted streams to CP

Re: What are delimited strings good for?

2011-04-11 Thread Stewart Gordon
On 10/04/2011 21:51, Jonathan M Davis wrote: If that had been `something instead of 'something, _then_ the delimited string becomes useful, but given how rarely backticks are needed, it does seem rather odd to have delimited strings just for that. So, I definitely have to wonder why they exist.

Re: static variables for non-constant expressions?

2011-04-11 Thread Stewart Gordon
On 11/04/2011 02:37, Jonathan M Davis wrote: I don't know the background of how static variables really work, so is there a good reason why the first function can't work like the one below it? They have to be calculated at compile time so that ordering doesn't matter. If the order mattered, th

Re: Next Release

2011-04-25 Thread Stewart Gordon
On 22/04/2011 20:48, Jonathan M Davis wrote: Well, then I'd better make sure that I get my most recent updates to std.datetime in soon. - Jonathan M Davis Does your library take into account that there's no year 0? Actually, for ISO 8601, which the library follows, there _is_ a year 0. And

Re: Shouldn't duplicate functions be caught by DMD?

2011-05-08 Thread Stewart Gordon
On 08/05/2011 09:41, bearophile wrote: Andrej Mitrovic: I think the compiler should check catch these mistakes at compile-time. I suggest to add an enhancement request in Bugzilla. Bugzilla entries are a form of "voting" by themselves too. One should not file stuff in Bugzilla without fir

Re: int or size_t ?

2011-05-08 Thread Stewart Gordon
On 07/05/2011 18:09, %u wrote: In Patterns of Human Error, the slide 31 point that you should replce int with size_t why that consider an error ? For those who aren't sure what this is on about: http://www.slideshare.net/dcacm/patterns-of-human-error But the short answer is because dim is a si

Re: toHash() and Interfaces

2011-05-11 Thread Stewart Gordon
On 06/05/2011 13:02, Steven Schveighoffer wrote: D has this horrible notion that any interface can be for a COM object, even though COM interfaces can only inherit from IUnknown (known statically). Therefore, interfaces that don't inherit from IUnknown are not considered Objects, even though t

Re: .init of field == type's initializer or field initializer?

2011-05-21 Thread Stewart Gordon
On 20/05/2011 04:19, Andrej Mitrovic wrote: Foo.b.init is actually 0. Are the docs wrong, or is the compiler wrong? Let me know so I can fix the docs if necessary as I'm doing that now. Known issue: http://d.puremagic.com/issues/show_bug.cgi?id=5715 Stewart.

Re: What is this strange alias syntax?

2011-05-22 Thread Stewart Gordon
On 21/05/2011 10:15, Simen Kjaeraas wrote: On Sat, 21 May 2011 05:12:20 +0200, Andrej Mitrovic wrote: Taken from the docs: alias int func(int); It's the old C syntax for defining function pointers. Functions, not function pointers. The C syntax for declaring function pointers is i

Re: What is this strange alias syntax?

2011-05-22 Thread Stewart Gordon
On 22/05/2011 11:57, Steven Schveighoffer wrote: On Sat, 21 May 2011 05:15:32 -0400, Simen Kjaeraas wrote: It's the old C syntax for defining function pointers. Well, without the pointer. And that last part is important, because the latter example is an array of function pointers, with which

Re: What is this strange alias syntax?

2011-05-22 Thread Stewart Gordon
On 22/05/2011 16:20, Timon Gehr wrote: Andrej Mitrovic wrote: Should I file a bug report to kill this syntax? No. It is perfectly valid, see grammar: http://www.digitalmars.com/d/2.0/declaration.html Grammar states only that it's syntactically valid, and makes no comment on semantic validit

Re: What is this strange alias syntax?

2011-05-23 Thread Stewart Gordon
On 23/05/2011 07:43, David Nadlinger wrote: On 5/23/11 8:41 AM, Andrej Mitrovic wrote: What's wrong with using this: alias void function(int, int) funcAlias; It's a function pointer type, not a function type. How is that something wrong with it? I.e. what can you do with a function type

Re: What is this strange alias syntax?

2011-05-23 Thread Stewart Gordon
On 22/05/2011 21:51, Timon Gehr wrote: I suspect what Andrej actually meant is to kill treating function signatures as types in this way. And possibly "enhancement request" rather than "bug". It is the opposite of an enhancement request. It means removing a feature that cannot be meaningfull

Re: Assert allowed to have side effects?

2011-05-29 Thread Stewart Gordon
On 29/05/2011 09:44, simendsjo wrote: The documentation for assert, http://www.digitalmars.com/d/2.0/expression.html#AssertExpression, states that it's an error if the assert expression contains side effects, but it doesn't seem the compiler is enforcing this. There are places where the spec

Re: Assert allowed to have side effects?

2011-05-30 Thread Stewart Gordon
On 29/05/2011 14:03, bearophile wrote: Stewart Gordon: There are places where the spec fails to make a clear distinction between illegal code and incorrect code that the compiler may reject if it's smart enough. In D there are pure functions, so I think it's not too much hard for

Re: Make a variable single-assignment?

2011-11-30 Thread Stewart Gordon
On 21/11/2011 20:06, Jesse Phillips wrote: What you are describing is Head Const, and is not available. http://www.d-programming-language.org/const-faq.html#head-const It will not be added as it doesn't provide any guarantees about the code that is useful to the compiler. It can't be added to

Re: Formatted date

2011-12-01 Thread Stewart Gordon
On 03/11/2011 23:58, Lishaak Bystroushaak wrote: Hello. Is there any way how to format date with formating strings? Yes. See the datetime stuff in http://pr.stewartsplace.org.uk/d/sutil/ Stewart.

Re: Formatted date

2011-12-01 Thread Stewart Gordon
On 04/11/2011 00:51, Jonathan M Davis wrote: On Thursday, November 03, 2011 16:58 Lishaak Bystroushaak wrote: Hello. Is there any way how to format date with formating strings? Something like strftime in python; http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior Not c

Re: writef %d of string

2011-12-01 Thread Stewart Gordon
On 12/10/2011 23:41, bearophile wrote: This code, that a sane language/language implementation refuses at compile-time, runs: It's perfectly legal code, so the best a compiler can correctly do is give a warning. Some C(++) compilers understand printf and will warn if the format string doesn't

Re: Formatted date

2011-12-01 Thread Stewart Gordon
On 01/12/2011 16:44, Jonathan M Davis wrote: On Thursday, December 01, 2011 11:28:39 Stewart Gordon wrote: I could've sworn it was you I was talking to about the stuff in my library before. Are you an imposter? Why would I be an imposter? If you weren't, you would already kno

Re: Formatted date

2011-12-01 Thread Stewart Gordon
On 01/12/2011 22:57, Jonathan M Davis wrote: There's a halfway decent chance that I posted in this thread prior to reading anything about your library or before I looked at it at all. And both Lishaak's and your computers had their clocks set several days fast at the time? Stewart.

Re: writef %d of string

2011-12-04 Thread Stewart Gordon
On 02/12/2011 03:19, bearophile wrote: Stewart Gordon: It's perfectly legal code, If that code is legal, then in my opinion it's the rules of the language that are wrong and in need to be changed :-) You mean all programming languages should support CTFE for argument validation

Re: Void initialization

2011-12-20 Thread Stewart Gordon
On 19/12/2011 18:11, Steven Schveighoffer wrote: On Mon, 19 Dec 2011 12:24:18 -0500, Bear wrote: gc.malloc actually returns void[] http://www.d-programming-language.org/phobos/core_memory.html#malloc Looks like void* to me... Or is there another function I'm not aware of? I think it should

Re: Void initialization

2011-12-20 Thread Stewart Gordon
On 19/12/2011 12:12, bearophile wrote: Bear: float[] f = cast(float[])std.gc.malloc(x*4); Try something like this (untested): alias float TF; TF[] f = (cast(TF*)std.gc.malloc(x * TF.sizeof))[0 .. x]; I fail to see any real difference from the OP's code: - Why the alias? - std.gc.malloc

Re: Void initialization

2011-12-20 Thread Stewart Gordon
On 20/12/2011 18:12, bearophile wrote: Because in that code I have used three times a type (TF), auto allows to remove only one of them. The alias is not the best solution (a better solution is to put that code into a templated function), but repeating the same generic type more than one time

Re: newbie question: Can D do this?

2011-12-20 Thread Stewart Gordon
On 20/12/2011 20:36, Philippe Sigaud wrote: That is, it expects some values, then string/values couples as associative arrays. I've a recollection of seeing something like this in the PHP library, but I forget where. I believe it's used in some functions that have a lot of options to set, s

Re: Void initialization

2011-12-20 Thread Stewart Gordon
On 20/12/2011 22:19, bearophile wrote: That's also why I have said a better solution is to wrap that code into a function template, so there is no need for an alias. So what you actually meant was to make TF a template parameter? That would make more sense. I can understand an alias being

Re: typedef deprecated - now what ?

2011-12-31 Thread Stewart Gordon
On 30/12/2011 10:35, Stephan wrote: is there a template or something in phobos to get the same typesafe behaviour of good old typedef ? Could someone please provide a link to the thread with the reasons for deprecating typedef? There are too many threads with the words "typedef" and "depreca

Re: typedef deprecated - now what ?

2012-01-01 Thread Stewart Gordon
On 31/12/2011 13:34, Trass3r wrote: Basically it was deprecated because it's poorly defined and implemented. Would you care to elaborate? Moreover, if that's the only reason then why not improve it rather than getting rid of it? There are several types of typedefs that need to be availabl

Re: Bug or feature? std.c.stdlib.exit() breaks RAII

2012-01-06 Thread Stewart Gordon
On 29/12/2011 19:09, Jacob Carlborg wrote: Could druntime hook up on the atexit function to run destructors and similar when the program exits? I'm not sure. Maybe it could be called upon to run static destructors and destruct heap-allocated objects. But in order to call scope guards and R

Re: Bug or feature? std.c.stdlib.exit() breaks RAII

2012-01-06 Thread Stewart Gordon
On 06/01/2012 14:44, Andrej Mitrovic wrote: Just implement your own exception type, e.g. ExitException, and then use: That's more or less what people have already said. What's more, Ashish has already suggested a further improvement whereby the custom exception carries an exit code. void m

Re: An issue with lazy delegates

2012-01-09 Thread Stewart Gordon
On 05/01/2012 05:26, Andrej Mitrovic wrote: The first call doesn't do anything because the delegate is wrapped inside of another delegate. I want this template to be versatile enough to be used by both lazy expressions and delegate literals, but I don't know how. If you have a delegate you wa

Re: Taking a function or delegate as argument.

2012-01-10 Thread Stewart Gordon
On 10/01/2012 19:56, Jacob Carlborg wrote: A template parameter with a template constraint will accept any callable type. Function pointer, delegate, struct/class overloading the call operator and so on. Indeed, this is done in the C++ STL quite a lot. The drawback is that templated methods

Re: Taking a function or delegate as argument.

2012-01-10 Thread Stewart Gordon
On 10/01/2012 19:56, Jacob Carlborg wrote: A template parameter with a template constraint will accept any callable type. Function pointer, delegate, struct/class overloading the call operator and so on. Moreover, if you want to save the callback for later use, you need to distinguish the ca

Re: Error: 'this' is only defined in non-static member functions, not parse

2012-01-17 Thread Stewart Gordon
For future reference and to elaborate on what others have said, if you're asking for help solving a problem with your code, then please: 1. Post a small, self-contained testcase that demonstrates the problem straight out of the box. Tips here: http://www.sscce.org/ 2. Post full compiler outp

Re: inout constructor?

2012-01-27 Thread Stewart Gordon
On 26/01/2012 15:27, Steven Schveighoffer wrote: auto tsm = TestStruct(&xm); auto tsc = TestStruct(&xc); auto tsi = TestStruct(&xi); writeln(typeof(tsm).stringof); // TestStruct writeln(typeof(tsc).stringof); // const(TestStruct) writeln(typeof(tsi).stringof); // immutable(TestStruct) To actu

Re: i18n

2012-02-02 Thread Stewart Gordon
On 02/02/2012 18:48, xancorreu wrote: Hi, Is there any way for localizate and internationalizate messages? I were shocked if D has something like Fantom [http://fantom.org/doc/docLang/Localization.html]. Gettext is pretty ugly ;-) Is this just about supporting different human languages in your

Re: maketrans and translate

2012-02-13 Thread Stewart Gordon
On 13/02/2012 03:04, bearophile wrote: In the online docs I've seen that std.string.maketrans() is (going to be) deprecated. How do you adapt this code to the new regime? Use an associative array for the translation table. Or write your own functions that work in the same way as maketrans/tr

Re: float.nan is not itself ?

2012-02-14 Thread Stewart Gordon
On 14/02/2012 15:39, Joshua Reusch wrote: Hello, why does this assertion fail: assert(float.nan == float.nan); there is the std.math.isNaN function which works correctly, but why can I not just use the comparison ? A NaN typically denotes some kind of invalid computation. If the results

Re: More octal questions

2012-02-15 Thread Stewart Gordon
On 15/02/2012 16:41, Jonathan M Davis wrote: They're not left over at all, and they have nothing to do with octal. They are something to do with octal: because in D an integer literal beginning with 0 is defined to be octal, the compiler must interpret them as such if it is going to accept

Re: Hex floats

2012-02-15 Thread Stewart Gordon
On 15/02/2012 21:33, H. S. Teoh wrote: On Wed, Feb 15, 2012 at 01:24:13PM -0800, H. S. Teoh wrote: [...] This is ambiguous, since you could interpret 0xFFp0F as either 0xFFp0 followed by the suffix 'F', or 0xFFp0F with an exponent of 0x0F no suffix. [...] Actually, nevermind that. I misread th

Re: Hex floats

2012-02-16 Thread Stewart Gordon
On 16/02/2012 12:04, Don Clugston wrote: On 15/02/12 22:24, H. S. Teoh wrote: What's the original rationale for requiring that hex float literals must always have an exponent? For example, 0xFFi obviously must be float, not integer, so why does the compiler (and the spec) require an exponent?

Re: delegate as memeber

2012-02-25 Thread Stewart Gordon
On 21/02/2012 17:46, Jacob Carlborg wrote: On 2012-02-21 16:55, deadalnix wrote: You can implement a static opCall and use that instead of the constructor. But you don't have to call a static opCall. You can just declare a struct instance without any initialisation. Presumably half the po

Re: Simple operator precidence chart (and associativity)?

2012-03-14 Thread Stewart Gordon
On 13/03/2012 23:14, Timon Gehr wrote: (Also, for associativity: Assign and OpAssign are right-associative and everything else is left-associative, correct?) Power is right-associative too. You forgot the conditional operator. And the relational operators are non-associative (a == b == c

Re: Tail call optimization?

2012-03-19 Thread Stewart Gordon
On 18/03/2012 21:28, bearophile wrote: Alex Rønne Petersen Wrote: Does D to tail call optimization of any kind? The D standard doesn't require the D compiler to perform that optimization (unlike Scheme). Currently both DMD and LDC are able to perform tail call optimization in some normal ca

Making sense of ranges

2012-03-24 Thread Stewart Gordon
The documentation for std.range states http://dlang.org/phobos/std_range.html "This module defines the notion of range (by the membership tests isInputRange, isForwardRange, isBidirectionalRange, isRandomAccessRange), range capability tests (such as hasLength or hasSlicing), and a few useful ra

Re: Making sense of ranges

2012-03-24 Thread Stewart Gordon
On 24/03/2012 18:57, Ali Çehreli wrote: Iterating an output range is also by popFront(). So what it says is, put this element to the output range and advance the range. There is a gotcha about this when the output range is a slice: Whatever is just put into the range is popped right away! :) [

Re: Read a unicode character from the terminal

2012-03-31 Thread Stewart Gordon
On 31/03/2012 16:56, Jacob Carlborg wrote: How would I read a unicode character from the terminal? I've tried using "std.cstream.din.getc" but it seems to only work for ascii characters. If I try to read and print something that isn't ascii, it just prints a question mark. What OS are you usin

Re: Read a unicode character from the terminal

2012-04-04 Thread Stewart Gordon
On 31/03/2012 23:14, Stewart Gordon wrote: You might want to try the console module in my utility library: http://pr.stewartsplace.org.uk/d/sutil/ (For D1 at the moment, but a D2 version will be available any day now!) The D2 version is now up on the site. Jacob - would you be up for

Re: Read a unicode character from the terminal

2012-04-04 Thread Stewart Gordon
On 04/04/2012 17:37, Jacob Carlborg wrote: Sure I can help you with testing. I have a lot on my own table so I don't have any time for implementing things (maybe some small things). If I may ask, what is the point of this library? Just to hold some miscellaneous utility classes/structs/funct

SUL for Posix (was: Read a unicode character from the terminal)

2012-04-05 Thread Stewart Gordon
On 05/04/2012 07:18, Jacob Carlborg wrote: Ok, I see. The functions that need a Posix implementation are mostly in datetime and commandline, if I recall correctly. These are already present in Phobos? Maybe it contains the code I need to finish datetime off. Though I can't really just copy

Re: SUL for Posix

2012-04-07 Thread Stewart Gordon
On 05/04/2012 14:51, Jacob Carlborg wrote: http://dlang.org/phobos/std_getopt.html But it might not do what you want. Where is the code in std.getopt that has any relevance whatsoever to what smjg.libs.util.datetime or smjg.libs.util.commandline is for? Stewart.

Re: SUL for Posix

2012-04-07 Thread Stewart Gordon
On 07/04/2012 17:54, Jacob Carlborg wrote: Both std.getopt and mjg.libs.util.commandline handle command line arguments? What's that to do with anything? If the code I need to finish smjg.libs.util.commandline is somewhere in std.getopt, please tell me where exactly it is. If it isn't, then

Re: SUL for Posix

2012-04-07 Thread Stewart Gordon
On 07/04/2012 20:16, Jacob Carlborg wrote: I don't know what your module is supposed to do. Then how about reading its documentation? http://pr.stewartsplace.org.uk/d/sutil/doc/commandline.html If there's something you don't understand about it, this is the issue that needs to be addressed,

Re: Multiple %s format specifiers with a single argument

2012-04-10 Thread Stewart Gordon
On 09/04/2012 18:35, Andrej Mitrovic wrote: On 4/9/12, Jonathan M Davis wrote: Posix positional arguments seem to work for writefln but not format for whatever reason. Report it as a bug. Thanks, http://d.puremagic.com/issues/show_bug.cgi?id=7877 Andrej, are emails from Bugzilla not getting

Re: Multiple %s format specifiers with a single argument

2012-04-10 Thread Stewart Gordon
On 10/04/2012 13:30, Andrej Mitrovic wrote: On 4/10/12, Stewart Gordon wrote: Andrej, are emails from Bugzilla not getting through to you? I'm not getting any emails. Bugzilla stopped emailing me for quite a while now, I don't know why (except the monthly password reminder). Ass

Re: Clearly Label D1/D2/Tango/Phobos

2012-04-18 Thread Stewart Gordon
On 18/04/2012 13:34, Paul wrote: I bought the book and am trying to patiently learn this language. I follow various tutorials here and around the web that frequently won't compile. I suspect it has something to do with D1/D2/Phobos/Tango and not just really poor unvetted tutorials. It would re

Re: T : T*

2012-04-18 Thread Stewart Gordon
On 13/04/2012 19:47, Jonathan M Davis wrote: I'd just like to verify that my understanding of T : T* in this template is correct: struct S(T : T*) it appears that the compiler is instead taking this to mean that the pointer part of the type should be stripped from the template argument's type

Re: Formatting dates in std.datetime?

2012-04-21 Thread Stewart Gordon
On 20/04/2012 21:29, H. S. Teoh wrote: Is there a way to format std.datetime.Date objects with a custom format string? My utility library has a datetime module with a custom formatting facility. http://pr.stewartsplace.org.uk/d/sutil/ The format string scheme is one of my own design, using re

Re: Docs: Section on local variables

2012-04-21 Thread Stewart Gordon
On 20/04/2012 01:53, Andrej Mitrovic wrote: Can I remove this section from the D docs, in functions? : " Local Variables It is an error to use a local variable without first assigning it a value. The implementation may not always be able to detect these cases. Other language compilers sometimes

Re: Docs: Section on local variables

2012-04-25 Thread Stewart Gordon
On 21/04/2012 19:24, H. S. Teoh wrote: In finished code, it's obviously a bad thing to have unused variables (unless the compiler optimizes them away, Whether the compiler optimises it away or not, an unused variable is a code smell. Complaining about unused variables serves as a warning to t

Re: Docs: Section on local variables

2012-04-25 Thread Stewart Gordon
On 21/04/2012 17:26, Andrej Mitrovic wrote: Next thing you know the compiler will start warning me when I indent my code with uneven number of spaces! Or more usefully, warn if you have a mishmash of tab and space indentation. How do indent-sensitive languages (Haskell, Python, whatever else)

Re: Docs: Section on local variables

2012-04-25 Thread Stewart Gordon
On 25/04/2012 17:10, Andrej Mitrovic wrote: On 4/25/12, Stewart Gordon wrote: Even if it's left over from debugging, it looks silly, and might lead other people reading the code to believe something's wrong. There's about a million ways to make code unreadable, and nobo

Re: Docs: Section on local variables

2012-04-25 Thread Stewart Gordon
On 25/04/2012 21:12, Andrej Mitrovic wrote: I'm really only talking about: void a() { int x; } What is the distinction you're making exactly? And of course: void a() { bool state; ... if (state) { } } You mean an empty if body should trigger something? Or shouldn't? OK, so I can see a si

OT: Indent-sensitive languages again (was: Docs: Section on local variables)

2012-04-25 Thread Stewart Gordon
On 25/04/2012 12:30, Stewart Gordon wrote: On 21/04/2012 17:26, Andrej Mitrovic wrote: Next thing you know the compiler will start warning me when I indent my code with uneven number of spaces! Or more usefully, warn if you have a mishmash of tab and space indentation. How do indent

Re: Docs: Section on local variables

2012-04-26 Thread Stewart Gordon
On 26/04/2012 08:26, Timon Gehr wrote: Another thing: It might not be unused in every static code path. One way to deal with this would be to do the checking before conditional compilation. That said, I've a feeling that mixin expansion might get in the way of this. Even more important: t

Re: Docs: Section on local variables

2012-04-26 Thread Stewart Gordon
On 26/04/2012 08:26, Timon Gehr wrote: template isInputRange(R) { enum bool isInputRange = is(typeof( { R r; // can define a range object if (r.empty) {} // can test for empty r.popFront(); // can invoke popFront() auto h = r.front; // can declare an unused variable }())); } This is indeed a

Re: Docs: Section on local variables

2012-04-26 Thread Stewart Gordon
On 26/04/2012 15:05, Stewart Gordon wrote: http://d.puremagic.com/issues/show_bug.cgi?id=7989 From JMD: "The fact that isInputRange and isForwardRange rely on declaring variables which aren't used being legal. It would be really annoying for unused local variables to be illegal wh

Re: Docs: Section on local variables

2012-04-26 Thread Stewart Gordon
On 26/04/2012 22:52, bearophile wrote: For uncommon situations like isInputRange a specific annotation solves the problem cleanly. As does the compiler swallowing warnings in the content of an IsExpression as I already suggested. How many C/C++ programmers do you know that use lints? I t

Re: Transforming a range back to the original type?

2012-05-03 Thread Stewart Gordon
On 02/05/2012 22:01, Jacob Carlborg wrote: Is there a general function for transforming a range back to the original type? If not, would it be possible to create one? To sum it up, it can't be done in the general case. The range API doesn't know or care about the underlying data structure.

Re: ProjectEuler problem 35

2012-05-19 Thread Stewart Gordon
On 16/05/2012 10:46, Dmitry Olshansky wrote: Don't ever do that. I mean allocating memory in tight cycle. Instead use circular buffer. (just use the same array and wrap indexes) You might as well not use a string representation at all. At the beginning of the loop, calculate the number of d

Re: ProjectEuler problem 35

2012-05-20 Thread Stewart Gordon
On 19/05/2012 16:13, maarten van damme wrote: A huge optimization could be made by storing and int array of already found primes and test all primes smaller then half the to-test number. this will speed up a lot. Do you mean build an array of already-found primes and use them to test new primes

Re: Limit number of compiler error messages

2012-05-27 Thread Stewart Gordon
On 22/05/2012 18:36, cal wrote: 2>&1 | head -n Where is your dmd/rdmd/build script command. There's probably something similar you could use on Windows, I don't really know though. By "something similar" do you mean a way of piping stderr, or a head utility? A head utility is trivial to c

Re: opCmp, opEquals

2008-10-28 Thread Stewart Gordon
"bearophile" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] I have a small question regarding OOP design. The signature of opCmp, opEquals when defined inside classes require a Object argument. So you have to define what to do when the given object can't be cast to the this class. H

Re: Getting environment variables?

2008-11-22 Thread Stewart Gordon
"Christopher Wright" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Hey all, How do I get environment variables in a D program? std.c.stdlib.getenv http://www.cplusplus.com/reference/clibrary/cstdlib/getenv.html I specifically want the path to a user's home folder. Platform-de

Re: Getting environment variables?

2008-11-23 Thread Stewart Gordon
"novice2" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] homeDrive = toString(getenv("HOMEDRIVE")).dup; homePath = toString(getenv("HOMEPATH")).dup; don't forget, that D char[] is utf8 and windows char* is 8-bit chars, not utf8. so you should import std.windows.charset and

Re: expected array behaviour

2009-01-02 Thread Stewart Gordon
Mike James wrote: const char[26] array1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char[26] array2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; It doesn't occur. Is this expected behaviour? Yes. Static arrays have value semantics, unlike dynamic arrays, which have reference semantics. Stewart.

Re: Window procedure declaration

2009-01-06 Thread Stewart Gordon
John Reimer wrote: There are many win32 functions missing from std.c.windows.windows. Check www.dsource.org/projects/core32 for a more complete D win32 import. That one's old and, by the looks of it, no longer maintained. You want this one: http://www.dsource.org/projects/bindings/wiki/Wind

Re: Window procedure declaration

2009-01-06 Thread Stewart Gordon
Stewart Gordon wrote: John Reimer wrote: There are many win32 functions missing from std.c.windows.windows. Check www.dsource.org/projects/core32 for a more complete D win32 import. That one's old and, by the looks of it, no longer maintained. You want this one: http://www.dsourc

Re: invalid utf-8 sequence

2009-01-06 Thread Stewart Gordon
james wrote: im writing an indexer, but im having a problem because on some file, when i read gives this error Error 4: invalid UTF-8 sequence is there a way to fix it. Probably, but since you've decided not to post your code, nobody can tell you for sure what that way is. Moreover, wha

Re: invalid utf-8 sequence

2009-01-07 Thread Stewart Gordon
james wrote: Jarrett Billingsley Wrote: On Tue, Jan 6, 2009 at 8:04 PM, james wrote: im writing an indexer, but im having a problem because on some file, when i read gives this error Error 4: invalid UTF-8 sequence is there a way to fix it. You're probably reading a file that's encoded i

Re: timezone problem

2009-01-13 Thread Stewart Gordon
Qian Xu wrote: BTW: Is there any Date.Format("-mm-dd") function? Not in Phobos. But there is such a thing in my utility library: http://pr.stewartsplace.org.uk/d/sutil/ Stewart.

Re: timezone problem

2009-01-13 Thread Stewart Gordon
Sergey Gromov wrote: I thought that std.date.getUTCtime(), std.date.UTCtoLocalTime() and std.date.LocalTimetoUTC() were quite enough. std.date is somewhat badly designed - a time can be in any time zone but has no time zone information in it. And toString(d_time) expects a UTC time but form

Re: timezone problem

2009-01-14 Thread Stewart Gordon
Kagamin wrote: Even windows doesn't have this kind of heuristics. The only solution is to keep all timestamps in UTC and leave local time representation only for user eyes and don't care about its precision. That's the best thing indeed for timestamps and the like. For some other kinds of ap

Re: Guideline for D1/2 compatible code?

2009-01-17 Thread Stewart Gordon
Trass3r wrote: Are there any guidelines for writing code compilable with both dmd 1.x and 2.x? This is to make a library usable by users of either, I presume? I can give a few: - Have a module to define types for such things as pointers/arrays that will be const in D2. - Use version(D_Vers

Re: Guideline for D1/2 compatible code?

2009-01-18 Thread Stewart Gordon
Trass3r wrote: I'd like to use "alias char[] string", but dmd complains about conflicts with the builtin "alias invariant(char)[] string" Is there any way to redefine string in the scope of the library? I don't think so. I know I could simply use another name or use char[] but if it's poss

Re: D_Version2 problem

2009-01-18 Thread Stewart Gordon
Hoenir wrote: The D_Version2 version identifier doesn't work properly for me. Tried compiling with dmd 1.039. D_Version2 is set even if I pass -v1 to it. Is this a bug Works for me, as this code demonstrates: -- import std.stdio; void main() { version (D_Version2) { writef

Re: state of win32 headers?

2009-02-03 Thread Stewart Gordon
akcom wrote: What is the state of the win32 headers? Looking for people like you to help complete the work. But usable. Stewart.

Re: A array bug?

2009-02-04 Thread Stewart Gordon
Ellery Newcomer wrote: taqya wrote: char[] a = "a".dup; char[] b = "b".dup; writefln(a + b); //Error: Array operations not implemented If so, the error informs you why you can't do that. Except that it doesn't. "Array operations not implemented" is a leftover from a previou

Re: A array bug?

2009-02-05 Thread Stewart Gordon
Chris Nicholson-Sauls wrote: Suggest: Array operation '' not implemented for type []. Where is here '+' and 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, which this isn't. And possibly cat

Re: Char[] confusing

2009-03-05 Thread Stewart Gordon
Qian Xu wrote: IMO, it does not make any sense. s[start..end] end - is neither the count of characters in the array slice, nor the end index of the slice. it is just the index after the real end character. It might help to think of the indexes in a slice as numbering the

Re: immutable storage class?

2009-03-06 Thread Stewart Gordon
Sergey Kovrov wrote: I cannot find any information about immutable keyword. http://d.puremagic.com/issues/show_bug.cgi?id=2572 Stewart.

Re: array and pointer

2009-03-06 Thread Stewart Gordon
takeshi wrote: Hello, I have just started learning D. Welcome. I cannot compile the code in the documentation on array and pointer either with dmd (D 2.0) and gdmd (D 1.0). Known error in the docs. http://d.puremagic.com/issues/show_bug.cgi?id=996 Stewart.

  1   2   >