Xinok:
My concern is that SortedRange only accepts a range which is
random-access and limits its functionality to those primitives.
Concatenation is not required for random-access ranges, so
should we expect SortedRange to overload this operator?
I understand, that's why I am asking this
tcak:
Is there any VERY SPECIAL reason behind that limitation?
What advantages gives removing that limitation? Is the price in
increased complexity worth paying?
Bye,
bearophile
Third part of the A Programming Language for Games, by Jonathan
Blow:
https://www.youtube.com/watch?v=UTqZNujQOlA
Discussions:
http://www.reddit.com/r/programming/comments/2kxi89/jonathan_blow_a_programming_language_for_games/
His language seems to disallow comparisons of different types:
Now in Phobos there is std.concurrency.Generator. In Python they
added yield from for various reasons:
http://legacy.python.org/dev/peps/pep-0380/
One of the reasons is performance:
Using a specialised syntax opens up possibilities for
optimisation when there is a long chain of generators.
Walter Bright:
* for over an array in D:
foreach (it; results) ...
D is better here, because it doesn't introduce magically named
variables.
* D does the check function thing using compile time function
execution to check template arguments.
This is not nearly enough. I have
Walter Bright:
I know you've suggested extensive data flow analysis,
The static enum (and related ideas) I've suggested require no
flow analysis.
Compile time checking can only be done on compile time
arguments (obviously) and template functions can arbitrarily
check compile time
Paulo Pinto:
- arrays were bound checked (just use a compiler flags and
dataflow to remove them like any sane language)
D removes very little bound checks. No data flow is used for this.
- enums were strong typed
D enums are only half strongly typed.
- had namespaces or real modules
Walter Bright:
D has writefln which does not have printf's issues. There's no
reason to add a feature for printf.
The feature we are talking about is not just for D writeln, as
I've tried to explain several times.
And D writeln is not verified at compile-time, this is silly for
a language
Walter Bright:
Thank you for your answers.
D removes very little bound checks. No data flow is used for
this.
This is false.
Oh, good, what are the bound checks removed by the D front-end? I
remember only one case (and I wrote the enhancement request for
it). Recently I argued that we
Steven Schveighoffer:
long a = src.countUntil(start);
if (a 0)
return src; // null
a += start.length;
long b = src[a..$].countUntil(end);
I think there it's better to use auto instead of long.
Bye,
bearophile
Brad Anderson:
you rarely want
to iterate through an associative array without having both the
key and the value on hand.
This is very false. I have tons of cases where you only iterate
on values or keys. On the other hand I have suggested several
times that I'd like a byPairs (that yields
Andrei Alexandrescu:
Looks like the one I saw years ago: a proof that you don't want
that kind of stuff :o). -- Andrei
Silly Andrei :-)
Bye,
bearophile
H. S. Teoh:
And how would it be implemented in a way that is stable across
AA implementations?
Adding tuples as first-class entities in the language, and
deprecating std.typecons.Tuple :-)
Bye,
bearophile
advibm:
I would like to have something like that:
char[] buf; // already filled array
char[] partOfBuf = betweenTwoStrings(buf, START, END);
partOfBuf[0] = 'a'; // THIS should also change the 'buf'
variable
assert(buf[0] == 'a');
Thanks for your help
To do this you don't need to return a
Brian Schott:
https://github.com/Hackerpilot/dfix
Sounds like a very good start :-)
Bye,
bearophile
Andrei Alexandrescu:
I recall there was an earlier implementation of a
statically-checked sort, maybe in Agda? It wouldn't typecheck
if the output array weren't sorted.
Yes, there is a similar code even in ATS language (that is much
simpler than Agda, you can't verify a generic proof as in
http://dpaste.dzfl.pl/e60eeb30e3b6
That code is in ATS1. Now there is ATS2 that has a better syntax,
and is a bit more powerful (and can compile even to JavaScript).
On the ATS site all the ATS1 examples apparently have being
removed.
Bye,
bearophile
Ola Fosheim Grøstad:
X.action(Y) will in most OO languages mean do action to
object X, but parent.send(results) means the opposite?!
Why the opposite?
Bye,
bearophile
Walter Bright:
http://www.quora.com/What-are-the-algorithms-required-to-solve-all-problems-using-C++-in-any-competitive-coding-contest
Anyone want to review these and see what we should add to
Phobos?
It's a good idea to help people that want to use D for contests,
because contests require
In the latest version of the Idris language there are some
interesting improvements, in particular the static arguments,
using a [static] annotation on one or more arguments of a
function (works with functions as arguments too):
Shriramana Sharma:
int i ;
ref ir = i ;
// Error: variable ref_type.main.ir only parameters or foreach
declarations can be ref
// Comment: add , return values after parameters
}
I like this.
Bye,
bearophile
deadalnix:
There are possibilities to do more, but compatibility require
that we put the line somewhere.
The line is still moving forward.
The current line seems to be to do VRP on expression and compile
time know values. Is that right ?
No, it's not right. VRP was recently improved to
Stefan Koch:
The problem with vrp for non-static immutable values is, that
vrp becomes a runtime-thing and I would like to avoid that!
Tracking the range of a Variable at runtime could cause
significant overhead!
Nope, the value range tracking is purely compile-time.
2. implementation is
Etienne Cimon:
So what's the point of making a class or methods final?
It forbids subclassing. And final methods are not virtual, so
they can be inlined.
Bye,
bearophile
Shammah Chancellor:
Several of us working on it were a little surprised that DMD
does not compile this:
void main() {
long l = 42;
int i = l;
}
Is this expected to compile? Planned?
Currently this doesn't compile, and it's expected to not compile.
Currently VRP works only
Walter Bright:
To do it reliably would require dataflow analysis.
There are still several useful cases where dataflow analysis is
not needed (like for immutable values) that are still missing.
They could be added.
Bye,
bearophile
Jonathan M Davis:
Questions like this have come up and been discussed before, but
using the same parameter names as member variable names for
constructors is such a common practice that there would be
quite a bit of screaming if we didn't allow it.
I'm willing to hear them scream. D should
Etienne Cimon:
I'm not sure, why does a final class carry a vtable pointer?
In D all class instances contain a pointer to the class and a
monitor pointer. The table is used for run-time reflection, and
for standard virtual methods like toString, etc.
Bye,
bearophile
Ola Fosheim Grøstad:
I think the overrated C++ standard library has influenced
phobos too much.
I agree.
I also want to see string mixins removed from phobos. It is a
very ugly feature.
What are your problems with those strings?
Bye,
bearophile
Ola Fosheim Grøstad:
2. Easy to write ugly code: It suffers from the same issues as
macros.
Do you mean C macros? I think this is not true.
3. Language integration: It is desirable to have an application
level language that can integrate well with a low level
language when calling out to
neal:
data.sort!q{ to!int(a[4]) to!int(b[4]) };
This code fixes my problem! Thanks for the quick responses
guys. you rock!
That converts string-int many more than once for each string. So
if memory is not a problem, consider using a
decorate-sort-undecorate pattern:
Neal:
Interesting! Thank you. Memory isn't a problem
Unfortunately currently the sort-decorate-undercorate in Phobos
is not very fast.
but I would still
like to learn how to write more efficient programs. If i posted
my code would you be able to give me some advice?
There is far more
Ali Çehreli:
- References to any local data because 'ref' is only for
parameters and return types.
int a;
int b;
int* r = (condition ? a : b);// r must be a pointer
*r = 42;
Regarding this example, this works:
void main() {
int a, b;
bool condition;
Nordlöw:
It would be nice to have a lambda-variant of std.string.tr to
call like
x.tr!isWhite(['_'])
If your text is ASCII, then there is std.ascii.whitespace that
can be given as argument to std.string.tr.
Bye,
bearophile
Currently this code gets rejected:
const int[] a = [1];
void main() pure {
auto y = a[0];
}
test2.d(3,14): Error: pure function 'D main' cannot access
mutable static data 'a'
test2.d(3,14): Error: pure function 'D main' cannot access
mutable static data 'a'
But is this a good idea?
Minas Mina:
Aren't pure functions supposed to return the same result every
time? If yes, it is correct to not accept it.
But how can main() not be pure? Or, how can't the 'a' array be
immutable?
Bye,
bearophile
Szymon Gatner:
const int[] a;
int[] b;
static this()
{
b = [1];
a = b;
}
Ant this code works? What is the point of const then if you can
assign it to mutable slice?
It works, and I think it should work. Inside the (module)
constructor the const state is handled differently.
Thank
neal:
Anybody have any suggestions?
Something like this, perhaps?
data.sort!q{ a[4] b[4] };
Bye,
bearophile
John Carter:
Your paste has expired / no longer there but the subject
has come up again...
...
Do you still have your implementation hanging around?
I think it was this. *Untested*:
void main(string[] args) {
import core.stdc.stdio, std.bigint, core.stdc.stdlib;
immutable n =
Nordlöw:
How can I extend
string line = carwash;
line.strip.splitter!isWhite.joiner(_).to!string
so that
car wash
becomes
car_wash
and not
car___wash
?
Use std.string.tr.
Bye,
bearophile
Justin Whear:
std.string.squeeze might be more appropriate.
But with tr you can also replace the spaces with the underscore.
Bye,
bearophile
They are discussing about named arguments for C++:
http://www.reddit.com/r/cpp/comments/2jiai2/n4172_named_arguments/
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4172.htm
Bye,
bearophile
Ola Fosheim Grøstad:
The IDE support is probably a bit better with Java/C#
The importance of the IDE for the first language is
controversial. I think it's not so important.
and using a statically typed language as your first language
has advantages,
While no one has determined
Just found with Reddit. C seems one step ahead of D with this:
http://developerblog.redhat.com/2014/10/16/gcc-undefined-behavior-sanitizer-ubsan/
Bye,
bearophile
RBfromME:
I'm a newbie to programming and have been looking into the D
lang as a general purposing language to learn, yet the D
overview indicates that java would be a better language to
learn for your first programming language. Why? Looks like D
is easier than Java...
Python is probably
ketmar:
besides, nested foreach with '_' is not working. but __
can generate unique temporary variable each time.
The point is to introduce a little breaking change in D and use
_ as don't care, so you can reuse it for nested scoped and
for tuple unpacking, and for other similar future
Domingo:
Ideally I want to use something like this:
-
import std.stdio;
import std.string;
import std.algorithm;
import std.conv;
void main()
{
string[] ar = [ dad , blue ];
writeln(typeid(ar));
//ar.each(writeln);
//ar.map!writeln;
eles:
Just a bunch of links:
http://www.horstpeterhermann.de/ada_related/gems.html
This one reminded me D, with some hints about what could still
be offered:
http://www.adacore.com/adaanswers/gems/ada-gem-7/
Two nice ones:
http://www.adacore.com/adaanswers/gems/ada-gem-24/
bachmeier:
def foo(x: int = 1000, y: double = 0.0): double {}
If you later change the names to something more informative
def foo(reps: int = 1000, variance: double = 0.0): double {}
You can use:
double foo(int deprecated(x) reps=100, deprecated(y)
variance=0.0) {...}
Bye,
bearophile
Ali Çehreli:
foreach (i, element; MyRange(42).enumerate) {
// ...
}
versus sequence!n and zip:
foreach (i, element; zip(sequence!n, MyRange(42))) {
// ...
}
But it's better to not use automatic unpacking of tuples. See
issues 7361 and especially 9817.
Bye,
ketmar:
is there any hack/trick to determine if variable is __gshared?
or if it is a thread-local, for that matter?
There is the -vtls compiler switch.
Bye,
bearophile
A series of small OCaML projects that implement bare-bones type
systems. This implements a basic Refined Typing and explains the
nice ideas:
https://github.com/tomprimozic/type-systems/tree/master/refined_types
This is one example (the unrefined underlying types are managed
with a standard
Meta:
On Sunday, 12 October 2014 at 16:21:50 UTC, bearophile wrote:
What happens if one of these conditions fails? Is an exception
thrown?
If you are using refined types, and D is somewhat assuming they
are refinements of those types, and one of those condition fails,
then you surely have
yawniek:
i found two snippets from the functional docs that do not work
(anymore?)
http://dlang.org/phobos/std_functional.html
assert(compose!(map!(to!(int)), split)(1 2 3) == [1, 2, 3]);
and
int[] a = pipe!(readText, split, map!(to!(int)))(file.txt);
throwing a std.array.array into the mix
Jonathan M Davis:
and it's primarily been Walter who hasn't wanted it on the
grounds that it's more consistent as it is
Consistency is a good thing to have, but if adhering to it causes
bugs and troubles, and if the symmetry breakage causes readable
compile-time errors, then it's often a
Walter Bright:
If we're going to break things, it needs to be for something
that matters. This doesn't make the cut.
I think you are wrong. This seems a worthy little breaking change.
Bye,
bearophile
Walter Bright:
https://www.reddit.com/r/programming/comments/2ilsij/function_purity_and_immutable_data_structure/
A problem is caused by with(){} that creates a scope. If I want
to write the literal of an immutable array of many enumerations I
have to repeat the enum name many times, this is
I have had few bugs caused by byLine not copying the line on
default. Now we have byLineCopy, but sometimes I forget to use
it. In D I prefer unsafe functions to be on request, and safe
ones by default.
Originally I suggested to give to byLine a boolean template
argument named doCopy that is
Tofu Ninja:
What do you think are the worst parts of D?
There are several problems in D/Phobos, but I think the biggest
one is the development process, that is currently toxic:
http://forum.dlang.org/thread/54374de0.6040...@digitalmars.com
In my opinion an Open Source language with such
Martin Nowak:
Kenji just proposed a slightly controversial pull request so I
want to reach out for more people to discuss it's tradeoffs.
It's about deprecating function qualifiers on the left hand
side of a function.
So instead of
const int foo();
you'd should write
int foo() const;
Observe:
void main() {
int[3] a1 = [1, 3, 6];
int[] a2 = a1[] * 3; // line 3, Error
int[] a3 = a1.dup[] *= 3; // line 4, OK?
int[] a4 = (a1[] * 3).dup; // line 5, Error
}
Currently the operation in line 4 is accepted:
test.d(3,17): Error: array operation a1[] * 3
Anibal:
byte[] arr = [ 0x00, 0xA4, 0x04];
This throws a int[] to byte[] cast error
You want ubytes (unsigned bytes) because 0x04 is 164 that is
bigger than byte.max.
So use:
ubyte[] arr = [ 0x00, 0xA4, 0x04];
I also tried
byte[] arr = [cast(byte) 0x00, cast(byte)0xA4, cast(byte)
You want ubytes (unsigned bytes) because 0x04 is 164 that is
bigger than byte.max.
I'd like bytes to be named sbyte and ubyte in D, but Walter has
refused this.
Bye,
bearophile
Marc Schütz:
It's equivalent to:
int[] tmp = a1[] * 3;
int[] a4 = tmp.dup;
The first part is of course identical to line 3, so this should
be an error, too. Normal rules for evaluation order require
`a1[] * 3` to be evaluated before `(...).dup`, so where is it
supposed to store the
ketmar:
additionally to all bearophile said, there is another
interesting thing in D: special string literals for hex data.
immutable ubyte[] n = cast(typeof(n))xdeadf00d;
or even:
immutable ubyte[] n = cast(typeof(n))xde ad f 0 0 d;
spaces doesn't matter, only digits do.
The problem
deadalnix:
There is something that is badly needed in std.butmanip : a way
to create tagged pointers. It is doable safely by checking
pointer alignment and allowing for n bits to be taken for
various things.
It can't be used for GC-managed pointers. A possible usage syntax:
enum Tag1 { A,
This is the first part of a function to convert to base 58 (some
letters are missing, like the upper case I) used in the Bitcoin
protocol:
alias Address = ubyte[1 + 4 + RIPEMD160_digest_len];
char[] toBase58(ref Address a) pure nothrow @safe {
static immutable symbols = 123456789 ~
Andrei Alexandrescu:
Or would static if (__ctfe) work? -- Andrei
Currently it doesn't work, because __ctfe is a run-time variable.
Walter originally tried and failed to make it a compile-time
variable.
Bye,
bearophile
antropod:
Looks fairly straightforward. But, the second function causes
compilation error:
std.format.FormatException@C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(2
585): Expected '%s' format specifier for type 'Tuple!(uint,
uint)'
Can you help me with that?
Currently the %(%s%)
anonymous:
You can turn the tuples into ranges with `only`:
writef(%(%(%s %)\n%), zip(indexes, source).map!(t =
only(t.expand)));
This is a nice idea. Expand can probably be replaced by a []. I
presume this works only if the types inside the tuple are the
same.
Bye,
bearophile
AsmMan:
import myModule : func, func2;
I use this in D to know what I have imported and where is was
imported from.
Bye,
bearophile
Sean Kelly:
Another issue is what the error tells us about the locality of
the failure. A precondition indicates that the failure simply
occurred sometime before the precondition was called, while a
postcondition indicates that the failure occurred within the
processing of the function.
H. S. Teoh:
So this new syntax can be implemented alongside the existing
syntax and people can gradually migrate over from
purely-runtime format strings to compile-time,
statically-checked format strings.
Very good.
D has a static type system, unlike Python/Ruby/etc but D printing
Max Klyga:
https://www.youtube.com/watch?v=TH9VCN6UkyQ
A third talk (from another person) about related matters:
https://www.youtube.com/watch?v=rX0ItVEVjHc
He doesn't use RTTI, exceptions, multiple inheritance, STL,
templates, and lot of other C++ stuff. On the other hand he
writes
Bruno Medeiros:
But if Walter is fixated on thinking that all the practical
uses of D will be critical systems, or simple (ie, single-use,
non-interactive) command-line applications,
There's still some of way to go for D design to make it well fit
for high integrity systems (some people
currysoup:
At what point does he say it's difficult to code in a SoA style
in C++?
Perhaps a (part of) language more fit/helpful/nice for that
purpose/use can be invented.
Bye,
bearophile
Oren Tirosh:
Bingo. Have some way to mark the function return type as a
unique pointer. This does not imply full-fledged unique pointer
type support in the language
Let's have full-fledged memory zones tracking in the D type
system :-)
Bye,
bearophile
Ali Çehreli:
Found on Reddit:
Where's the Reddit thread?
Are you motivated enough to compare D's associative arrays with
those results? :)
D associative arrays are often even slower than CPython ones, so
I don't expect D to shine in this comparison.
This is a D port of the Java code,
Ali Çehreli:
Never mind then.
Well, now the D code is present, so why don't you benchmark it
(but I don't know how much correct it is)? :-)
Bye,
bearophile
ixid:
It might be an effective argument to give bearophile some of
the problematic code and see what his idiomatic D version looks
like and if what you're after is elegantly achievable.
Manu is quite more expert than me in the kind of code he writes.
So what you propose is just going to
SomeDude:
The problem is, the C++ community is unwilling to collaborate
with anyone else and this attitude is encouraged by Stroustrup.
The C++ language has plenty of warts and unnecessary
complexities, but to me the C++ community seems normal, like
other languages communities. Usually such
Manu:
Trouble for me is, I've invested so much time now.
If your think your choice was the wrong one, don't invest even
more in something you think is wasted effort. Otherwise if you
like D, then try to improve it from the inside, writing
dmd/Phobos/druntime pull requests, instead of doing
Manu:
In the case of ref, I can't think of any programmers that I've
introduced to D that haven't complained about ref within their
first
hour or 2 of interaction.
Most of the times I have no problems with D ref. Perhaps you are
trying to use D too much like you use C++.
I'd never have
deadalnix:
the function could be returned and used elsewhere, where these
attribute aren't necessary.
Filed:
https://issues.dlang.org/show_bug.cgi?id=13550
Bye,
bearophile
Walter Bright:
A feature without a solid rationale is no good in spite of how
many votes it has.
I agree that the number of votes alone means very little. But
perhaps those persons have reasons.
(If votes from people are not important, then better to remove
this feature from Bugzilla.)
D
luka8088:
All library code is marked appropriately so when stack is
outputted it is shadows out (with gray color) all the lines in
library code and point out first non-library line from the top
of the stack. In 95% of the time it is the line that the
programmer should look into. Other 5% is
H. S. Teoh:
There will be a proper migration path and deprecation cycle.
I get refusals if I propose tiny breaking changes that require
changes in a small amount of user code. In comparison the user
code changes you are suggesting are very large.
Bye,
bearophile
Marco Leise:
The extent of what borrowing solves is really yaw dropping
when you read the list of use cases and I will surely add
scope to every function argument that it applies to (and
already do that), because it makes it verifiable safe to call
with any pointer type, be it ARC, GC or stack.
Walter Bright:
Inlining is not a random thing. If there's a case that doesn't
inline, ask about it.
Even when you use annotations like forced_inline and the like
you can't be certain the compiler is doing what you ask for. I
have seen several critical template functions not inlined even by
Walter Bright:
I suggest removal of stack trace for exceptions, but leaving
them in for asserts.
I suggest to keep stack trace for both cases, and improve it with
colors :-) Another possibility is to keep the stack trace for
exceptions in nonrelease mode only.
Asserts are a deliberately
Walter Bright:
I'm painfully aware of what a large change removing
autodecoding is. That means it'll take a long time to do it. In
the meantime, we can stop adding new code to Phobos that does
autodecoding. We have taken the first step by adding the
.byDchar and .byCodeUnit adapters.
We
Walter Bright:
but do want to stop adding more autodecoding functions like the
proposed std.path.withExtension().
I am not sure that can work. Perhaps you need to create a range2
and algorithm2 modules, and keep adding some autodecoding
functions to the old modules.
Bye,
bearophile
Walter Bright:
It can work just fine, and I wrote it. The problem is
convincing someone to pull it :-( as the PR was closed and
reopened with autodecoding put back in.
Perhaps you need a range2 and algorithm2 modules. Introducing
your changes in a sneaky way may not produce well working and
--
And I'd like map/filter to accept arrays and associative
arrays, and not just functions:
void main() {
import std.algorithm: map;
auto keys = [1, 2, 1, 1, 1];
auto a = [0, 10, 20];
auto r1 = map!(k = a[k])(keys); // OK
auto r2 = map!a(keys); // Error
Walter Bright:
* local functions with the same syntax as global functions
* safety which defaults to off
All of which D does right now.
It could be nice to have a syntax like lambdas for small
struct/class methods:
https://issues.dlang.org/show_bug.cgi?id=7176
struct Foo {
int
Walter Bright:
import std.algorithm, std.stdio;
int main(string[] args) {
return cast(int)args.map!(a.length).reduce!a+b();
}
Here's what LDC produces (with -O -inline -release
-noboundscheck)
Part of this particular case problem is not a compiler
optimizer weakness, but that autodecode
H. S. Teoh:
If we can get Andrei on board, I'm all for killing off
autodecoding.
Killing auto-decoding for std.algorithm functions will break most
of my D2 code... perhaps we can do that in a D3 language.
Bye,
bearophile
Walter Bright:
It could be nice to have a syntax like lambdas for small
struct/class methods:
https://issues.dlang.org/show_bug.cgi?id=7176
struct Foo {
int bar(int x) pure { return x * x; }
}
Becomes something like::
struct Foo {
int bar = (int x) pure = x * x;
}
I see no gain
Walter Bright:
As for the programmer wanting to know where the message
missing } came from,
grep -r dmd/src/*.c missing }
works nicely. I do that sort of thing all the time. It really
isn't a problem.
grep is not useful for the purposes explained in issue 13543
because the file name
Walter Bright:
Even if that is what you wanted, you won't get that from
FileException, as it will only show file/lines emanating from
calls inside std.file, not from higher level callers.
Can't we use the template arguments like __LINE__ to offer the
line of code in the IO function in user
501 - 600 of 1477 matches
Mail list logo