Daniel Kozak:
http://stackoverflow.com/questions/24600796/d-set-default-value-for-a-struct-member-which-is-a-multidimensional-static-arr/24754361#24754361
Do you also know why the simplest syntax doesn't work? Can't it
be implemented and added to the D language?
Bye,
bearophile
Tomer Rosenschtein:
Awesome article.
Paper of the week is a modest word for this.
The D code is not good.
Bye,
bearophile
, and I think this is good.
Bye,
bearophile
Walter Bright:
We need to do a lot better.
I agree. D has to come back to the living. It looks like D is
hibernating.
Bye,
bearophile
years old D code.
Bye,
bearophile
development trying to solve it will cause more
problems (and more wasted efforts) than it can solve.
Bye,
bearophile
Walter Bright:
Just for fun, I've decided to try and [...]
There's a pull in need of some love, I'd like to see this in D:
https://github.com/D-Programming-Language/dmd/pull/3615
Bye,
bearophile
to the old names can be kept for a long
time without causing problems
This is usually true, but not always (see above).
3. when removed entirely, the documentation for them should be
kept along with instructions on corrective action
I agree.
Bye,
bearophile
Uranuz:
Same situation happens when I assign reference data to
properties.
Someone has suggested to solve this problem with an attribute,
like owned, that forbids to return mutable reference data owned
by a class/struct instance.
Bye,
bearophuile
several
lazy items to a dynamic array? This doesn't work:
void main() {
import std.array, std.range;
int[] arr;
arr.put(only(1, 2, 3));
}
Bye,
bearophile
[] = 1;
HeadConst!int c = arr;
HeadConst!int d;
arr = d; // fail
}
Bye,
bearophile
,
bearophile
performance a little). But I'd call it extend as in
Python.
Bye,
bearophile
Kagamin:
You can't change coding practice by introducing a new type.
We can try to change coding practice introducing new types :-)
Bye,
bearophile
the
compiler finds the bug:
class MyClass {
this() {}
void someFunction() {
//body
}
}
void main() {
MyClass classObject;
classObject.someFunction;
}
test.d(11,5): Error: null dereference in function _Dmain
But in more complex cases the compiler doesn't.
Bye,
bearophile
Oleg:
how create variable that store const object and can be changed
to other const object?
Take a look at std.typecons.Rebindable/std.typecons.rebindable.
Read all Phobos documentation, it helps.
Bye,
bearophile
a warning if you use the built-in sort and reverse.
Unfortunately the library reverse still needs to be fixed to
return the array as the built-in reverse.
Bye,
bearophile
unsigned types.
I think the intention probably was to improve on the C
situation, where there is undefined behaviour that really
should be defined.
But do we really want to preclude ever having overflow checking
for integers?
+1
Bye,
bearophile
MattCoder:
May I understand that you're disabling the default
constructor of the struct to use your own constructor?
Right. So the instance data of the struct is more likely correct
when you call its methods.
Bye,
bearophile
Dmitry Olshansky:
Why is File.byLine so slow?
Seems to be mostly fixed sometime ago.
Really? I am not so sure.
Bye,
bearophile
Dmitry Olshansky:
Which is 1:1 parity. Another myth busted? ;)
There is still an open bug report:
https://issues.dlang.org/show_bug.cgi?id=11810
Do you want also to benchmark that byLineFast that for me is
usually significantly faster than the byLine?
Bye,
bearophile
{
return iota(5);
}
void main() {}
This limits the usefulness of post-conditions in my code. Do you
have ideas to solve this problem?
Bye,
bearophile
= b.length == 2));
} body {
auto a = new int[10];
return a.chunks(2);
}
void main() {}
Bye,
bearophile
to
consume the result in a post-condition check that doesn't
consume it.
I agree.
Bye,
bearophile
too.
Bye,
bearophile
).
The eager version creates an array of the results in heap memory.
Bye,
bearophile
doesn't offer me much good to
express this idiom, but I am not sure how much a type system can
help here even in principle.
Bye,
bearophile
.
And the @disable this() assures that a struct is correctly
initialized by the constructor.
This pattern has significant advantages regarding code
reliability.
You can see an example of this pattern that I've used here:
http://rosettacode.org/wiki/Solve_a_Hopido_puzzle#D
Bye,
bearophile
?
Bye,
bearophile
Walter Bright:
Except that isn't really quicksort. Monads are the workaround
functional languages use to deal with things that need mutation.
Take also a look at Clean language. It doesn't use monads and
it's a very efficient functional language.
Bye,
bearophile
Daniel Murphy:
void fun(int[] a)
{
foreach_reverse(i, 0...a.length)
{
}
}
Better (it's a workaround for a D design flaw that we're
unwilling to fix):
foreach_reverse(immutable i, 0...a.length)
Bye,
bearophile
Walter Bright:
I thought everyone hated foreach_reverse!
I love it!
Bye,
bearophile
is to have immutable on default and mutable on request.
If D doesn't have this quality, better to add immutable every
damn time).
Bye,
bearophile
floating point benchmarks
there's a huge difference between LDC2 and DMD).
Bye,
bearophile
Kapps:
The flags make it likely that DMD was used (-O -inline
-release).
But I use ldmd2 all the time with those arguments :-)
Bye,
bearophile
(no exceptions are involved):
https://issues.dlang.org/show_bug.cgi?id=6840
See also:
https://issues.dlang.org/show_bug.cgi?id=6843
Bye,
bearophile
Walter Bright:
If that is changed to a signed type, then you'll have a
same-only-different set of subtle bugs,
This is possible. Can you show some of the bugs, we can discuss
them, and see if they are actually worse than the current
situation.
Bye,
bearophile
uri:
It's by design
And it's a nice handy design.
Bye,
bearophile
an
ER for it, and otherwise to add the little diagnostic ER it to
Bugzilla.
Bye,
bearophile
compile and run this program:
void main() {
import std.stdio;
writeln(
first string
second ~
string
);
}
I see this output (and it's correct, as expected):
first stringsecondstring
Bye,
bearophile
Kent:
I am reading the book 《D Cookbook》
In Page 36,this code can't be complied:
auto filtered = filter!((a) = Clock.currTime() -
a.timeLastModified 14.days)(sorted);
Perhaps:
mySorted.filter!(a = Clock.currTime - a.timeLastModified
14.days);
Bye,
bearophile
/ulong. I don't agree with this
design decision, but it's unlikely that Walter has changed his
mind on it. So better to go on and discuss other things more
likely to happen.
Bye,
bearophile
workarounds (or to
use better designed languages. But no language is perfect).
Bye,
bearophile
work with x
}
That's all perfectly sound and good, but it's wasting tons of
time doing bounds checking! It's also totally unidiomatic.
This is nice:
fn split_at_mut(mut self, mid: uint) - (mut [T], mut [T]);
Bye,
bearophile
even if you just compare (with ) a length
with a signed value.
Bye,
bearophile
Andrei Alexandrescu:
No. -- Andrei
Yet, experience in D has shown very well that having unsigned
lengths is the wrong design choice. It's a D wart.
Bye,
bearophile
is saying that a system language
should not have unsigned values. The discussion here is about the
type of array lengths.
Bye,
bearophile
,
without going to full manual formal proof, that is an excessive
burden for most cases for most programmers.
Bye,
bearophile
Marco Leise:
foreach (i; 0 .. a.length)
{
somework();
}
Better:
foreach (immutable _; 0 .. a.length)
{
somework();
}
Unfortunately this syntax is not yet supported, for unknown
reasons:
foreach (; 0 .. a.length)
{
somework();
}
Bye,
bearophile
Wsdes:
union value {
const char *string;
}
Try:
union Value {
const char* myString;
}
Note the upper caseing, the spacing after the star, and the
string name replaced with something else.
Bye,
bearophile
programmers and language
implementators) than the Rust solution.
Bye,
bearophile
Wyatt:
So, how to write a source-to-source compiler from CS to D…? ;-)
I think it would be more useful would be to go the other way
around for targeting Windows Phone.
Perhaps it's better to make LDC2-LLVM output the intermediate
code of the dotnet :-)
Bye,
bearophile
Wsdes:
The wiki says that callback
functions should be declared as integer functions,
What's bad in returning void?
Bye,
bearophile
difficulties, is it
possible to ask for help to one of the persons that designed (or
watched closely design) the similar thing for Rust?
Bye,
bearophile
, std.array;
float[] vals = [1.1, 2.1, 3.1, 4.1];
auto arr = vals.map!(Foo!float).array;
arr.writeln;
}
Bye,
bearophile
,
bearophile
=c61b200fb0130f0b0f9f51b48e3799625b83
Bye,
bearophile
Andrei Alexandrescu:
One possibility is a function sortedChain that takes two or
more sorted ranges and returns a lazy sorted range. -- Andrei
Perhaps you are answering another thread and another problem. In
this problem there is only one range.
Bye,
bearophile
new Exception(Bad);
else {
static assert(is(typeof(y) == Natural));
return x / y;
}
}
In Whiley inside the else branch the _type_ of y is different.
Bye,
bearophile
Tomer Filiba:
http://wiki.dlang.org/DIP68
Perhaps your DIP also needs a trait?
struct Foo {}
@nogc struct Bar {}
static assert(!__traits(hasNogc, Foo));
static assert(__traits(hasNogc, Bar));
Byem
bearophile
Andrei Alexandrescu:
http://dlang.org/phobos/std_algorithm.html#.setUnion
That's right! -- Andrei
Still, this is very far from what I asked for...
Bye,
bearophile
Jacob Carlborg:
Don't we have something for that already?
Do you mean we already have a trait for a feature that doesn't
yet exists? :-)
Bye,
bearophile
the complexity, it
just increases the confusion. I greatly prefer when things with
different semantics have cleanly distinct names.
Bye,
bearophile
the same if you want to create a
lib):
dmd a.d b.d
Otherwise you can also use ddmd and let it find the module
dependencies by itself.
Bye,
bearophile
:
http://dlang.org/dstyle.html
Bye,
bearophile
Xavier Bigand:
So for the moment I build the web site on a physical machine,
and I saw the compilation takes around 1.6Go of memory.
Compiling the whole Phobos as a single compilation unit on 32 bit
DMD requires a little more than 1 GB.
Bye,
bearophile
convert
static arrays to dynamic arrays.
Yeah, what do you suggest to change in the language to avoid this
problem?
Bye,
bearophile
AlanThinker:
If there all classes in one file, the file will be to big.
The file will also probably contain several free functions, and
not just classes.
Bye,
bearophile
that kind of operations indiscriminately,
you reduce a lot the usefulness of D (because fixed size =
dynamic slice array is a conversion useful in many cases) and
probably force the introduction of many casts, and I don't know
if this will increase the overall safety of the D code.
Bye,
bearophile
!(fieldGetter(field1, field2));
Bye,
bearophile
Laeeth Isharc:
Walter Bright suggests that a supplementary benefit of using
contrats is helping the compiler make optimisations.
I think no D compilers do this, currently. And no one knows when
such things will be added, if ever.
Bye,
bearophile
,
bearophile
H. S. Teoh:
It's only a bad idea because people abuse assert() where it's
not appropriate.
It's a bad idea because Walter seems unable to understand the
difference between verifying and proving.
Bye,
bearophile
;
}
Bye,
bearophile
This was Issue 8405 opened by Jonathan M Davis two years ago, I
have added my use cases:
https://issues.dlang.org/show_bug.cgi?id=8405
Bye,
bearophile
working on it...
In most cases a built-in dynamic array is fine. Once in a while
you want to use an std.array.Array. When they are not enough, I
use a sorted tree or something else.
Bye,
bearophile
can have arbitrary many rows.
chain(m[0], m[1]).sort();
m.joiner.writeln;
}
Is it possible and reasonable for joiner to return a random
access range in such cases (where the input is a random access
range of random access ranges), so I can sort its items?
Bye,
bearophile
; }
SortedRange!(Foo[], q{ a.x b.x }) data;
data ~= Foo(5);
immutable n = data.upperBound(Foo(2)).length;
Bye,
bearophile
very
fast binary searches, unlike a heap).
So what solution do you suggest? A pair of functions that work on
a sorted container of that type for Phobos?
Bye,
bearophile
. Generally
it's better to not use a more complex data structure if a simpler
one suffices.
Bye,
bearophile
to use an assumeSorted(). This is not good.
Bye,
bearophile
!(a = a.sum);
Bye,
bearophile
alias this much).
Bye,
bearophile
, and little else).
Bye,
bearophile
(classInstanceSize, Foo));
pragma(msg, __traits(classInstanceSize, Bar));
}
Output:
12u
8u
Bye,
bearophile
Marc Schütz:
r.sortBy!(a = a.norm);
r.schwartzSort!(a = a.norm);
Bye,
bearophile
Nordlöw:
Ok, but this doesn't support multi-sorting, right?
If performance is not a top priority, you can use a tuple:
r.schwartzSort!(x = tuple(x.a, x.b, x.c));
Bye,
bearophile
well-behaving
guarantees.
Bye,
bearophile
designers don't
want it to be easy to do. And this is good.
Bye,
bearophile
those asserts.
Bye,
bearophile
Justin Whear:
--any compiler crash is a bug
regardless of whether the source is valid D code or not.
I suspect that in some cases those compiler crashes are a way for
the compiler to tell the programmer that the code was too much
hairy and too much hard to understand ;-)
Bye,
bearophile
Sometimes I have a function that needs an iterable:
void foo(Range)(Range data)
if (isForwardRange!Range is(Unqual!(ForeachType!Range) ==
int)) {}
So is it a good idea to add a isRangeOf template to Phobos?
void foo(Range)(Range data)
if (isRangeOf!(Range, int)) {}
Bye,
bearophile
).
I have opened an ER:
https://issues.dlang.org/show_bug.cgi?id=13682
Bye,
bearophile
Ali Çehreli:
Perhaps I am expecting too much from the current 'in' contract
design and implementation. ;)
The in contract is named pre-condition, or precondition.
Bye,
bearophile
the full information themselves (note: this
is how science works in laboratories).
Bye,
bearophile
.
It is memory safe.
Probably that's why there are two kind of casts in Haskell.
Bye,
bearophile
the faults
are more acceptable than the known alternatives.
I think the free mixing of signed and unsigned integral values is
not a good idea in D. I think that there are various ways to
refine immutable value range propagation.
Bye,
bearophile
Andrei Alexandrescu:
Is that a best-effort kind of approach? If so, that would be
pretty bad...
I don't exactly know how that Rust macro works, sorry, I am still
rather ignorant about Rust.
Bye,
bearophile
.
Is this possible and a good idea to do?
Bye,
bearophile
Ola Fosheim Grøstad:
Shouldn't sorted range maintain the invariant automatically in
order to remain typesafe?
Yes, of course.
Bye,
bearophile
401 - 500 of 10824 matches
Mail list logo