.. 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
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
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
flexible, and often performs some work at run-time too. Given such design a
string-int conversion is better left to to!().
Bye,
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
fit). So 95% of the arguments of your program are better tagged with in.
Bye,
bearophile
that
produces a compile error if you apply it to a function that's not
tail-recursive?
Bye,
bearophile
is mutability where
needed, and a bit more functional-style everywhere else :-)
Bye,
bearophile
newsgroup (and maybe later
worth an enhancement request).
Bye,
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
)
{
debug assert(bar != 0);
Asserts go away with -release. So generally I don't need to write that.
Bye,
bearophile
)
somethingNifty(Point(x, y));
}
Bye,
bearophile
));
ForwardRange!int[] a2 = [r1, r2];
}
Bye,
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
fault
Also try to compile it with -O :-)
Bye,
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
seen D. I'll take a look in Bugzilla if
there is already something on this.
Bye,
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
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
(ejnqrwxdsyftamcivbkulopghzEJNQRWXDSYFTAMCIVBKULOPGHZ,
0111222333445566677788899901112223334455666777888999);
auto text2 = text.translate(tab, \);
writeln(text2);
}
Bye,
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
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
in mind there are many
different NaNs (I think double.nan and double.init are different in the bits
too).
Bye,
bearophile
,
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
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
, but
most CPUs around are not that good:
http://www.agner.org/optimize/blog/read.php?i=142
Bye,
bearophile
not
a type yet.
Bye,
bearophile
newsgroup. The more people
asks for something similar, the more probable/sooner that it will be
implemented.
Bye,
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
}
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
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
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
Ali:
At first reading, that seems to disqualify constructors.
inout was recently improved, and I think its documentation is not updated
enough.
Bye,
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
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
just raw pointers :-)
Bye,
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
named init() in
structs? (Especially if they are a @property). Or maybe there is a better
solution, opinions welcome.
Bye,
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
simendsjo:
Perhaps also the documentation for opCmp should be improved..?
Also, and maybe here DMD has to give better error messages :-)
Bye,
bearophile
there is a problem.
Bye,
bearophile
Do you know why std.array.Appender defines a put method instead of
overloading the ~= operator?
Bye and thank you,
bearophile
and ~= operator.
Bye,
bearophile
(...) {...
Bye,
bearophile
[] a) {
a ~= 5;
a.length++;
}
I have had some of such bugs in my D code.
Bye,
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
);
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
= { 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
Andrej Mitrovic:
I think parse should pop the first two characters if the string starts with
0x.
I agree.
Bye,
bearophile
'];
sort(a1);
char[] a2 = ['a', 'b', 'c'];
sort(cast(ubyte[])a2);
}
Bye,
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
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
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
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
the same.
Bye,
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
-defined function.
Bye,
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
) void function() funcB;
}
Bye,
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
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
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
.
Bye,
bearophile
;
} else {
enum isFoo = false;
}
}
void main() {
auto f1 = new Foo!(true, false)();
static assert(isFoo!(typeof(f1)));
}
Bye,
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
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
,
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
to on the list?)
Bye,
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
than the D type system if you also want it
to be sufficiently handy to use.
Bye,
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
.
Bye,
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
). Lately I
hit new bugs less often, but they happen still.
Bye,
bearophile
near the top of the list of my enhancement requests :-)
Bye,
bearophile
of Phobos will be put
in your binary, usually a little more than the induced tree of
functions you use.
Bye,
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
/Category:D
Bye,
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
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
instantiating
Is this good/expected?
Bye,
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
Maybe related to this?
http://d.puremagic.com/issues/show_bug.cgi?id=7864
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
, urng, N, true);
Bye,
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
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
,
bearophile
is essentially the same as before:
http://dlang.org/dbc.html
Bye,
bearophile
I'd like the solution used by C# + an annotation to not
initialize a variable or array.
Bye,
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
{
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
some constructors...
Bye,
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
) {
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
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
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
the situation.
Bye,
bearophile
://www.yesodweb.com/
).
Bye,
bearophile
1 - 100 of 3204 matches
Mail list logo