When would you use in / out parameters instead of ref const
keywords?
Thanks.
to any doc generation setup with decent styling
that works out of the box would be great.
Thanks,
Dan
and want that for my own code, is there a tutorial on how to
create
it?
Thanks
Dan
On Thursday, 11 October 2012 at 16:45:08 UTC, Aziz K. wrote:
It's very easy to use DIL for doc generation (at least I try
hard to make it so.)
In your case you'd just have to run this command (use -I as
well if required):
dil ddoc path/to/output/ package1/*.d package2/*.d -v --kandil
-hl
/foo.d
tmp$ ls
candydoc foo.html foo.o pkgouter
Only foo.html was generated referencing pkgouter.pkg2.foo and
pkgouter.pkg2.foo. So, if I could get the dmd to output the html
filename as the package qualified name I think it would just work.
Thanks
Dan
to a different module, the
private impl prevents it from working:
Thanks
Dan
--
module play.m.x;
import std.stdio;
import std.container;
import std.datetime;
struct DateValue {
Date date;
double value;
}
struct RateCurve {
alias Array!DateValue Impl;
alias impl this;
// I am a Array
On Friday, 12 October 2012 at 23:05:27 UTC, Jonathan M Davis
wrote:
You can have the variable be private and alias a function which
returns by ref
instead of the variable itself. Something like
class C
{
@property ref inout(Impl) get() inout { return _impl; }
alias get this;
private:
According to the spec, private module members are equivalent to
static
declarations in C programs. Why does this work (i.e. print 5)?
Both imported.d and sample.d are in same directory
(.../attributes).
Thanks
Dan
--
import
On Tuesday, 16 October 2012 at 19:31:45 UTC, bearophile wrote:
Dan:
Why does this work (i.e. print 5)?
It looks like a compiler bug/hole. DMD is not yet aligned to
its specs...
Is it in Bugzilla?
Bye,
bearophile
Thanks. I had assumed my interpretation was incorrect and was
just
.
--
import std.stdio;
struct X {
class D {
string b = B;
}
string a = A;
D d;
}
void main() {
auto c = new X();
auto o = marshalJSON(c);
writeln(o);
}
--
Thanks
Dan
I got msgpack and was trying out an example (compare_json.d) and
I get an unresolved error.
Not sure what I'm doing wrong...
https://github.com/msgpack/msgpack-d/blob/master/src/msgpack.d
I think length is built in for associative arrays?
Thanks
Dan
The error and lines of code is:
-
/tmp
The following takes nearly three minutes to compile.
The culprit is the line bar ~= B();
What is wrong with this?
Thanks,
Dan
struct B {
const size_t SIZE = 1024*64;
int[SIZE] x;
}
void main() {
B[] barr;
barr ~= B();
}
-
On Tuesday, 23 October 2012 at 13:40:00 UTC, Dan wrote:
/tmp/.rd.../objs/compare_json.o: In function `const(@trusted
void function(ref
msgpack.Packer!(std.array.Appender!(ubyte[]).Appender).Packer))
msgpack.Value.toMsgpack!(msgpack.Packer!(std.array.Appender!(ubyte[]).Appender).Packer
refers to two methods with the same signature. In
typecons there are only two Binary methods, opBinary and
opBinaryRight, both in Proxy, so where is the
duplication/conflict coming from?
Thanks
Dan
---
import std.stdio;
import std.typecons;
import std.algorithm;
struct CcRate
specifying msgpack.d on the command line.
Thanks
Dan
dmd /.../msgpack-d/example/compare_json.d
/.../msgpack-d/src/msgpack.d
compare_json.o: In function
On Thursday, 25 October 2012 at 16:39:57 UTC, Dan wrote:
From bug tracker I see that Proxy has a few issues, so this has
likely been seen. But what would cause this error?
tmp/c.d(16): Error: overloads pure nothrow @safe double(auto
ref CcRate b) and pure nothrow @safe double(auto ref CcRate
, isNumeric!double); // true
-
struct CcRate {
private double rate = 0;
mixin Proxy!rate;
this(double rate) {
this.rate = rate;
}
}
Thanks
Dan
the crash is at:
http://pastebin.com/M67PamQM
Also the call stack is below. Any suggestions appreciated.
Thanks
Dan
Program received signal SIGSEGV, Segmentation fault.
0x7764990a in snprintf () from
/lib/x86_64-linux-gnu/libc.so.6
(gdb) where
#0 0x7764990a in snprintf () from
/lib
problem or not. I have a crash, I rebuild with different
flags and it works does not mean compiler bug - although in this
case you may be correct.
Thanks
Dan
must not be relying too much on
deep equality semantics like this. But how else can you find
things?
Thanks
Dan
of opEquals in B,C,D for
free (maybe only if called).
If this is still off base please let me know.
Thanks
Dan
was for poor man debugging
capabilities.
Thanks
Dan
?
Thanks
Dan
Why do the commented out calls to goo fail?
Thanks
Dan
-
import std.stdio;
struct S {
}
void goo(const ref S s) {
writeln(s);
}
struct T {
S s;
void foo(const ref T other) const {
goo(s);
// Error: function fdsaf.goo (ref const(S) s
On Wednesday, 31 October 2012 at 17:11:47 UTC, Tobias Pankrath
wrote:
On Wednesday, 31 October 2012 at 16:59:14 UTC, Dan wrote:
Why do the commented out calls to goo fail?
Thanks
Dan
Compiles fine with git-head.
I did git clone: git clone
https://github.com/D-Programming-Language/dmd.git
_D55TypeInfo_S8plusauri6bsheet13balance_sheet12BalanceSheet6__initZ
| ./ddmangle
this
_D56TypeInfo_xS8plusauri6bsheet13balance_sheet12BalanceSheet6__initZ
unq
_D55TypeInfo_S8plusauri6bsheet13balance_sheet12BalanceSheet6__initZ
What is the correct way to do this?
Thanks
Dan
, then per TDPL not necessary? Is it harmful or
harmless?
Also, are there any guidelines for using and interpreting the
output of
valgrind on a D executable?
Thanks
Dan
The following works, but I want to make opAssign in D take const
ref D.
It needs to still print (dup here). How can this be done?
Thanks
Dan
import std.stdio;
struct A {
char a[];
this(this) { a = a.dup; writeln((dup here)); }
}
struct B { A a; }
struct C { B b; }
struct
This may be a manifestation of bug 1528. In the code below how
can I heap allocate a default S? I can't seem to get a call to
work.
In general structs are stack objects, but is there any problem
with using the heap to get one?
Thanks
Dan
--
import std.stdio
On Sunday, 4 November 2012 at 19:30:49 UTC, Tobias Pankrath wrote:
Sadly you have to cast, because typeof([]) is void[].
Alternatively you could define an constructor that takes void[]
but insists of the argument being empty.
Great explanation - thanks!
() is not callable using
argument types () const
Below I cast away const (Dohh!). Is it safe in this case?
If not is there another way?
Thanks,
Dan
import std.stdio;
import std.traits;
alias Account[string] Map;
struct Account {
this(this){ writeln(acct copied); }
}
void foo(const ref Map m
the
casts safe and on a future release of D rendering them
unnecessary.
Thanks
Dan
-
alias Account[string] Map;
struct Account {
this(this) const { writeln(acct copied); }
//this(this) { writeln(acct copied); }
}
they be incorporated or would that be a can of worms?
Hopefully the comments convey the intent well enough and if there
are better approaches please let me know.
Any feedback appreciated.
Thanks
Dan
efficient it wont get called.
As bearophile pointed out this issue will change anyway. At that
point I think the OpEquals becomes mute. I hope I'm covered by
just turning its implementation into a no-op and my classes
don't change.
Thanks
Dan
--
struct A {
void pushOne() { i ~= 1
Why does g(cs) compile but not G(cs)?
Thanks,
Dan
struct S{}
void g(ref S i) {}
void g(const ref S i) {}
void G(T)(ref T i) {}
void G(T)(const ref T i) {}
void main() {
S s;
const(S) cs;
g(s);
g(cs);
G(s);
// Error: template p.G matches more than one template
declaration, /p.d(5
. If it is a bogus comparison for whatever reason let me
know. It seems if performance is the only issue, just use *const
ref* or *in ref*.
Thanks
Dan
-
2 bytes: using cref_(int size) took 39[ms]
2 bytes: using inref(int size) took 40[ms]
2 bytes: using in___(int size) took 31[ms]
4
) if(isMutable!T) { }
void G(T)(const ref T i) { }
Thanks,
Dan
some automated way of pulling
in info from all fields you need to revisit the hash (and opCmp
and opEquals).
Thanks
Dan
be upset.
Thanks
Dan
;
A a = { [0], [ foo : bar ] };
b.a = a;
}
Thanks
Dan
-jonkbhtibdxjfjethtuo:40forum.dlang.org
Thanks
Dan
import std.stdio;
struct S {
this(const this) { writeln(Is this called); }
}
void main() {
S x;
const(S) cx;
S x2 = x;
S x3 = cx;
}
in the hash while avoiding
concatenation.
Yes.
Thanks
Dan
is how I'm doing it.
No guarantees, but output looks promising. Code following output.
Thanks
Dan
-
true
false
false
true
7F053B2DCFC0
20883845 vs 20883845
-
import std.stdio;
import std.traits;
import std.typecons;
import opmix.mix;
struct
This fails to compile when accessing as m.pgoo() complaining
about postblit.
What is wrong with this?
Note: If I alias as array instead of map: alias const(X)[] Map;
it compiles fine.
Thanks
Dan
-
struct X { this(this) {} }
alias const(X)[string] Map;
@property int
This fails to compile when accessing as m.pgoo() complaining
about postblit.
What is wrong with this?
Note: If I alias as array instead of map: alias const(X)[] Map;
it compiles fine.
Thanks
Dan
-
struct X { this(this) {} }
alias const(X)[string] Map;
@property int
This fails to compile when accessing as m.pgoo() complaining
about postblit.
What is wrong with this?
Note: If I alias as array instead of map: alias const(X)[] Map;
it compiles fine.
Thanks
Dan
-
struct X { this(this) {} }
alias const(X)[string] Map;
@property int
. Assuming I do nothing to
val in the loop (in fact I'd like to just cast it to const to
guarantee it), is this the way to go?
Thanks
Dan
-
import std.traits;
alias const(X)[string] Map;
struct X {
this(this) {}
char[] x;
}
void foo(ref const(Map) m) {
// FAILS
custom opCast members. Is a
reasonable
suggestion for the language?
The cast here fails because it is considering custom opCast
methods,
but that is not helpful.
Thanks
Dan
-
import std.bitmanip;
void main() {
const(BitArray) cba;
cast()cba;
}
On Thursday, 15 November 2012 at 17:24:44 UTC, Jonathan M Davis
wrote:
On Thursday, November 15, 2012 14:21:41 Dan wrote:
I do not see how copy constructors can help. Receiving const(T)
or const(T) ref to anything and hoping to copy it is the
challenge and doing it from a copy constructor
On Thursday, 15 November 2012 at 20:59:37 UTC, Namespace wrote:
Why work this: http://dpaste.dzfl.pl/16a1c912
but not this: http://dpaste.dzfl.pl/6cebb0ad
?
If it is any consolation - the latter does work in 2.061 but not
2.060. It prints:
[0:const(A), 1:const(A)]
Thanks
Dan
it's own dup with a proper const qualifier,
which gdup could call in preference to a recursive call to gdup.
You mention that possibly postblits will go away. That is
discomforting.
In terms of priority, where does this fall?
Thanks
Dan
-
import
On Monday, 19 November 2012 at 05:22:38 UTC, Jonathan M Davis
wrote:
On Monday, November 19, 2012 06:01:55 Rob T wrote:
postblit constructors and opAssign aren't really related. The
postblit
constructor is used when a _new_ instance is being constructed
(it plays the
same role as a copy
/doc/canonical.pdf
https://github.com/patefacio/d-help/blob/master/d-help/opmix/mix.d
The idea is that the transitive nature of const in D is perfect
for providing those copy on write semantics without any extra
work if you can copy the const object when needed.
Thanks
Dan
On Monday, 19 November 2012 at 12:10:32 UTC, Dan wrote:
Just following up to get confirmation. Hopefully Johnathan or
similar expert can follow up.
Here is a strong statement:
If for any struct S you implement a postblit then there is no
need to implement opAssign to get a working
:
(https://github.com/patefacio/d-help/blob/master/d-help/opmix/mix.d)
Thanks
Dan
-
import std.stdio;
import std.traits;
import opmix.mix;
struct Bar {
private char[] c;
this(this) { c = c.dup; }
}
class Foo {
@property ref const(Bar) bar() const { return _bar
your own opAssign. I
think some of the magic goes away if I'm not mistaken (i.e. those
well-crafted postblits will not be called). I think this should
be documented as well.
Thanks
Dan
.
Thanks
Dan
On Monday, 26 November 2012 at 03:23:42 UTC, Geancarlo wrote:
Hello, I'm using DMD32 D Compiler v2.060 for on Windows.
writeln(TestStruct.x.offsetof);//bug here
This works without creating your own instance:
writeln(TestStruct.init.x.offsetof);
Thanks
Dan
On Monday, 26 November 2012 at 19:14:09 UTC, Joseph Rushton
Wakeling wrote:
On 11/26/2012 04:07 PM, Joseph Rushton Wakeling wrote:
I'm a bit confused as to why. By the look of things it's
actually the creation
of new entries in the Node[uint] associative array, rather
than appending links
to
welcome.
Thanks
Dan
-
import std.typecons;
import std.stdio;
alias RefCounted!(int) Foo;
Foo[int] map;
unittest {
map[1] = Foo();
}
Dump of assembler code for function _D3lnk11__unittest1FZv:
0x0044367c +0: push %rbp
On Tuesday, 27 November 2012 at 14:05:37 UTC, Joseph Rushton
Wakeling wrote:
On 11/27/2012 01:16 PM, Joseph Rushton Wakeling wrote:
... so the real issue here seems to be that there's no
canonical way (that I can find) to idup an _associative_ array.
I'm using a custom gdup that recursively
since it
figures it out.
The below seems to work.
Thanks,
Dan
import std.traits;
import std.stdio;
void test1(T)(auto ref T val) if(!isArray!T) {
writeln(Nonarray , typeid(typeof(val)));
}
void test1(T)(auto ref T val) if(isArray!T) {
writeln(Array , typeid(typeof(val)));
}
void main
On Tuesday, 27 November 2012 at 18:04:19 UTC, Maxim Fomin wrote:
I think it crashes because of using associative array.
Assignment to an absent aa member causes memory allocation
without proper object construction, and immediately after
compiler issues call to opAssign for not-constructed
inserting a key that is not present). Or maybe it is just a map
problem and by switching to main I am just getting lucky in not
getting a crash.
It would be interesting to know if Joseph was doing his testing
out in unittest or in a main.
Thanks
Dan
Here is the code that crashes. Change
On Wednesday, 28 November 2012 at 13:43:04 UTC, Maxim Fomin wrote:
On Wednesday, 28 November 2012 at 13:09:36 UTC, Dan wrote:
Actually bug is still there - changing unittest to main() does
not fix program, even if it seems to run correctly. The problem
with memory corruption is that it may
On Wednesday, 28 November 2012 at 20:30:41 UTC, Maxim Fomin wrote:
On Wednesday, 28 November 2012 at 18:08:59 UTC, Dan wrote:
This code with version=bug produces garbage because of
opAssign. It seems that opAssign is actually called before
accessing map:
Maxim, thanks for looking more
On Thursday, 29 November 2012 at 07:59:02 UTC, Maxim Fomin wrote:
This doesn't look like assembly for previous source. Please
provide the source for which you have assembly and tell which
dmd options do you use.
Well, I'm using the latest dmd (from the trunk), phobos,
druntime, so I could
some (unwanted?) data sharing going on since there are no
postblits and you have reference types with aliasing.
Some descriptions of the code and its intentions are:
https://github.com/patefacio/d-help/blob/master/doc/canonical.pdf
Thanks
Dan
On Thursday, 29 November 2012 at 15:06:07 UTC, Maxim Fomin wrote:
On Thursday, 29 November 2012 at 12:38:03 UTC, Dan wrote:
On Thursday, 29 November 2012 at 07:59:02 UTC, Maxim Fomin
wrote:
This doesn't look like assembly for previous source. Please
provide the source for which you have
Is there a way to walk files with std.file.dirEntries such that
certain directories are skipped (i.e. how to avoid .git
entirely/recursively)?
Thanks
Dan
On Friday, 30 November 2012 at 01:13:13 UTC, Jonathan M Davis
wrote:
On Friday, November 30, 2012 01:24:07 Dan wrote:
Is there a way to walk files with std.file.dirEntries such that
certain directories are skipped (i.e. how to avoid .git
entirely/recursively)?
You can use std.algorithm.filter
is for performance, and it actually runs
significantly slower than without on my test case - but no work
is being done other than build the list of files, so that is
probably normal. For my case the breakdown is:
No Pruning: 11 sec
Pruning Parallel: 4.78 sec
Pruning Serial: 0.377 sec
Thanks
Dan
On Friday, 30 November 2012 at 19:52:26 UTC, Jonathan M Davis
wrote:
If you're compiling with -property, filter must have the parens
for the
function call as it's a function, not a property. The !() is
for the template
arguments and is separate from the parens for the function
call. That
thing, is there maybe a C-* alternative to M-compile
since it takes time to type that everytime?
I use the lisp code below. Then from the source with main I do:
C-c @ To run the main in the current buffer
C-c # To run the unit test in the current buffer
Thanks
Dan
is on the chopping block?
Thanks
Dan
On Sunday, 2 December 2012 at 01:50:08 UTC, Jonathan M Davis
wrote:
On Saturday, December 01, 2012 19:36:34 Dan wrote:
That syntax is from C. There was definitely a push to deprecate
it, and
personally I definitely think that it should go, but I don't
recall that it was
definitively decided
is no and default implemented opAssign
must remain impure, is there a standard way, in a member function
to do like:
auto ref opAssign(S other) pure {
blit other into this
call this(this)
}
Thanks
Dan
-
import std.stdio;
import std.algorithm;
struct S {
char[] c;
this(this) pure { c
On Sunday, 2 December 2012 at 14:13:34 UTC, Maxim Fomin wrote:
On Sunday, 2 December 2012 at 13:07:42 UTC, Dan wrote:
Default opAssign function is described here:
http://dlang.org/struct.html. It calls dtor and postblit (if
any) which are impure. Even if you mark them pure, you still
On Sunday, 2 December 2012 at 19:12:46 UTC, Ali Çehreli wrote:
On 12/02/2012 07:50 AM, Dan wrote:
I was going to ask Is __postblit a part of the language spec
but then I found TypeInfo.postblit:
http://dlang.org/phobos/object.html#postblit
I hoped the following might work
On Sunday, 2 December 2012 at 19:34:46 UTC, Jonathan M Davis
wrote:
Pretty much none of the built-in stuff like that is pure or
nothrow right now.
It needs to be fixed.
Maybe I'm naive, but problems with lax specification of pure,
const and immutable should be low hanging fruit - relatively
On Sunday, 2 December 2012 at 22:19:18 UTC, Jonathan M Davis
wrote:
On Sunday, December 02, 2012 23:04:29 Dan wrote:
What about the specification is lax? pure, const, and immutable
are quite well
defined.
Sorry - by specification I was not thinking D Language
Specification but more API
On Wednesday, 5 December 2012 at 00:17:05 UTC, deed wrote:
interface I
{
bool opEquals(I i);
}
class C : I
{
bool opEquals(I i)
{
return true;
}
}
void main()
{
I i1 = new C;
I i2 = new C;
assert(i1 == i2); // Assertino failure
assert(i1 != i2); //
statement anywhere it will ensure everything is rebuilt. If you
have just recently run this command, you can run again without
--force.
One thing to be aware of, I think when using unittest sections,
not only are your unittests run, but unittests of all your
imports.
Thanks
Dan
.
Usually the best place to learn the way of a language is studying
its standard libraries, so that is what I am after - the why's of
it.
Thanks
Dan
On Monday, 17 December 2012 at 03:23:13 UTC, bearophile wrote:
Then I suggest you to not study std.random because it currently
contains know flaws regarding what you are saying.
Fine, thanks. But which would be recommended to study?
For the code below, S is never copied even though a version of
the function resolving to void x.foo!(x.S).foo(x.S) is called.
How is this possible?
Is it an optimization? I figure if I call a function that takes
its parameter by value, there should be a copy.
Thanks
Dan
make sense to follow? I
apologize if this is obvious/well known and I consider myself new
to D, so please address any of my misconceptions. I'm finding
that on the surface D sounds much simpler than it is, but if I
can get a good set of guidelines it should all work out.
Thanks,
Dan
(COW
On Monday, 17 December 2012 at 20:46:27 UTC, Dan wrote:
Sorry, here is the table more legible:
http://pastebin.com/0bFSL0Xz
be glad
to learn from your experience.
Thanks
Dan
... I don't know how successful it is.)
Agreed.
Thanks,
Dan
selection process accordingly.
Thanks,
Dan
History with no relationship to RC causes an error to show for RC.
Thanks
Dan
to the offending and I still don't
understand the error.
Thanks
Dan
. Baffling.
Any suggestions appreciated.
Thanks
Dan
where needed. That approach, just does not seem worth
it without more systematic support for COW. Assuming postblits
are the issue, I don't understand why they are so hard to get
right.
Thanks
Dan
) led you to this
solution and for how long will it be valid? Where can I read more
on it?
Thanks
Dan
welcome.
Also, an FYI to dpaste maintainer that the compiler service has
been unavailable for a while.
Thanks
Dan
for a given key the hash is computed
just once. I believe this would have to be done at the level of
AssociativeArray and can not be done as a helper function, since
this set helper is still doing 3 hashes/lookups.
Thanks
Dan
is the reason for the difference
between unittest constants and module constants?
Thanks,
Dan
On Saturday, 9 February 2013 at 00:54:58 UTC, Andrej Mitrovic
wrote:
Feel free to file an enhancement request.
http://d.puremagic.com/issues/show_bug.cgi?id=9491
Hopefully that is clear.
1 - 100 of 221 matches
Mail list logo