FreeSlave:
On Thursday, 28 January 2016 at 08:15:38 UTC, FreeSlave wrote:
Not directly. You can declare cdecl function on Free Pascal
side and call it as extern(C).
What about extern(Pascal)?
https://dlang.org/spec/attribute.html#linkage
Bye,
bearophile
ki/Sokoban#Faster_Version
You can also add a constructor to such struct, for safety and
disallow default construction.
Bye,
bearophile
Yazan D:
On Saturday, 16 January 2016 at 14:42:27 UTC, Yazan D wrote:
ubyte[] b = (cast(ubyte*) &a)[0 .. int.sizeof];
Better to use the actual size:
ubyte[] b = (cast(ubyte*) &a)[0 .. a.sizeof];
Bye,
bearophile
void main() {
import std.stdio, std.algorithm, std.conv, std.bigint,
std.string;
auto n = 17.BigInt ^^ 179;
n.text.dup.representation.sort().release.assumeUTF.writeln;
}
Better:
n.to!(char[]).representation.sort().release.assumeUTF.writeln;
Bye,
bearophile
Namal:
Hello I am trying to convert BigInt to string like that while
trying to sort it:
void main() {
import std.stdio, std.algorithm, std.conv, std.bigint,
std.string;
auto n = 17.BigInt ^^ 179;
n.text.dup.representation.sort().release.assumeUTF.writeln;
}
Bye,
bearophile
Namal:
std::vector foo(int N){
std::vector V(N);
int some_array[N];
VLAs are not present in D.
Bye,
bearophile
of_powers_conjecture#Third_version
Bye,
bearophile
without SIMD,
perhaps about as nice as the Ada ones (D sometimes offers good
enough tools to build what you need).
Posible use:
PackedDynamicArray!6 pa; // On heap.
PackedFixedArray!(6, 300) pfa; // On stack.
Bye,
bearophile
uot; is
always a 32 bit signed integer. D allows implicit assignment of a
32 bit size_t to int but not a 64 bit size_t to an int. I agree
that it's a bit of a mess.
Bye,
bearophile
Dennis Ritchie:
There is an array of values to store each of which sufficiently
6 bits.
As it is written down on the D?
You can't do it directly in D. Someone has to write a packed
array data structure to do it.
Bye,
bearophile
edSwitch(
0, "FizzBuzz",
3, "Fizz",
5, "Buzz",
6, "Fizz",
9, "Fizz",
10, "Buzz",
12, "Fizz",
/*else*/ i.text))
.reverseArgs!writefln("%-(%s\n%)");
}
Bye,
bearophile
Steven Schveighoffer:
These are the same, __gshared overrides static.
Isn't forbidding "__gshared static" a good idea then, to avoid
user confusion?
Bye,
bearophile
too. But this idea was refused for D
(also because it goes against UFCS chains).
Bye,
bearophile
need the "&" when you call the function.
Bye,
bearophile
uot;. Or you can use Algebraic from Phobos. Sometimes
you can use another Phobos function that simulates an improved
switch. Or often you can just give up at using ADTs in D and use
what other solutions D offers you (like OOP).
Bye,
bearophile
pairs.multiSort!(q{a.value > b.value}, q{a.key < b.key});
assert(pairs[2].key == "beer");
foreach (const ref it; pairs)
writeln(it.key, ": ", it.value);
}
Bye,
bearophile
tring label)
{
this.label = label;
}
}
The constructor doesn't look very useful.
Perhaps a named enum is safer.
Bye,
bearophile
Paul D Anderson:
Is there a way to return the name of a function (a string) from
a pointer to that function?
Perhaps creating a string[void*] AA and initializing with all the
function pointers you care about.
Bye,
bearophile
Jack Applegame:
writeln(a.find(4).empty ? "No" : "Yes");
canFind?
Bye,
bearophile
wobbles:
Have just tested, it is!
But with the current D front-end it's not a good idea to generate
too many combinations at compile-time. Efficient code doesn't
save you from bad usages.
Bye,
bearophile
ddos:
same behavior when overriding methods of base classes
This is by design.
Bye,
bearophile
look at the versions here, the usable one is the third:
http://rosettacode.org/wiki/Combinations#D
Bye,
bearophile
tcak:
I am planning to implement "Iterator" class. But looking at
"foreach" statement, it takes a range only.
Unless you are just experimenting, it's better to not go against
a language and its std lib.
Bye,
bearophile
ave a good reason to do
it, and you know what you are doing (and most times you don't
know it).
More generally, minimize the number of cast() in your D programs.
You can use a search to count how many "cast(" there are in your
whole D codebase, and you can try to reduce that number.
Bye,
bearophile
code. Here is mine:
https://github.com/Dgame/m3/blob/master/source/m3/List.d
In 99%+ of cases it's a bad idea to use a linked list.
Bye,
bearophile
necks.
You can even replace the *w multiplications with an increment of
an index each loop, but this time saving is dwarfed by the
reverse().
Bye,
bearophile
Brian Schott:
Do this instead:
ulong u = 1L << 63;
I suggest a more explicit:
ulong u = 1UL << 63;
Alternative:
ulong u = 2UL ^^ 63;
Bye,
bearophile
bitwise:
I'm a little confused at this point why this doesn't work
either:
const and immutable are rather different between C++ and D, I
suggest you to take a look at the documentation:
http://dlang.org/const-faq.html
Bye,
bearophile
an associative array of const
objects?
You meant to say "associative array with const objects as
values". I think the short answer is that you can't. This is a
breaking change, I think, it broke some of my code too. But
perhaps something like Rebindable could be used.
Bye,
bearophile
se the range formatting of writefln,
avoiding the "map", "to", and "join", something like:
writefln("%(%d %)", arr);
Bye,
bearophile
Nordlöw:
Ahh, a Binary Heap perfectly matches my needs.
https://en.wikipedia.org/wiki/Binary_heap
http://dlang.org/phobos/std_container_binaryheap.html
But isn't topNCopy using a heap?
Bye,
bearophile
ike we are doing in this thread.
Bye,
bearophile
[7, 5, 7, 3, 3, 5, 3, 3, 0, 3, 1, 1, 5, 1, 1, 1, 2, 2, 8, 5,
8, 8]
.sort()
.groupBy!((a, b) => a == b)
.map!array
.array
.sort!q{a.length > b.length}
.joiner
.writeln;
}
Bye,
bearophile
Ali Çehreli:
Do you know the story about groupBy?
It's a long messy story. Look for it with another name, like
chunkBy or something like that.
Bye,
bearophile
.schwartzSort!(x => tuple(-arr.count!(y => y == x), x))
But calling "count" for each item is not efficient (in both C#
and D). If your array is largish, then you need a more efficient
solution.
Bye,
bearophile
8 8 2 2 7 7 0
One solution:
void main() {
import std.stdio, std.algorithm, std.typecons;
auto arr = [7, 5, 7, 3, 3, 5, 3, 3, 0, 3, 1, 1, 5, 1, 1, 1,
2, 2, 8, 5, 8, 8];
arr
.schwartzSort!(x => tuple(-arr.count!(y => y == x), x))
.writeln;
}
Bye,
bearophile
Nordlöw:
I have graph traversal algorithm that needs to keep track of
the N "best" node visit.
std.algorithm.topNCopy?
Bye,
bearophile
s and learn. They are sometimes tricky
to get right, but it's not a problem of ugly syntax.
I wondered if you could check statically that the type could
implement an interface *if it wanted to* that is, without
inheriting it...
Template constraints don't require inheritance.
Bye,
bearophile
thing that allocates inside that function.
Bye,
bearophile
Robert burner Schadek:
... from all Unicode characters in an idiomatic D way?
Perhaps by rejection? I mean, generating a uint, test if it's a
character and repeat until the result is true.
Bye,
bearophile
u are experiencing those problems it's probably the way
D/Phobos to tell you to not use basic tuples for your purpose.
Use tuples with named fields (or even structs).
Take also a look at Algebraic in std.variant.
Bye,
bearophile
Charles Cooper:
Is there a better way to do this?
Can you show some use cases for this, and isn't "foo[1]" better?
Bye,
bearophile
dnewer:
but,C# cant compiled to native code.
Soon you will be able to compile C# natively.
Bye,
bearophile
ot;
"Proposal : aggregated dlang git repository"
"dmd 2.066.1 cannot build phobos 2.066.1"
I will try to get something out of those threads, thank you :-)
Bye,
bearophile
="" "OPT=-o"
"DEBUG=" "LFLAGS=-L/delexe/la" dmd.exe
run idgen
Error: 'run' not found
--- errorlevel 1
--- errorlevel 1
So is Dmitry (or someone else) willing and able to tell me how to
fix my compilation script and what to do?
Thank you,
bye,
bearophile
Ola Fosheim Grøstad:
D claims to follow C, so using unions for type punning is
ultimately implementation defined.
I am not sure if D is the same as C regarding this.
Bye,
bearophile
lst.strandSort)
write(e, " ");
}
Now it gives a runtime error like
"phobos\std\container\dlist.d(329): DList.front: List is empty".
I think the cause is that "list = leftover;" has a different
semantics. Is this a regression fit for Bugzilla?
Bye,
bearophile
Jack Applegame:
On Tuesday, 3 March 2015 at 17:49:24 UTC, bearophile wrote:
That's 1 + n-1 :-)
Could you please explain what does '1 + n-1' mean?
This is your code:
template Is(ARGS...) if(ARGS.length % 2 == 0) {
enum N = ARGS.length/2;
static if(N == 1) enum Is = is
Jack Applegame:
or use recursion (with splitting in two, and not 1 + n-1).
Bye,
bearophile
I already have one:
template Is(ARGS...) if(ARGS.length % 2 == 0) {
enum N = ARGS.length/2;
static if(N == 1) enum Is = is(ARGS[0] : ARGS[1]);
else enum Is = is(ARGS[0] : ARGS[N]) &
, and not 1 + n-1).
Bye,
bearophile
to be an error, but in D we introduce
errors slowly.
Bye,
bearophile
Baz:
Is this a normal behaviour ?
Try to move the definition of "poly" to module-level scope.
This is a design decision to avoid other troubles.
Bye,
bearophile
Mayuresh Kathe:
Should I choose DMD or go with GDC?
It's a good idea to use all available compilers. LDC and DMD are
both useful. Every one of them has advantages and disadvantages.
Bye,
bearophile
Rikki Cattermole:
Foo*[string] bar;
Foo v = *bar.grab("mykey");
Is this the setdefault of Python dicts? If this need is strong a
new function could be added to Phobos (or even druntime if you
want to reduce the number of hash computations).
Bye,
bearophile
gt; "eat " ~ a)(a)`
)([fruits, vegies]);
Better to use another lambda inside, instead of that string.
Bye,
bearophile
void main() {
foo([1,2,3,4,5,6,7,8], [0.1,0.2], [10,20,30,40]);
}
What a fun program :-)
Bye,
bearophile
. In future this kind of bugs will be hopefully
avoided by a better tracking of the memory.
I am not sure if http://wiki.dlang.org/DIP69 is able to avoid
this bug, if it can't, then DIP69 needs to be improved.
Bye,
bearophile
hrow away
your work just for a comment... be tolerant and be good.
Bye,
bearophile
H. S. Teoh:
So it could be called ilog2?
Perhaps floorIlog2? Isn't ilog2 a different function?
Bye,
bearophile
H. S. Teoh:
Maybe that could be the basis of a better name?
Right.
Bye,
bearophile
I suggest you to read how a mark&sweep GC works, or better to
implement a bare-bones mark&sweep GC in C language yourself for
Lisp-like cons cells, you only need 100 lines of code or so to do
it.
Bye,
bearophile
Tobias Pankrath:
Why should splitter.front allocate?
I think that front was able to throw Unicode exceptions, that
require the GC. But I think later they have become asserts, that
don't require the GC.
Bye,
bearophile
scriptive name?
Bye,
bearophile
mmutable b; 0 .. 2)
foreach (immutable c; 0 .. 2)
writefln("%d xor %d xor %d = %d", a, b, c,
tuple(a, b, c).f);
}
Bye,
bearophile
Dennis Ritchie:
Please help.
This starts to look like homework :-)
Bye,
bearophile
switching off swap as result
we get ~200 MB of "dead data" in RAM, which can be released by
rebooting. How i can resolve it?
Look for CTFE code, perhaps some of it is excessive. You can
convert some of it to run-time in a module-level static this().
Bye,
bearophile
ted:
... where you say 'More DRY' above, are you referring to
I was referring to both, but mostly to the typeof. It's more DRY
(http://en.wikipedia.org/wiki/Don%27t_repeat_yourself ). You are
stating only once the type of the return variable. This is less
bug-prone.
Bye,
bearophile
I think this can be filed in Bugzilla as diagnostic enhancement:
class Foo {
@disable this();
this(int i) {}
}
void main() {}
https://issues.dlang.org/show_bug.cgi?id=14163
Bye,
bearophile
void bar(size_t N)(int[N] a, int[N ^ 2] b) {}
I meant:
void bar(size_t N)(int[N] a, int[N ^^ 2] b) {}
] b) {}
void main() {
int[2] a = [1, 2];
int[4] b = [1, 2, 3, 4];
foo(a, b);
bar(a, b);
}
So perhaps my suggestion to file an enhancement request is not a
good idea...
Bye,
bearophile
() {
auto values = [0.0, 3.0, -1.0, 5.0];
auto result = testFunc(values, 8.8);
}
The D compiler seems unable to compute ElementType!R in the
function signature. If I am right, then this seems worth an
enhancement request.
Bye,
bearophile
weak in optimizing well such kind of code... I think D compilers
handle built-in associative arrays in a very straight way.
Bye,
bearophile
more like this in D using the
latest version of the compiler:
void main() {
import std.stdio, std.range, std.algorithm, std.typecons;
iota(2, 12)
.map!(c => tuple(c ^^ 2 - 1, c ^^ 2 + 1, 2 * c))
.each!(x => writefln("%3d%4d%4d", x[]));
}
Bye,
bearophile
Tobias Pankrath:
Check for null with (x is null) not via printing to stdout.
In most cases instead of checking dynamic arrays for null, it's
better to use std.array.empty.
Bye,
bearophile
tion2 }
struct Boring {
this(E Opt = E.option1)(int arg1, int arg2) {}
}
void main() {
auto a = Boring().__ctor!(E.option2)(1, 2);
}
Bye,
bearophile
fra:
However making it a compiler error would be far, far better
I think this can be filed in Bugzilla as diagnostic enhancement:
class Foo {
@disable this();
this(int i) {}
}
void main() {}
Bye,
bearophile
e the first item equal to the given one.
You can then add a second function that removes at a given index
(like removeAt).
Bye,
bearophile
Tobias Pankrath:
Works as designed:
http://dlang.org/phobos/std_algorithm.html#.remove
Unfortunately it's one of the worst designed functions of Phobos:
https://issues.dlang.org/show_bug.cgi?id=10959
Bye,
bearophile
zhmt:
Will arr.ptr change in the future?
As the array add more members , it need more memroy, then
remalloc may be called, the pointer maybe change, then the
stored pointer will be invalid.
Will this happen?
Yes, it can happen.
Bye,
bearophile
t be immutable by default because otherwise
programmers often don't bother making them immutable. It's a lost
war.
Bye,
bearophile
error
of the D compiler to have them disabled by default).
foreach(i; 0..INITIALPOP){
It's less bug-prone to make that index immutable:
foreach(immutable i; 0 .. initialPop) {
Bye,
bearophile
It's probably better to ask such questions on GitHub (and to open
an enhancement request in Bugzilla).
Bye,
bearophile
gedaiu:
https://github.com/gedaiu/Game-Of-Life-D
A bare-bones implementation:
http://rosettacode.org/wiki/Conway%27s_Game_of_Life#Faster_Version
The quality of the D GC is not important for a simple Life
implementation, you just need two arrays.
Bye,
bearophile
chains is
quite important.
Bye,
bearophile
Jeremy DeHaan:
I figured that it would be smart enough to
deduce the parameter type based on the type that it was trying
to be assigned to.
For that you need languages like Haskell/Rust. D type inference
doesn't work from the type something is assigned to.
Bye,
bearophile
Tofu Ninja:
Basically what the title says, how do I check if a type T is an
instantiation of a specific template?
If you have an updated Phobos std.traits.isInstanceOf could be
what you look for.
Bye,
bearophile
newbies:
void main() {
int x;
writeln(a);
printf("%d\n", x);
}
Gives:
test.d(3,5): Error: 'writeln' is not defined, perhaps you need to
import std.stdio; ?
test.d(4,5): Error: 'printf' is not defined, perhaps you need to
import core.stdc.stdio; ?
Bye,
bearophile
Bye,
bearophile
question, do I ever need to manually release
objects I create with new?
Usually not. How much advanced do you want to be? :-)
Bye,
bearophile
T x, y;
}
This probably isn't enough to solve your problems, but it's a
start.
Bye,
bearophile
Currently we are
implementing a kind of pre-phase: http://wiki.dlang.org/DIP25
And here I have asked for @safe to become the default (Walter
seems not against this idea):
https://d.puremagic.com/issues/show_bug.cgi?id=13838
Bye,
bearophile
Baz:
doesn't work. And similarly to the the orginal post:
I suggest to read some D documentation first, and program later.
Bye,
bearophile
And it's named "dynamic array", instead of "Array List object",
it's not a class instance.
Bye,
bearophile
Gan:
//Initializing the array
tiles = new SBTile[](0);
This is often useless.
//Clearing the array
tiles = [];
This doesn't "clear" the array, it rebinds it to a null pointer.
Bye,
bearophile
erence and they are often on the heap, while a
struct is handled by value (or pointer to value). A class has two
extra hidden fields.
Bye,
bearophile
__traits(allMembers, mixin(__MODULE__)) also yields a module name
like object, but then how can you find out that "object" is a
module?
This doesn't work:
void main() {
pragma(msg, is(int == int));
pragma(msg, is(object == module));
}
Bye,
bearophile
Laeeth Isharc:
I think concatenation and append are used as synonyms (the same
meaning is meant). a~=b or a=a~b
a=a~b always allocates a new array, while a~=b sometimes
re-allocates in place.
Bye,
bearophile
Dominikus Dittes Scherkl:
Because this is useful in more situations,
Right, but it's still a cast. And in D you want to minimize the
number of usages of casts. The proposed syntax iota!"[]" is
cast-safe.
Bye,
bearophile
Vlad Levenfeld:
What's this about !`[]` and std.range.uniform?? It's not in the
documentation.
It's an enhancement I have proposed.
Bye,
bearophile
Dominikus Dittes Scherkl:
Has anyone any idea how to work around this?
In Bugzilla I have proposed to solve this problem with this
syntax taken from std.range.uniform:
iota!"[]"(ubyte.min, ubyte.max)
Bye,
bearophile
1 - 100 of 3597 matches
Mail list logo