Don wrote
Consider this notorious piece of code:
assert(x1);
double y = 1 / x;
This calculates y as the reciprocal of x, if x is a floating-point number.
But if x is an integer, an integer division is performed instead of a
floating-point one, and y will be 0.
It's a very common newbie
Removing a struct definition from the second mixin seems to fix the problem.
Is this a (known) bug?
The struct was only used within that template.
public struct S
{
enum LOCAL { ONE, TWO };
LOCAL local;
bool b = false;
StructOut s;
ENUM_OUT eo;
}
bearophile wrote:
Saaa:
Is this a (known) bug?
It's generally better if you show a tiny compilable example that has the
problem.
Bye,
bearophile
I'm trying :)
I just hoped somebody would recognize it from my babbling
Tomorrow I'll continue my quest for the mall piece of code which will choke
the compiler.
Can't recreate the error in a small test project (5 modules).
I think the problem lies somewhere in between cyclic module imports, mixin
struct definitions and maybe the actual size of the class(1k) and its
complexity of interfaces(8).
One more thing:
The out of memory is before it can tell
I was trying out composite oriented programming, meaning moving class
functionality into templates which you then mixin.
First part mixined just fine, second also ok, third . .
- Error : Out of memory (2GB VM)
Even with an empty template :(
struct S : Pos {}
Why is this not possible?
bearophile wrote:
Moritz Warning:
If you only what a contract that certain functions are implemented,
then it just need to be implemented in the compiler frontend.
In the meantime this can be done with a template mixin, where the template
statically asserts the presence of the
Bill Baxter wrote:
On Tue, Nov 24, 2009 at 2:49 PM, Saaa em...@needmail.com wrote:
bearophile wrote:
Moritz Warning:
If you only what a contract that certain functions are implemented,
then it just need to be implemented in the compiler frontend.
In the meantime this can be done
Bill Baxter wrote:
daniel.keep.li...@gmail.com wrote:
(This is all off the top of my head.)
nice explanation snipped -- thanks
snipped --bb
Thanks for all the explanations!
Is it possible to have different objects of the same class have (refs to)
different sized static arrays?
I loop through the 2D arrays diagonally and as far as I understand arrays,
dynamic ones don't really like this.
Thanks!
Also random accessing the array :)
Ali Cehreli wrote...
This helps me with the meaning of in, out ref.
http://bayimg.com/NaeOgaaCC
Andrei Alexandrescu wrote
Saaa wrote:
Andrei Alexandrescu wrote:
Andrei Alexandrescu wrote:
Saaa wrote:
Could anybody clear these up for me?
p16. Is there anything other than the random values, unsafe about
void assignment?
I'd put your feedback on my pile of things to do, but now
Andrei Alexandrescu wrote
Saaa wrote:
Andrei Alexandrescu wrote:
Andrei Alexandrescu wrote:
Saaa wrote:
Could anybody clear these up for me?
p16. Is there anything other than the random values, unsafe about
void assignment?
I'd put your feedback on my pile of things to do, but now
Could anybody clear these up for me?
p16. Is there anything other than the random values, unsafe about void
assignment?
p18. What is unsafe about implicit conversion of static to dynamic array?
Meaning getting a dynamic array pointing to a stack allocated
array.
Any
Andrei Alexandrescu wrote:
Andrei Alexandrescu wrote:
Saaa wrote:
Could anybody clear these up for me?
p16. Is there anything other than the random values, unsafe about void
assignment?
I'd put your feedback on my pile of things to do, but now that you ask, I
made this change
Also, no mention about .dup not being a deep dup.
crp
p20. 40 words?
those where for myself, to check
Andrei Alexandrescu wrote
It's a rough rough draft, but one for the full chapter on arrays,
associative arrays, and strings.
http://erdani.com/d/thermopylae.pdf
Any feedback is welcome. Thanks!
Andrei
Makes me want to read the rest!
Will we get the electronic version with the paper
Also, no mention about .dup not being a deep dup.
Saaa wrote
Also, no mention about .dup not being a deep dup.
Sorry, should've been attached to my response
crp
p20. 40 words?
those where for myself, to check
Saaa wrote:
Steven Schveighoffer wrote
But I've changed everything to `new` the array afterwards as I deleted
all the
keys anyways.
Not sure what you mean here.
foreach (K k, ; aa)
{
..
//aa.remove(k);
}
aa = new int[char];
Error: new can only create structs, dynamic arrays
Lutger wrote:
I'm not sure it is very useful. I can think of a couple of reasons to
define
simple getter / setters:
- must be done when implementing an interface
- binary compatibility perhaps (again: interfaces)
- you will or might add functionality to the get/set functions at a later
Steven Schveighoffer wrote:
Yes, behavior is undefined.
from http://digitalmars.com/d/2.0/statement.html#ForeachStatement :
The aggregate must be loop invariant, meaning that elements to the
aggregate cannot be added or removed from it in the [loop body]
I suspect removing the current key
Ellery Newcomer wrote:
grauzone wrote:
Saaa wrote:
public void addToAA(char[] var_name, KT, ET)(KT key, ET element)
{
mixin(ET.stringof~`[]* elements = key in `~var_name~`;`);
if( elements == null )
{
ET[] temp;
temp.length = 1;
temp[0] = element;
mixin(var_name
Ary Borenszweig wrote:
Saaa wrote:
public void addToAA(char[] var_name, KT, ET)(KT key, ET element)
{
mixin(ET.stringof~`[]* elements = key in `~var_name~`;`);
if( elements == null )
{
ET[] temp;
temp.length = 1;
temp[0] = element;
mixin(var_name~`[key] = temp
public void addToAA(char[] var_name, KT, ET)(KT key, ET element)
{
mixin(ET.stringof~`[]* elements = key in `~var_name~`;`);
if( elements == null )
{
ET[] temp;
temp.length = 1;
temp[0] = element;
mixin(var_name~`[key] = temp;`);
}
else
{
(*elements).length =
Chris Nicholson-Sauls wrote
The most important thing is remembering that black text on a white screen
carries absolutely no emotional information whatsoever, in either
direction, in any case. The exception that proves the rule, of course, is
ZOMG NERD RAGE ALLCAPS. Otherwise, there's
Michael Rynn wrote
I have made a validating or optionally none validating XML parser in
D.
nice
But I would like to have it made available so others can test.
Maybe add it as an enhancement in bugzilla
Where and to whom can I post the 56 KB source code zip?
NG attachement? Or is that
Justin Johansson wrote
Saaa Wrote:
Michael Rynn wrote
I have made a validating or optionally none validating XML parser in
D.
nice
But I would like to have it made available so others can test.
Maybe add it as an enhancement in bugzilla
Where and to whom can I post the 56 KB
Michael Rynn wrote
Where and to whom can I post the 56 KB source code zip?
Attaching it to an enhancement in bugzilla would be best, I think.
Yigal Chripun wrote
ego has nothing to do with being smart.
you can be extremely smart without getting on people's nerves all the
time.
A smart person can choose when to get on somebody's nerves ;)
Yigal Chripun yigal...@gmail.com wrote in message
news:hb2u2n$2if...@digitalmars.com...
On 13/10/2009 20:24, Saaa wrote:
Yigal Chripun wrote
ego has nothing to do with being smart.
you can be extremely smart without getting on people's nerves all the
time.
A smart person can choose when
#ponce wrote...
Hi,
We won another demo compo with a D entry (at MAIN demoparty)
http://www.pouet.net/prod.php?which=53942
We tried to make a bigger and more impressive entry this time. Note that
it's a french party so it's not Breakpoint.
D clearly allowed us to be more productive
Jarrett Billingsley wrote
On Thu, Oct 8, 2009 at 12:04 AM, Andrei Alexandrescu
seewebsiteforem...@erdani.org wrote:
I'd decided to not use the first person at all in TDPL, but now I find
myself a bit constrained by that decision. I personally think a small
amount
of meta-references and
Jeremie Pelletier wrote
Then why use an ubyte instead of a byte or an int?
I wasn't me who wrote that part of the code :)
You could also just do:
for(int i = cast(byte)nloop; i 10; i++)
I forgot the minus sign:
for(int i = -cast(int)nloop;i 10; i++)
Still think it is unnecessary bug-prone.
Moritz Warning wrote
This is a troublesome behavior:
ubyte z = 5;
int x = -z; // x now is 251
int y = -1 * z; // y is now -5
Yes, troublesome is the correct word :)
Does anybody ever use the =-z behaviour?
Andrei Alexandrescu wrote
I wonder whether this would be a good topic for TDPL. Currently I'm
thinking it's too low-level. I do plan to insert a short section about
implementation, just not go deep inside the object model.
Andrei
I'd really love to see more about implementations as it
Phil Deets wrote
I tried Descent, but it didn't work well at all with my D2 program. It
also didn't support building. I'll look into Poseidon. Thanks.
What exactly do you expect from supporting building?
I use descent to build my project by using the external tool setup shown
here:
Jeremie Pelletier wrote
...
Wow, talk about slow.. thanks again for all the help/explanations !
http://bayimg.com/NaeOgaaCC
I tried callee/caller but it is just that bit more difficult to distinguish.
There should be more diagrams like this..
would make a lot of things a lot easier (to me at
Steven Schveighoffer wrote:
On Mon, 21 Sep 2009 11:12:49 -0400, #ponce alil...@gmail.com wrote:
Is there a reason to use ref instead of in, inout or out ?
I'm using D1 and it's not in the spec.
It is here in the spec: Function Parameters
http://www.digitalmars.com/d/1.0/function.html
ref
Don wrote:
You always seem to be so negative! In one recent DMD release, half the
changes were bugfixes requested by you...
If everyone involved in compiler development spent 100% of their time on
bearophile requests, you still might not get everything you want g.
Actually you have at
bearophile Wrote:
Saaa:
Is there a better way to support arrays of any type?
Currently all the code working with these Structs are templated with loads
of static ifs in them.
You have to ask a more precise question if you want an answer.
Maybe a more general one :)
I use a tagged
Ah, slicing, of course, thanks!
Hello Saaa,
I understand a bitarray being faster than a boolean array as the first
uses
bitwise (hardware) operators.
Is this a correct understanding of the situation?
Why then is a boolean array not implemented in that way?
Because you can't slice a bit
(D1 Phobos)
I use the struct below like: Struct[][char[]] _struct;
Is there a better way to support arrays of any type?
Currently all the code working with these Structs are templated with loads
of static ifs in them.
Also, is it possible to add a .deepdup property to all arrays?
One last
(D1 Phobos)
I use the struct below like: Struct[][char[]] _struct;
Is there a better way to support arrays of any type?
Currently all the code working with these Structs are templated with loads
of static ifs in them.
Also, is it possible to add a .deepdup property to all arrays?
One
I understand a bitarray being faster than a boolean array as the first uses
bitwise (hardware) operators.
Is this a correct understanding of the situation?
Why then is a boolean array not implemented in that way?
I expect there to be a good reason which I just don't know.
I'd like to be able to
How should I procede to get this functionallity into phobos?
Daniel Keep daniel.keep.li...@gmail.com wrote in message
news:h88cck$1or...@digitalmars.com...
Saaa wrote:
abstract class C
{
int method();
}
class C2:C
{
int method() return 2;
}
class C3:C
{
int method() return 3;
}
int delegate() deleg;
void main()
{
C c;
C2 c2 = new
Ary Borenszweig a...@esperanto.org.ar wrote in message
news:h88i6o$23h...@digitalmars.com...
Saaa wrote:
Daniel Keep daniel.keep.li...@gmail.com wrote in message
news:h88cck$1or...@digitalmars.com...
Saaa wrote:
abstract class C
{
int method();
}
class C2:C
{
int method() return 2
class Foo
{
C* c;
this(ref C c)
{
this.c = c;
}
int invoke()
{
return (*c).method();
}
}
void main()
{
// ...
deleg = (new Foo(c)).invoke;
}
Or something similar.
This is dangerous. Do not allow either the Foo instance or the delegate
to survive past the
Hello Saaa,
How should I do this then?
C c;
C2 c2 = new C2;
C3 c3 = new C3;
c=c2;
auto dg = { return c.method(); };
c=c3;
I actually did it like this before :) Thanks
But like this I need to do the c is null checking within the function
literal.
I'm not sure how these function
Or does the compiler handle them like any
other
function and just thinks of a name itself ?
Exactly. If you compile with DMD and the -v flag you can see what names it
gives them.
:) nice
Thanks!
Steven Schveighoffer schvei...@yahoo.com wrote in message
news:op.uzxs4wyreav...@localhost.localdomain...
On Sun, 06 Sep 2009 18:54:47 -0400, Saaa em...@needmail.com wrote:
I'd like to set D's delegate to a method which is not yet available (like
c.method).
I solved this by encapsulating
The problem lies more in that I'd like to point to something which is not
there yet.
In the code 'c.method()' is not there yet, as c is null.
Maybe I should create a dummy object for c to point to in stead of null ?
That way I point the delegate to the dummy method and ignore it as long
as
Hm... I'm still confused. Why not just set the delegate to null? Why
do
you need to have the delegate set to something?
It is for the gui. I give it a list of things to display.
And some of these things don't yet exist or can be deleted at any time.
I'd like it to display the last valid
But most of the ideas I suggest here get dispersed like tears in rain :-)
I read them ;-)
Steven Schveighoffer schvei...@yahoo.com wrote in message
news:op.uzqxxo1neav...@localhost.localdomain...
On Fri, 04 Sep 2009 14:33:12 -0400, Saaa em...@needmail.com wrote:
class C
{
private int i;
int method()
{
return i;
}
}
class D
{
private int delegate(void
class C
{
private int i;
int method()
{
return i;
}
}
class D
{
private int delegate(void) _deleg;
this(int delegate(void) d)
{
_deleg = d;
}
void write()
{
if(_deleg !is null)
}
writef(_deleg());
}
}
}
C c = null;
D d = new d;
Only curious, what is the influence record of the wishlist?
Mixins can be used to do a lot (most? all?) of things CRTP is used for:
class Class(alias MixMe)
{
mixin MixMe impl;
...
void doSomething {
impl.doIt();
}
}
where can I read about class parameters?
const char[] re1 = `(re)1`;
const char[] re2 = `(re)2`;
char[] matchWrite(RegExp re)
{
writefln(re.match(1),`,`,re.match(2));
return ;
}
std.regexp.sub(`re1 re2`, re1~'|'~re2, matchWrite, g);
--- prints
re,
re,re // shouldn't this be `,re`?
I cannot believe that anybody actually uses the std2 project files.
Why do you believe this?
I do..
Ran unit tests and also successfully rab the books.xml example.
Ok, so I can use this one as well, thanks!
Re-enabled the disabled unittest in std.encoding, and fixed the little
bug that was
Lars T. Kyllingstad pub...@kyllingen.nospamnet wrote in message
news:h5tsuu$bc...@digitalmars.com...
Saaa wrote:
Some time ago I requested something on .D, but it was ignored.
I'm interested in why this is so.
It was only a small request, maybe not fitting for .D but dsourse/phobos
said
filed
http://d.puremagic.com/issues/show_bug.cgi?id=3248
Some time ago I requested something on .D, but it was ignored.
I'm interested in why this is so.
It was only a small request, maybe not fitting for .D but dsourse/phobos
said that was the place for such things.
(Maybe it was unintelligible again?)
---
Could an option be added to the formatting
2 is very nice towards the namespace
how will you do regex.find vs string.find?
Ary Borenszweig a...@esperanto.org.ar wrote in message
news:h4pcpc$2ef...@digitalmars.com...
Qian Xu escribió:
Ary Borenszweig wrote:
Enjoy :-)
Great work.
BTW: Is there any plan to make a Organize Imports
2 is very nice towards the namespace
how will you do regex.find vs string.find?
Just what JDT does: show you the matches of find and allow you to choose
one of them.
never used JDT for anything but your descent :)
but I should have known this is handled nicely already
I don't see how all this property talk has anything to do with formatting!
:D
Marketing? I don't think Walter's really looking to get rich with D.
I vaguely remember Walter asking for ideas to make money with D though.
(might remember that incorrectly:)
And there are plenty of popular things out there with silly-sounding
names - Hadoop, Twitter, Meebo, Mibbit..Google
Could an option be added to the formatting to elide trailing zero's for %f ?
That way it is possible to create an more optimal formatting for which the
following holds:
float f;
s = format(f);
float f2 = to!(float)(s);
assert(f==f2);
The formatting I'm trying to get can be seen here (decimal):
But you never inserted anything in aa[test].
You must do:
S s;
aa[test] = s;
aa[test].i = 10;
or:
S s;
s.i = 10;
aa[test] = s;
erm, ok
Thanks
So no creation on use :)
Personally I find the declation step clutter in the first case.
Maybe promote the bug to a request?
struct literals .. need to remember all D's features :)
D1.046 seems SS
aa[test]=S();
works fine as well
Try:
struct S { int i; }
S[char[]] aa;
void main() {
aa[test] = S(10);
}
In theory a Sufficiently Smart Compiler is able to optimize that code
well.
Bye,
bearophile
Your Idea isn't so bad, but why should a programmer translate his complete
project into another language? I mean, when I've chosen Java, then I want
to make Java:) and NOT D or C#...
D1 to D2 I can fathom
Maybe interesting for other people
Abstract:
%.8e format holds full precision information for floats
making it a good %a contender
float have max 24bit precision
2^-24 = 0.00059604644775390625
2^-23 = 0.0011920928955078125
to distinguish between these two you only need a precision of 8.
That is a question for a philosopher, right up there with what makes you,
you? IIRC the body replaces 100% of it's matter several times of your
life. Some parts more often than others.
No, some parts stay with you for the rest of your life (e.g. nuclear pore
scaffold in brain cells)
What
I suppose the answer would be the same, too: The Soul.
Lol
Isn't the precision of a float 8 decimal digits?
.dig reports 6
Why isn't %.100g cropped to the max decimal digits of the accompanying
type?
floating point types are printed with 20 digits.
I just want to format in full precision.
As far as I can see 6 digits is not the full precision
e.g. 0x7EAB = 1.1342746e38
You'd just have to convert each element of the
array separately.
I found the formatting options, they are in std.format..
(I was apparently searching for the 'g' option.. )
this seems to work (using std2.string.format)
double[] d1;
d1=[double.max,double.min];
char[] c;
c=format(
double d[2] = [ 0, 1, double.max];
char[] c = format(d);
How do I get c to represent full precision?
[0,1,1.7976931348623157e+308] // but then with double.max being
represented fully
You want a 309-digit number consisting mostly of 0s?
Yes, but only if they are necessary.
0 doesn't need
Is it possible to get the passed variable name à la:
--
void functio(A...)(ref A a)
{
writefln(typeof(a[0]));
}
int i;
functio(i); // prints i
--
Also how do I fix this:
--
functio(`i`); // Error: i is not an lvalue
--
No.
You should be able to get the name using an alias:
void func(alias var)()
{
writefln(var.stringof);
}
Can this be combined with the tuple parameter?
But you can't do it at runtime.
Also how do I fix this:
--
functio(`i`); // Error: i is not an lvalue
You have to store the
Kisses Ary:
It seems you can't mixin cases separately, you need to mixin the whole
switch (bug?)
string CasesString(int depth)
{
string res;
res ~= `switch( depth ){`;
for (int i = 0; i depth; ++i)
{
res ~= `case `~ctToString(i)~`:`~
` if( temp`~ indexString(i) ~`.length
Is it possible to do a call like
--
arrayLength!(T[])( temp, index[0..depth] );
//temp is (multi)array being created while parsing an (multi)array in a file
//index[] is an array of the current index
//depth = current depth
--
in stead of
--
switch( depth )
{
case 0:
if( temp.length
I am currently approaching arrays in a absolute manner, like for setting a
value:
---
private template indexAssign(T: T[])
{
void indexAssign(ref T array, BaseType!(T) value, int[] indices)
{
static if( is( typeof(array[0]) == typeof(value)))
{
array[indices[0]] = value;
}
Always nice to see the inner workings, thanks.
Here a few things that bugged me:
Seeing templates as runtime functions, making the whole instantiation thing
kind of strange :)
Trying to use implicitly deduces parameters for function templates.
Writing Foo(d) iso Foo!(int [][])(d).
--
template
template BaseType(T: T[]) { alias BaseType!(T) BaseType; }
template BaseType(T) { alias T BaseType; }
Otherwise, you need indexAssign:
void indexAssign(TArray : TArray[])(TArray array, BaseType!(TArray) value,
int[] indices...)
{
static if (is (typeof (array[0]) == typeof(value))
{
Ever heard of recursion?
Why don't you simply handle all types recursively?
I'm still very interested in what exactly that means. Could you maybe
give a small example?
int Index(T)(T arr, int[] ind)
{
static if(is(T B == B[][])) // if array of array
return
So have I. But we can at least still shout.
Please do
Jarrett Billingsley jarrett.billings...@gmail.com wrote in message
news:mailman.272.1245123167.13405.digitalmars-d-le...@puremagic.com...
On Mon, Jun 15, 2009 at 11:26 PM, downsdefault_357-l...@yahoo.de wrote:
Jarrett Billingsley wrote:
On Mon, Jun 15, 2009 at 10:15 PM, Derek
I can't figure out how to create the IndexArray function,
it should work on arrays of any depth
int[][][] array; //any depth
array.length=10;
array[1].length=3;
array[1][2].length=4;
array[1][2][1]=99;
writefln(array);
//[[],[[],[],[0,99,0,0]],[],[],[],[],[],[],[],[]]
int[3] index; //same
Thanks.
But my problem lays in supporting arrays of arbitrary depth.
For 2 dim array I like auto a=new char[][](40,25); so that
a[39][24]='B'; 'B' is at the bottom right of the 2D array.
IndexArray should take an array of integers as well. The int[] foo...
syntax is implicit convert to array anyway.
I think I'll go with Christophers code, hope you don't mind :)
Also, please bottom-post. It's the convention.
:)
Why is that?
scroll
scroll
I probably use a retarded
Saaa wrote:
I can't figure out how to create the IndexArray function,
it should work on arrays of any depth
BaseType!(TArray) index(TArray : TArray[])(TArray array, int[] indices...)
{
return index(array[indices[0]], indices[1..$]);
}
TElement index(TElement)(TElement element, int
I guess it depends on your style. If you respond to the entire message,
then putting at the top makes sense, because then you can read the
response quickly, and read the history below if you want.
I also switch my way of reply on the type of the reply and often find it
strange people quote
Is this a good way to get the depth of an array?
int getArrayDepth(T)(ref T array)
{
static if( is(T A:A[]) )
{
A arr;
return 1 + getArrayDepth(arr);
}
else
{
return 0;
}
return -1;
}
Any advantage to using two?
I just tend to prefer template specialization when doing type pattern
matching. It works out better than is() in some cases.
Looks very Haskell like :)
He also does : is( T B ==B[]) iso is( T B:B[] )
Any significant difference there?
I'm.. not sure, in this
1 - 100 of 244 matches
Mail list logo