Re: Assigning to char[N]

2012-02-01 Thread bearophile
.. s1.length] = s1; writeln(a); string s2 = new content; a[0 .. s2.length] = s2; writeln(a); a[0 .. new content.length] = new content; writeln(a); } Bye, bearophile

Re: Assigning to char[N]

2012-02-01 Thread bearophile
to this: // // Error: template std.algorithm.copy(Range1,Range2) if // (isInputRange!(Range1) // isOutputRange!(Range2,ElementType!(Range1))) does not match any // function template declaration Try harder. Try to slice that a. Bye, bearophile

Re: Why I could not cast string to int?

2012-02-02 Thread bearophile
Alex Rønne Petersen Wrote: On 02-02-2012 17:26, xancorreu wrote: Why cast(int) does not work and I have to call another function? Thanks, Al 02/02/12 17:24, En/na Adam D. Ruppe ha escrit: On Thursday, 2 February 2012 at 16:21:39 UTC, xancorreu wrote: $ ./factorial 222 Factorial

Re: Why I could not cast string to int?

2012-02-02 Thread bearophile
flexible, and often performs some work at run-time too. Given such design a string-int conversion is better left to to!(). Bye, bearophile

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-02 Thread bearophile
gotta catch them all expression, because it leads to hiding other bugs in your code, and this is a source for troubles. Bye, bearophile

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-02 Thread bearophile
fit). So 95% of the arguments of your program are better tagged with in. Bye, bearophile

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-02 Thread bearophile
that produces a compile error if you apply it to a function that's not tail-recursive? Bye, bearophile

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-03 Thread bearophile
is mutability where needed, and a bit more functional-style everywhere else :-) Bye, bearophile

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-03 Thread bearophile
newsgroup (and maybe later worth an enhancement request). Bye, bearophile

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-03 Thread bearophile
Timon Gehr: However, it is nice that the shortest storage class, 'in', implies scope. I'd like to ask this to be valid, to shorten my code: alias immutable imm; Is this silly? Bye, bearophile

Re: Contracts vs debug

2012-02-04 Thread bearophile
) { debug assert(bar != 0); Asserts go away with -release. So generally I don't need to write that. Bye, bearophile

Re: Struct inheritance

2012-02-04 Thread bearophile
) somethingNifty(Point(x, y)); } Bye, bearophile

Less typed ranges

2012-02-04 Thread bearophile
)); ForwardRange!int[] a2 = [r1, r2]; } Bye, bearophile

Re: Less typed ranges

2012-02-04 Thread bearophile
Ali: It already exists: inputRangeObject() supports the accessing ranges and outputRangeObject takes care of output ranges. Thank you, I did miss them :-) Bye, bearophile

Re: linux linenumbers in stacktraces and druntime/phobos debug

2012-02-08 Thread bearophile
fault Also try to compile it with -O :-) Bye, bearophile

Re: D at work

2012-02-08 Thread bearophile
% of the changes are progressive, and compiling DMD+Phobos requires a very short time, and I avoid some troubles I used to have. Probably few years from now the situation will slow down, and a more relaxed approach will be enough, like updating my code every release or two. Bye, bearophile

Re: Compiler error with static vars/functions

2012-02-09 Thread bearophile
seen D. I'll take a look in Bugzilla if there is already something on this. Bye, bearophile

Re: Templated aliases name in compilation error output

2012-02-11 Thread bearophile
with the alias name rather than the original, but that's just not how it works at this point. Vote for this president :-) http://d.puremagic.com/issues/show_bug.cgi?id=5004 Bye, bearophile

Regarding a recent copy() fix

2012-02-12 Thread bearophile
me an answer, but I am being dumb, and I don't understand: I don't think it would have the same semantics in all cases. memmove() requires semantics identical to if an intermediate buffer were used. Imagine copying a[4..9] to a[5..10]. Bye and thank you, bearophile

maketrans and translate

2012-02-12 Thread bearophile
(ejnqrwxdsyftamcivbkulopghzEJNQRWXDSYFTAMCIVBKULOPGHZ, 0111222333445566677788899901112223334455666777888999); auto text2 = text.translate(tab, \); writeln(text2); } Bye, bearophile

Re: maketrans and translate

2012-02-13 Thread bearophile
maketrans and translate functions too and to un-deprecate them (maybe moving them in std.ascii)? They are not UTF-safe, but I have large amounts of biological data text that is not Unicode. Bye, bearophile

Re: maketrans and translate

2012-02-13 Thread bearophile
ASCII-only string stuff. Around there is a large amount of data that is essentially text, but it's ASCII, it's not Unicode. Like biological data, text data coming out of instruments, etc. Handling it as binary data is not good. Bye, bearophile

Re: float.nan is not itself ?

2012-02-14 Thread bearophile
in mind there are many different NaNs (I think double.nan and double.init are different in the bits too). Bye, bearophile

Re: Anti-OOP... stupid?

2012-02-14 Thread bearophile
, bearophile

Re: Anti-OOP... stupid?

2012-02-15 Thread bearophile
with type classes, Haskell template extensions, are designed to satisfy different needs and constraints. All of them are used and useful, none of them are perfect. Bye, bearophile

Re: maketrans and translate

2012-02-15 Thread bearophile
Jonathan M Davis: I'll look into the best way to handle it. Those functions aren't being deprecated this release regardless. I have added the topic to Bugzilla to avoid its oblivion: http://d.puremagic.com/issues/show_bug.cgi?id=7515 Bye, bearophile

Flushing denormals to zero

2012-02-16 Thread bearophile
, but most CPUs around are not that good: http://www.agner.org/optimize/blog/read.php?i=142 Bye, bearophile

Re: Let this() figure out T implicitly?

2012-02-17 Thread bearophile
not a type yet. Bye, bearophile

Re: Everything on the Stack

2012-02-20 Thread bearophile
newsgroup. The more people asks for something similar, the more probable/sooner that it will be implemented. Bye, bearophile

A inner pure function problem

2012-02-20 Thread bearophile
This compiles, but it's not nice: int sqr(in int x) pure { return x * x; } immutable sqrPtr = sqr; auto outer(typeof(sqrPtr) foo) pure { pure int inner() { return foo(5); } return inner(); } void main() { assert(outer(sqrPtr) == 25); } Bye and thank you, bearophile

Re: A inner pure function problem

2012-02-20 Thread bearophile
} Nice. The fact that qualifying the parameter with immutable directly causes a matching failure in IFTI appears to be a bug. http://d.puremagic.com/issues/show_bug.cgi?id=7554 Thank you, bye, bearophile

Re: Compress spaces to one space

2012-02-21 Thread bearophile
Andrej Mitrovic: Is there a Phobos function to compress all spaces to just one space in a string? E.g. foo bar becomes: foo bar import std.string; void main() { assert( foo bar .squeeze() == fo bar ); } Bye, bearophile

Re: Everything on the Stack

2012-02-21 Thread bearophile
Don Clugston: Does the library solution actually work the same as the language solution? Some time ago scoped worked worse than the built-in scope: http://d.puremagic.com/issues/show_bug.cgi?id=5115 But I don't know how well scoped works now, I have never used it any more. Bye, bearophile

Re: inout problems

2012-02-22 Thread bearophile
Ali: At first reading, that seems to disqualify constructors. inout was recently improved, and I think its documentation is not updated enough. Bye, bearophile

Re: Everything on the Stack

2012-02-22 Thread bearophile
int[1_000_000] array; void main() {} Ok I'll do that. Thanks once more. Generally Walter listens to efficiency concerns. You are welcome. Bye, bearophile

Re: Everything on the Stack

2012-02-22 Thread bearophile
Try this too: __gshared int[1_000_000] array; void main() {} Sorry, I meant: __gshared int[1_000_000] array = void; void main() {} Bye, bearophile

About CTFE and pointers

2012-02-24 Thread bearophile
just raw pointers :-) Bye, bearophile

Re: Pure and higher-order functions

2012-02-24 Thread bearophile
mist: Are there any reasons for this inconsistency? I don't know. Maybe it's just a parser bug. There are some of those in Bugzilla. If you don't like it, then I suggest you to add it to D Bugzilla. Bye, bearophile

struct init() method

2012-02-24 Thread bearophile
named init() in structs? (Especially if they are a @property). Or maybe there is a better solution, opinions welcome. Bye, bearophile

Re: Is empty array null?

2012-02-28 Thread bearophile
in place, where the pointer points to the contents of the array (chars or numbers or other things) (and there is a bit more stuff in the allocated memory block to manage array appending a bit more efficiently). So you are always allowed to read the array/string length. Bye, bearophile

Re: How can I use structs in a named enum?

2012-02-29 Thread bearophile
simendsjo: Perhaps also the documentation for opCmp should be improved..? Also, and maybe here DMD has to give better error messages :-) Bye, bearophile

Re: How can I use structs in a named enum?

2012-02-29 Thread bearophile
there is a problem. Bye, bearophile

Regarding std.array.Appender

2012-02-29 Thread bearophile
Do you know why std.array.Appender defines a put method instead of overloading the ~= operator? Bye and thank you, bearophile

Re: Regarding std.array.Appender

2012-02-29 Thread bearophile
and ~= operator. Bye, bearophile

Re: Using lazily ?

2012-03-01 Thread bearophile
(...) {... Bye, bearophile

Re: Is empty array null?

2012-03-05 Thread bearophile
[] a) { a ~= 5; a.length++; } I have had some of such bugs in my D code. Bye, bearophile

Re: Why is std.algorithm.reduce impure?

2012-03-06 Thread bearophile
this (now bug 2443 is fixed) at about line 723: // For now, just iterate using ref to avoid unnecessary copying. // When Bug 2443 is fixed, this may need to change. foreach(ref elem; r) { if(initialized) Bye, bearophile

Re: Parallelization issues

2012-03-08 Thread bearophile
); Error: template std.array.popFront(A) You are trying to do popFront on a fixed sized array. Try to use int[][] instead of int[][2]. Bye, bearophile

Immutable unions

2012-03-11 Thread bearophile
= { bar2: 100 }; // error } The latest DMD gives: test.d(12): Error: variable bug.main.foo2 is not a static and cannot have static initializer Bye and thank you, bearophile

Re: Parse issue

2012-03-11 Thread bearophile
Andrej Mitrovic: I think parse should pop the first two characters if the string starts with 0x. I agree. Bye, bearophile

Re: Sorting char arrays

2012-03-12 Thread bearophile
']; sort(a1); char[] a2 = ['a', 'b', 'c']; sort(cast(ubyte[])a2); } Bye, bearophile

Re: Why doesn't this have a length?

2012-03-12 Thread bearophile
Magnus Lie Hetland: Am I doing something illegal?-) It looks legal. As usual I suggest to minimize the code, and show us the reduced case that shows the problem :-) Bye, bearophile

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread bearophile
Alex R. Petersen: (Stylistic note: use equals_t instead of bool.) What is equals_t? See it's used here: http://dlang.org/phobos/object.html Bye, bearophile

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread bearophile
is required to return a bool, the value 25 has to become 1, this is not just a narrowing. This conversion requires one instruction, I think. Bye, bearophile

Re: Problem about Tuple.opEquals, const qualifier

2012-03-17 Thread bearophile
Tongzhou Li: I'm learning D, and trying to convert My C++ code into D: http://pastebin.com/eCz9DdZ3 I have translated a small part of your C++ program: http://codepad.org/hnKGxRUM There is no good stack collection in Phobos yet (possibly decks-based). Bye, bearophile

Re: Tail call optimization?

2012-03-18 Thread bearophile
the same. Bye, bearophile

Re: Tail call optimization?

2012-03-19 Thread bearophile
for months an no one noticed. I have written a bug report and they have made it work again. And then they have put it in their demo :-) http://llvm.org/demo/ Bye, bearophile

Re: Comparison issue

2012-03-19 Thread bearophile
-defined function. Bye, bearophile

Re: Is there an elegant way of making a Result eager instead of lazy?

2012-03-20 Thread bearophile
simendsjo: std.array includes a method, array(), for doing exactly this: int[] test2 = array(map!a+a(test1)); //eager With 2.059 you can write that also in a more readable way, because there is less nesting: int[] test2 = test1.map!q{a + a}().array(); Bye, bearophile

Re: Converting C .h Files to D Modules

2012-03-20 Thread bearophile
) void function() funcB; } Bye, bearophile

Re: Regarding writefln formatting

2012-03-20 Thread bearophile
Andrej Mitrovic: I didn't know that! Is this documented anywhere? It's documented formally, but I see no usage examples of the nested formatting syntax: http://dlang.org/phobos/std_format.html Bye, bearophile

Re: anonymous static array

2012-03-21 Thread bearophile
Jesse Phillips: int[100][string] counts; int[100] a; counts[some_key] = a; counts[some_key][20]++; Someone is currently trying to improve/fix AAs, this seems a problem that is worth trying removing. Bye, bearophile

Re: Calculating/Averaging over a struct value

2012-03-21 Thread bearophile
Brian Brady: // but if I write x[].para if throws an error This is a quite natural syntax, and I think it's handy, but it's not supported yet. Bye, bearophile

Re: Calculating/Averaging over a struct value

2012-03-21 Thread bearophile
. Bye, bearophile

Re: Template constraint and specializations

2012-03-23 Thread bearophile
; } else { enum isFoo = false; } } void main() { auto f1 = new Foo!(true, false)(); static assert(isFoo!(typeof(f1))); } Bye, bearophile

Re: string[] to char**

2012-03-23 Thread bearophile
!toStringz(data)).ptr; printf(%s %s %s\n, p[0], p[1], p[2]); } Note: the pointer array is managed by the D GC. With DMD 2.059: immutable(char)** p = data.map!toStringz().array().ptr; Bye, bearophile

Re: string[] to char**

2012-03-24 Thread bearophile
simendsjo: Oh, I didn't find toStringz, so I turned it into: It's in std.string. auto c_strings = strings.map!(toUTFz!(char*)).array().ptr; That's wrong syntax, that 2.059head doesn't enforce yet, map needs an ending (). Bye, bearophile

Re: GC collecting too much..

2012-03-25 Thread bearophile
, and free it manually or in a struct destructor (RAII) or with scope(exit). - Keep a pointer to the D-GC memory in the D code too. - In core.memory there are ways to disable scanning of a memory zone. Maybe it's usable for your purposes too. Bye, bearophile

Re: How to remove element from an SList?

2012-03-27 Thread bearophile
to on the list?) Bye, bearophile

Regarding nWayUnion

2012-03-31 Thread bearophile
.. $])])); } Isn't it better for it to just accept a variable number of arguments? T[] mergeSort(T)(in T[] D) { if (D.length 2) return D.dup; return array(nWayUnion(mergeSort(D[0 .. $ / 2]), mergeSort(D[$ / 2 .. $]))); } Bye, bearophile

Re: Length of an SLIst ?

2012-04-02 Thread bearophile
than the D type system if you also want it to be sufficiently handy to use. Bye, bearophile

Re: Questions about the slice operator

2012-04-03 Thread bearophile
, generally because implicit conversions are often a bad thing. Requiring some syntax to denote the lazy-eager conversion is positive, I think I don't know of a language that perform such conversion implicitly. Bye, bearophile

Re: log2 buggy or is a real thing?

2012-04-04 Thread bearophile
. Bye, bearophile

Re: log2 buggy or is a real thing?

2012-04-04 Thread bearophile
Do you know why is this program: import std.stdio; void main() { real r = 9223372036854775808UL; writefln(%1.19f, r); } Printing: 9223372036854775807.800 Instead of this? 9223372036854775808.000 Bye, bearophile

Re: Up to date documentation on D implementation.

2012-04-05 Thread bearophile
). Lately I hit new bugs less often, but they happen still. Bye, bearophile

Re: Questions about the slice operator

2012-04-05 Thread bearophile
near the top of the list of my enhancement requests :-) Bye, bearophile

Re: D1, D2, Tango, Phobos, Std, Runtime

2012-04-06 Thread bearophile
of Phobos will be put in your binary, usually a little more than the induced tree of functions you use. Bye, bearophile

Re: asm stackframe question

2012-04-07 Thread bearophile
Stefan: Ideas, anyone? Use the naked attribute and do it all by yourself? Keep also in mind that D functions that contain ASM don't get inlined in DMD (and probably elsewhere too). Bye, bearophile

Re: Input from a newbie

2012-04-07 Thread bearophile
/Category:D Bye, bearophile

Re: string concatenation

2012-04-08 Thread bearophile
dnewbie: string s = toUTF8(v) ~ , world!; MessageBoxA(null, s.toStringz, myapp, MB_OK); return 0; } I suggest to compile all your code with -property plus -w (or -wi), unless you have some specific needs to not do it. Bye, bearophile

Re: DMD/Windows: Inspect generated ASM?

2012-04-08 Thread bearophile
Stefan: Unlike gdc, dmd it has no -S option, I'd like that. This seems a nice enhancement request for you to add in Bugzilla. Bye, bearophile

A problem with mutable toString

2012-04-08 Thread bearophile
instantiating Is this good/expected? Bye, bearophile

Re: Input from a newbie

2012-04-09 Thread bearophile
are too much rigid, and so on and on. So if you want you are able to use that site to learn how to design languages too, a bit. - That site has several other smaller purposes. Bye, bearophile

Re: A problem with mutable toString

2012-04-09 Thread bearophile
Maybe related to this? http://d.puremagic.com/issues/show_bug.cgi?id=7864

Re: Name of files causes error. Why?

2012-04-12 Thread bearophile
Manfred Nowak: On the contrary: it requires work to implement limitations. Therefore limitations are implemented only to shield users from mess. Also, removing limitations from a language is usually FAR simpler than introducing them later :-) Bye, bearophile

Re: Sampling algorithms for D

2012-04-12 Thread bearophile
, urng, N, true); Bye, bearophile

Re: Sampling algorithms for D

2012-04-12 Thread bearophile
thing, not the important code ... :-) In my opinion demo code is a bit like unittests. And unittests require the same coding precision as the rest of the code :-) Bye, bearophile

Re: Sampling algorithms for D

2012-04-12 Thread bearophile
for the function. Then use a function/method precondition: final size_t select(ref UniformRNG urng) in { assert(_recordsRemaining 0); assert(_sampleRemaining 0); } body { ... } Bye, bearophile

Re: Sampling algorithms for D

2012-04-13 Thread bearophile
, bearophile

Re: Sampling algorithms for D

2012-04-13 Thread bearophile
is essentially the same as before: http://dlang.org/dbc.html Bye, bearophile

Re: floats default to NaN... why?

2012-04-14 Thread bearophile
I'd like the solution used by C# + an annotation to not initialize a variable or array. Bye, bearophile

Re: floats default to NaN... why?

2012-04-15 Thread bearophile
F i L: I should be able to tackle something like adding a compiler flag to default FP variables to zero. If I write the code, would anyone object to having a flag for this? I strongly doubt Walter Andrei will accept this in the main DMD trunk. Bye, bearophile

Re: const AB c = {a,20, numbers};

2012-04-16 Thread bearophile
{ int a, b; int [] numbers; } void main() { import std.stdio; int a = 300; const numbers = new int[2]; const c = const(AB)(a, 20, numbers); writeln(c); } Bye, bearophile

Re: Aquivalent References as in C++?

2012-04-16 Thread bearophile
some constructors... Bye, bearophile

Re: const AB c = {a,20, numbers};

2012-04-16 Thread bearophile
Timon Gehr: auto c = AB(a, 20, numbers) = AB c = {a, 20, numbers}; auto c = const(AB)(a, 20, numbers) = const AB c = {a, 20, numbers}; I think your second equivalence is wrong: const c = AB(a, 20, numbers) = const AB c = {a, 20, numbers}; Bye, bearophile

Re: Memoizing a templated function

2012-04-16 Thread bearophile
) { return n * n; } T test2(T)(T n) { return n * n; } void main() { int n = 5; n = memoize!test(n); // OK n = test2(n); // OK n = memoize!(test2!int)(n); // OK n = memoize!(test2!(typeof(n)))(n); // OK } Bye, bearophile

Re: retro() on a `string` creates a range of `dchar`, causing array() pains

2012-04-17 Thread bearophile
Jakob Ovrum: return array(strippedTail); } The type of the return expression is dstring, not string. What is the most elegant way or correct way to solve this friction? (Note: the function is used in CTFE) Try text instead of array. Bye, bearophile

Re: retro() on a `string` creates a range of `dchar`, causing array() pains

2012-04-17 Thread bearophile
Ali Çehreli: The reason is, a sequence of UTF-8 code units are not a valid UTF-8 when reversed (or retro'ed :p). But reversed(char[]) now works :-) Bye, bearophile

Re: retro() on a `string` creates a range of `dchar`, causing array()

2012-04-17 Thread bearophile
the situation. Bye, bearophile

Re: retro() on a `string` creates a range of `dchar`, causing array()

2012-04-17 Thread bearophile
://www.yesodweb.com/ ). Bye, bearophile

  1   2   3   4   5   6   7   8   9   10   >