jicman:
This is line 7634:
const Size DEFAULT_SCALE = { 5, 13 };
What does the error say and how can I fix it? Thanks.
Can you show the (reduced) definition of Size and DEFAULT_SCALE?
Even better to show a minimized self-contained program that has
the problem.
Bye,
bearophile
Bienlein:
@nogc is meant mostly for stack-allocation.
Ah, I missed that. Thanks for telling me.
@nogc is also for allocation from the C heap, despite this is
less common :-)
Bye,
bearophile
ketmar:
there is currenly no way to specify attributes for such implicit
delegates.
It could be a nice language enhancement.
Bye,
bearophile
ketmar:
so it can be forgotten in Bugzilla. ;-)
And in ten, or one hundred or one thousand years the whole D
language will be forgotten. There are various levels of
remembering and forgetting. Putting bugs and ERs in databases is
a different kind of forgetting.
Bye,
bearophile
maik klein:
Are there any exercises/challenges for D?
Something like this?
http://www.haskell.org/haskellwiki/99_questions/1_to_10
This is an interesting question. There are many
exercises/challenges that can be done in D, but I don't know any
specific for D. As D challenge I suggest to
Ola Fosheim Grøstad:
Bearophile has created many such examples at Rosettacode.
I am updating and improving them, but I have created only a
percentage of them (60-70%? I don't know).
Bye,
bearophile
Aerolite:
I was surprised to learn yesterday that D does not actually
support Multiple-Dispatch, also known as Multimethods. Why is
this? Support for this feature is already present in Scala, C#
4.0, Groovy, Clojure, etc... Would it not make sense for D to
remain competitive in this regard?
I
nikki:
How would you write it?
I don't know how much idiomatic this is, but you can start
cleaning up the code:
- Renaming the function with something more clear;
- using a D enumeration for the various constants.
- I have used a . before the module-level variables to denote
better they
ketmar:
don't use '==' to check for nulls. the right way is:
if (foo is null) {}
if (bar !is null) {}
'==' transforms to opEquals call (see 'operator overloading')
and 'is' not.
I use is and !is for class references and == != for pointers.
But now I think you are right, and in D it's
Dicebot:
All I want is that whatever decision Walter makes to happen
sooner than in few years from now.
There are other pending patches, like the support for the nice
[$] syntax by Kenji.
I keep thinking there's gotta be a way to do this without
language changes. or I keep thinking there
Jacob Carlborg:
How about we undeprecate it instead. If I recall correctly then
DDMD depends on it.
I think the idea is to discourage their usage as much as possible
in user code, until (someday, perhaps) some memory area tracking
system is implemented.
Bye,
bearophile
Apparently there is evidence that unused variables in C-like
languages correlate with bugs:
https://kev.inburke.com/slides/errors/#error-correlations
One problem with ruling out some classes of unused variables
(like unused function arguments, unused private module-level
variables, unused
Brian Schott:
The unused variable and unused parameter checks have existed
since May. As far as I know it only gives false positives if
mixin statements are present.
Another interesting feature is similar to -Wsuggest-final-types
and -Wsuggest-final-methods. They give warnings when there is
Timon Gehr:
http://xkcd.com/552/
What better alternative do you suggest in practice? The only
better solution I remember that was used for a language design is
the : added to Python after some controlled experiments done on
users.
Relying on experimental correlations (if the analysis is
Ary Borenszweig:
What language is that?
I don't remember its name, of course.
I have just scanned the last few months of the LambdaTheUltimate
blog without success.
Bye,
bearophile
Suliman:
void main()
{
auto result = readconfig();
foreach (_; result)
{
// I want to iterate result that I got from structure.
}
}
auto readconfig()
{
struct ConfigStruct
{
string key1;
Suliman:
foreach (field; result.tupleof)
Why I should here specify type of iterable element, but not
first element that I use for iteration?
I mean:
foreach (_some_type_possible_enum_ field; result)
?
I don't understand your question. In my code I have not specified
types in the
Marc Schütz:
But it would need to halt the system of course, because
throwing a RangeError might not work in his minimalistic
environment.
Halting the system, or jumping to a error routine seems better
than running in undefined state.
Bye,
bearophile
Suliman:
bool[4] x = [1, 1, 0, 0];
BitArray ba = BitArray(x);
When I try to compile this I am getting error:
source\app.d(13): Error: cannot implicitly convert expression
(x) of type bool[4] to uint
What I am doing wrong?
It still lacks some features like a constructor that accepts a
Andrei:
http://tomerfiliba.com/blog/dlang/
struct PascalString {
Field!ubyte length;
Also see if UDAs plus compile-time introspection is helpful.
auto stream = cast(ubyte[])\x05hello.dup;
Perhaps this is enough, and avoids one allocation:
immutable stream =
Jacob Carlborg:
The simplified signatures would be show for the main
signatures, i.e. the ones with a light blue background, and the
full signatures would be added at the end of the documentation
for each symbol.
Another possible improvement is to add popups that show the
complete type
Ary Borenszweig:
Then here someone from the team says he can't say a way to
improve the performance by an order of magnitude:
https://www.mail-archive.com/rust-dev@mozilla.org/msg02856.html
(but I don't know how true is that)
Can't they remove some type inference from the language?
Type
nrgyzer:
Sure, I can also use nested functions, but in my opinion it
results in dirty and complex code. It's totally overkilled
compared to a simple if and goto-instruction.
Often nested functions are less complex, more clean and simpler
code compared to using gotos. I suggest to start
Vladimir Panteleev:
I agree, I am also surprised that 2.066 was released despite
the regressions.
There is an apparently endless stream of regressions, I have
found another today
(https://issues.dlang.org/show_bug.cgi?id=13321 ). I think D is
not yet at the stage of its development where
Ivan Kazmenko:
My contest program, now on GitHub:
https://github.com/GassaFM/alphabet-city/
dmd bug: wrong file and line for array bounds check
Did you report the bugs?
Bye,
bearophile
Jonathan M Davis:
The biggest reason is memory safety. With a GC, it's possible
to make compiler guarantees about memory safety, whereas with
manual memory management, it isn't.
Unless you have a very smart type system and you accept some
compromises (Rust also uses a reference counter some
Ary Borenszweig:
It's very smart, yes. But it takes half an hour to compile the
compiler itself.
I think this is mostly a back-end issue. How much time does it
take to compile ldc2? Can't they create a Rust with dmc back-end?
:o)
And you have to put all those unwrap and types everywhere,
ketmar:
other function declarations (methods, nested functions) accepts
'static', so why free functions shouldn't?
For various reasons, one of them is that accepting useless code
confuses newbies and doesn't allow them to build a correct model
of the D semantics in their head.
Bye,
H. S. Teoh:
Is there a bug filed for this?
Probably there is. But I stopped filing similar bugs because they
seem to have a very low priority.
Bye,
bearophile
nrgyzer:
import std.bigint;
void main(string[] args)
{
BigInt i = 12345;
if (args.length 1)
{
goto Exit;
}
i = BigInt(67890);
Exit:
return;
}
When I try to compile this sample application I'm getting the
It looks like a compiler bug
https://issues.dlang.org/show_bug.cgi?id=13321
Bye,
bearophile
Jacob Carlborg:
A pull request [1] by Rainer Schuetze which adds COFF support
for Win32 has recently been merged by Walter. It seems to be
enabled using the -m32mscoff flag.
I have just recompiled dmd, but I don't see that new compiler
switch (dmd 2.067).
I am compiling in a wrong way?
ketmar:
are you sure that you compiled dmd for 32-bit windows? other
versions seems to not have this flag.
Yes, I am using a 32 bit Windows.
Bye,
bearophile
ketmar:
are you sure that you have latest git then? yes, i know that
this is very silly question, but sometimes... ;-)
OK, -m32mscoff works (probably I was using a wrongly written
switch), but I don't see it listed among the other compiler
switches.
Bye,
bearophile
Andrei Alexandrescu:
schwartzSort comes to mind -- Andrei
forgot the smiley :o) -- Andrei
Yeah that's an infamous example. Standard libraries should avoid
too much hard to write identifiers.
Bye,
bearophile
Jonathan M Davis:
Well, it _does_ follow the language spec, so it's not broken in
that sense, but it's a broken design IMHO in that it causes
confusion and bugs, and it has resulted in complaints in the
past
and will continue to do so until it's changed. So, I do think
that it's true that
Nordlöw:
I'm missing an instantiator function for std.typecons:Nullable.
Is this is intentional? If not, is this
Nullable!T nullable(T)(T a)
{
return typeof(return)(a);
}
sufficient for our needs?
It could be sufficient, but note that in Phobos there are two
different versions of
Recently I've found two very small introductions to the Rust
language. Below I list some of the things I've found in them.
The first tutorial is:
http://matej-lach.me/rust-basics/
--
The Rust tuple syntax similar to Kenji's:
let (i, result) = (0i, 0i);
let (x, y, z) = (15i,
Jacob Carlborg:
It can be implemented as a library function.
It can't be implemented with a library function. You want to use
it in function signatures, foreach, and so on. We have discussed
this many times.
Bye,
bearophile
Kenji Hara:
I implemented partial type deduction in AA keys.
https://github.com/D-Programming-Language/dmd/pull/3615
For example:
auto[auto[$]] aa5 = [[1,2]:1, [3,4]:2];
static assert(is(typeof(aa5) == int[int[2]]));
int[int[][$]] aa15 = [[[1],[2]]:1, [[3],[4]]:2];
static
A proposal for a basic pattern matching in C# 6:
http://www.infoq.com/news/2014/08/Pattern-Matching
But it's still rather limited:
Under the current draft specification, there is no support for
range checks. This means you cannot write patterns such as “a is
Location( 0, 1 to 5, = 10)”. Nor
artemav:
struct node(T) {
T data;
node!T next;
};
Try:
struct node(T) {
T data;
node!T* next;
}
Bye,
bearophile
Meta:
Isn't that also the case for the auto*, const[], immutable[$],
etc. syntax? Conceptually it feels the same to me as Kenji's
enhancement; I don't know enough about the compiler to talk
about it technically.
One difference between Kenji's enhancement and the AA type
inference is that
Dicebot:
This is already possible with standard library but the fact
that declarations need to be separate makes people not happy.
The unpack() lacks most of the capabilities you expect and want
from tuples handling.
Bye,
bearophile
Andrei Alexandrescu:
Destroy https://issues.dlang.org/show_bug.cgi?id=13291?
I'd like a way to test nested functions:
void foo() {
int bar() { return 0; }
unittest {
assert(bar() == 1);
}
}
void main() {}
Bye,
bearophile
Sean Kelly:
This looks really nice. I'd love to use it for std.concurrency,
but I'm still trying to sort out a way for this to work.
Specifically, it would be nice if there were a way to know from
a tuple's TypeInfo if it matches a pattern.
Elsewhere I have suggested to add to D an optional
Idan Arye:
Nested functions are not really units - they are
implementation details.
It's not important how you call them. I'd still like some nice
way to test those details :-)
H. S. Teoh:
When should such unittests be run, and how should the following
code behave?
Is
TJB:
I am trying to find the max and min values in an associative
array. Say I have:
double[char] bids;
bid['A'] = 37.50;
bid['B'] = 38.11;
bid['C'] = 36.12;
How can I find the max and min values. I am thinking that I
need to use max and min functions from std.algorithm, but not
sure how
Théo Bueno:
Same issue here with dsfml-audio, this is really annoying :/
Have you filed the issue?
Bye,
bearophile
safety0ff:
Here's a candidate for
http://rosettacode.org/wiki/Extensible_prime_generator#D in
case it is preferred to the existing entry:
http://dpaste.dzfl.pl/43735da3f1d1
I was away. I have added your nice code with some small changes
as an alternative faster version. I think you have
Andrei Alexandrescu:
* The representation is built on Algebraic,
Good.
But here I'd like a little more readable type:
alias Payload = std.variant.VariantN!(16LU, typeof(null), bool,
double, string, Value[], Value[string]).VariantN;
Like:
alias Payload =
Daniel Murphy:
What do you think about
https://github.com/D-Programming-Language/dmd/pull/3799 ?
Basically, turn obviously invalid failing function calls into
compile-time errors. IMO this pushes in-contracts well out of
the useless area.
I like compile-time tests, you can see it from
Xinok:
I do wonder if we should generalize an interface for these
types of ranges.
First of all you need some use cases and usage examples.
Bye,
bearophile
Daniel Murphy:
This doesn't need a lot of text to explain either: when
possible, the compiler will check preconditions at compile time
What defines possible? A compiler switch that allows to define
the amount of compile time?
I feel like you're confusing this pull request with another
By the way, I will be absent for more than a week. My comments or
answers in bug reports and threads will have to wait.
Bye,
bearophile
Ali Çehreli:
Ali Çehreli's (first speaker) slides are at
http://acehreli.org/AliCehreli_assumptions.pdf
It's a nice slides pack. Now in Phobos there's also assumeUTF
(https://d.puremagic.com/issues/show_bug.cgi?id=10162 ).
See also:
https://issues.dlang.org/show_bug.cgi?id=9682
It
Andrei Alexandrescu:
I do agree tagged unions should be pushed into the language;
they'd help the GC.
A more general solution is to add a onGC() optional method that
gets called by the GC on collections, and tells it what's inside
the union.
Bye,
bearophile
John Colvin:
This is enough to convince me.
Please don't feed Walter.
Bye,
bearophile
Walter Bright:
I don't care if you make such remarks about me, but I do care
about the level of discourse in the forum sinking to such
levels. Please refrain from such.
Yes sorry, I have lost my temper when you have written Or
perhaps some people are just being argumentative. I can't really
H. S. Teoh:
IMO the correct solution is for the compiler to insert
preconditions at the calling site,
I have seen this suggestion tens of times, but nothing has
happened. (delegates make the management of contract blame more
compex).
Bye,
bearophile
Freddy:
uint[uint] test;
void main(){
test=[0:2 ,1:3 ,2:4];
writeln(test.map!(a=a-2));
}
If you need keys or values you have .keys .values, .byKey,
.byValue (the first two are eager). If you need both you are out
of luck, and if you want to write safe code it's better to
Ola Fosheim Grøstad:
Here is a set of examples of annotated programs that have been
formally proved correct for those interested:
http://toccata.lri.fr/gallery/why3.en.html
More comments:
---
A problem with code like this is that it's drowing in noise. The
Walter Bright:
I'd like to see what you are saying is different in a real
example.
(The problem is that your have defined your own idea, so what I
can show you will look meaningless or not comformant to your own
definition. So this discussion is going nowhere. And my original
topic drowns
In debug builds gets rewritten as:
int max(in int x, in int y) {
if (x = y)
throw new AssertError(...);
return x;
}
Sorry, I meant:
In debug builds gets rewritten as:
int max(in int x, in int y) {
if (x = y)
throw new AssertError(...);
return (x y) ? x : y;
Daniel Gibson:
asm { : : m
(*cast(typeof(password[0])[999]*)password.ptr); }
inline asm is not portable
See:
https://d.puremagic.com/issues/show_bug.cgi?id=10661
C11 defines a memset_s which is guaranteed not to be optimized
away..
that's 9 years after that bugreport and will
Justin Whear:
In addition to the suggestions of Algebraic or Variant
elsewhere in this
thread, it's trivial to implement your own concrete tagged
unions:
struct MyTaggedUnion
{
enum Type { Int, Float, String }
Type tag;
union {
int int_;
float float_;
string
Walter Bright:
That's the way assert in C/C++ conventionally worked. But this
is changing. Bearophile's reference made it clear that
Microsoft C++ 2013 has already changed,
I am against the idea of turning asserts into a dangerous
assert-assume hybrid. And you have ignored some answers by
Daniel Gibson:
so they can make sure to use assert() accordingly.
What's the correct way to use the assert-assume hybrid?
Bye,
bearophile
safety0ff:
I modified the Hamming numbers code in a personal exercise.
It now uses considerably less memory but is slower.
I've posted the code here in case it is of use:
http://dpaste.dzfl.pl/3990023e5577
For a single n, n = 350_000_000:
Alternative version 2: 13.4s and ~5480 MB of ram
My
Kozzi11:
Is possible to somehow split class declaration and definition.
I mean something like this:
class C
{
void hello(); // just prototype
}
class C
{
void hello()
{
//actual code
}
}
or something like this
void C.hello() {
//actual code
}
I think this is
Is it a good idea to add int/uint/long/ulong functions for the
left shift operation here?
https://github.com/D-Programming-Language/druntime/blob/master/src/core/checkedint.d
Bye,
bearophile
H. S. Teoh:
What would you check for? Shifting something that already has
its high bit set?
If you have a uint where the 3 most significant bits are 1, and
you shift it 3 bits on the left, you lose those three bits, you
have an overflow. The point of checkedint functions/intrinsics is
to
Eric:
Suppose I have some memory allocated on the heap, and I have
two pointers pointing to the beginning and end of a contiguous
segment
of that memory. Is there a way I can convert those two pointers
to an array slice without actually copying anything within the
segment?
Use something
Marc Schütz:
class buffer(T, size_t sz) {
auto arr = new T[sz];
This allocates an array with `sz` elements once _at compile
time_, places it somewhere into the executable, and uses its
address as the default initializer for the member `arr`.
Right. It's not a compiler bug. Dmd/ldc
H. S. Teoh:
OK, makes sense. But what about if only the most significant
bit is 1?
Wouldn't that also be an overflow? So you're essentially
checking if the
topmost n bits are zero, where n is the number of bits you wish
to shift by.
Of course.
https://issues.dlang.org/show_bug.cgi?id=13231
Eric:
Thanks. That really works. I timed doing
auto mySlice = ptr1[0 .. ptr2 - ptr1]; 1,000,000 times
versus
auto mySlice = ptr1[0 .. ptr2 - ptr1].dup; 1,000,000 times
and I am quite convinced the data is not being copied.
Take a look at the asm!
Bye,
bearophile
Walter Bright:
Data flow analysis can figure that example out.
Sorry, my mistake, what I am discussing about should not need
much flow analysis. Here x and y are immutable:
void main(in string[] args) {
import std.stdio, std.conv;
assert(args.length == 3);
immutable ubyte ux
a way for x and y (that are of the library-defined type SInt)
to keep the value range of an ubyte.
Such management of value ranges by library code could also allow
to modify the implementation of iota to compile this:
void main() {
import std.range, std.algorithm;
auto result =
After thinking a bit more about this topic I have opened an ER,
because I think this could statically catch some slice-related
bugs and allow some safe implicit casts:
https://issues.dlang.org/show_bug.cgi?id=13228
Just a curiosity of mine: Do you remember who originally proposed
to add the
Ola Fosheim Grøstad:
Here is a set of examples of annotated programs that have been
formally proved correct for those interested:
http://toccata.lri.fr/gallery/why3.en.html
I have started to read those pages, it looks interesting. From
one of the first links (Sudoku solver):
valid
Walter Bright:
void f(ubyte[] a) @safe { assert(a.length99); a[88] =
a[77]; }
The compiler will insert array bounds checking for you.
But if your assert is the same as an assume(), then the
optimizer should remove bounds checks (otherwise it's a lousy
implementation of assume()) and
So now you now have a safe function that is unsafe.
Even in debug builds.
Bye,
bearophile
Andrei Alexandrescu:
Far as I can understand yes, there is distinction between
assert and assume. I don't find it as material as it would
need to be to make assume a language feature.
I didn't ask for an assume() in this thread. I have
suggested/discussed/asked the inclusion in D of means
Walter Bright:
That's a good point. You could reasonably argue that such an
optimization should not happen.
I agree. Turning D assert() in a kind of a assert-assume hybrid
will be a mistake.
I think you are still missing the essential difference between
assume and assert.
How does
Walter Bright:
assert(x != NULL);
if(x != NULL) {
x-foo = 42;
// ...
}
...
Your code is doomed to having problems using assert this way.
That usage of assert is fine. D programs use it that way. (And
you are going to break lot of D code if you will change the
semantics of D
Walter Bright:
So we're back to assert and assume being the same thing. Ok.
They aren't, and they shouldn't be, regardless the number of
times you say they are.
Bye,
bearophile
Walter Bright:
No, it will break code that already is broken.
I have probably lost the grasp of this part of the discussion.
But I don't see what's broken in using assert to verify that a
pointer is not null. Do you think that pointer comes from
outside?
Bye,
bearophile
Walter Bright:
Show me a piece of code with different behavior. Start with the
array bounds thing.
People have already shown you code that behaves differently with
assert and assume. But you have redefined assert to mean a mix
of assume and assert. So before me answering you have to switch
Walter Bright:
I believe we are talking past each other with no understanding.
The roadmap for the next three versions of Scala. Despite Scala
is used much more than D, they are willing to break library code
(shuffle around collections, turn mutable ones into immutable
ones), and change
Walter Bright:
Here there are no new language features required. muls() being
an intrinsic means the compiler knows about it. The compiler
already does data flow analysis on constants, meaning it knows
that x is 100,
Another example program, hopefully more clear:
void main(in string[]
Walter:
Instead of adding more language features,
Perhaps you can't solve this problem in a sufficiently clean way
without adding language features (and a assume() is not the
solution, see below).
-
Ola Fosheim:
Conflating run time debug checks with programmer
Ola Fosheim Grøstad:
IMO muls should yield 2N bits of output for N bits input, then
the compiler should do strength reduction.
Adds should be done on N+1 bits types, using 33 bit output for
32 bits input, then strength reduce it to =32 bit output if
both operands are 31 bits or less?
I
Iain Buclaw:
Staging area for the new look is found here:
http://staging.dgnu.org
I suggest to reduce the section about bugs, to add links in the
text to the other D compilers (and especially to the main D
site), to explain the differences and advantages/disadvantages
between dmd and gdc,
Ola Fosheim Grøstad:
D promotes int to uint, right? Which is a bad idea. It should
promote to long, right?
The purpose of safe integral operations like muls() is to detect
overflow bugs at run-time. If they don't detect bugs, they are
not useful.
Bye,
bearophile
The purpose of safe integral operations like muls() is to
detect overflow bugs at run-time. If they don't detect bugs,
they are not useful.
I think it detects the overflow correctly even if you use the
(uint, int) argument pair, because the usual conversions are
used, and I think the mulu is
Daniel Murphy:
One murky area is that assert(0) is currently used to mean both
'unreachable' and 'unimplemented'. It's unclear what the
compiler is allowed to do with an assert(0) in release mode.
I'd still like to have a halt() in D, and have assert(0) with the
same semantics of the other
Daniel Murphy:
Sure, we could add a new construct (ie 'assume') to the
language, and use that to pass information. But are they
really different?
Conflating the two concepts with a single name is a mistake that
will cause troubles. Different features need different names or
different
Domingo Alvarez Duarte:
Based on a question about manually allocated structures with
payload I found that a solution proposed seems to work when
compiled with dmd but segfaults when compiled with gdc.
...
int size;
char[0] _b;
@property char[]
Iain Buclaw:
BigInt is certainly on the cards for making native 128-bit
support possible, but it still needs to be set apart from
global and function symbols. For that, it needs to finally be
given a mangled identifier.
Is a mangled identifier also useful for partially library defined
The core.checkedint module isn't meant to be used directly like
this, it has the bricks to build partially library-defined safe
integral types:
void main(in string[] args) {
import std.stdio, std.conv, core.checkedint;
assert(args.length == 3);
immutable xy = args[1 ..
701 - 800 of 1477 matches
Mail list logo