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 :)
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 =
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?
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
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
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;
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`?
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
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
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.
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
It's kind of the right idea, but.. it's also kind of weird.
template ArrayDepth(T: T[]) { const ArrayDepth = 1 + ArrayDepth!(T); }
template ArrayDepth(T) { const ArrayDepth = 0; }
This lets you get the depth of any array _type_, like
ArrayDepth!(int[][]) gives 2.
Although I don't
template BaseType(T: T[]) { const BaseType = BaseType!(T); }
template BaseType(T) {const BaseType = T; }
..
else static if( std2.traits.isNumeric!( BaseType!(T) ) )
{
..
ddata\ddata.d(192): template instance isNumeric!(int) does not match any
template declaration
ddata\ddata.d(192): Error:
Your template. Types are not values, you cannot declare a constant
that is a type. You have to use alias instead:
template BaseType(T: T[]) { alias BaseType!(T) BaseType; }
template BaseType(T) { alias T BaseType; }
Erm, why did this print corretly?
writefln(`BaseType = `,
what is up with this code?
auto t = tuple(1,'a',3.333,false);
pragma(msg,typeof(t.tupleof[2 .. $]).stringof);
spits out
(double, bool, int, char, double, bool)
template Tuple(E...)
{
alias E Tuple;
}
alias Tuple!(1,'a',3.333,false) t;
pragma(msg,typeof(t.tupleof[2 .. $]).stringof);
What kind of fall-throughs were these?
A:
case value1:
case value2:
case valueN:
code1();
break;
B:
case value1:
code1();
case value2:
code2();
break;
The solution is to forbid fallthrough, and change the switch syntax:
switch(value) {
case 1:
case 2:
What's wrong with that?
Doesn't support B :)
How about a warning instead?
The idea is that it not supporting B is something good.
I know this is your idea, but as BCS doesn't support this idea.
You should have replied to him iso grauzone.
I personally never had any problems with falling
How do you know? BCS didn't reply to my idea.
Your idea was to give an error on the case (B) he uses. Or did I miss
something?
You missed the alternative syntax to get the same behaviour. But it's a
very subtle difference.
Do you mean the multiple cases?
http://www.digitalmars.com/d/1.0/statement.html#SwitchStatement
Yes, but make the multiple cases the *only* way to make case
statements fallthrough. That would be the change.
That is the same as giving an error on case B, right?
I mean, the syntax stays the same.
Well, yes, but you also have to prepare your mind for the change. This
is a huge step.
;)
(nah, just kidding, you're right, I didn't realize it :-P)
Ok, enough kidding around, lets get back to you helping me with 'code
generalization' :P
Write a lexer and a parser.
how do you mean?
I just finished my array parser but I can't support just any depth because
each depth needs its own code the way I am doing it now :(
Also, as you can see, I am using a doubling strategy to minimize the amount
of allocations (strating with 4). Is this still a good strategy with D
having a GC?
Christopher Wright dhase...@gmail.com wrote in message
news:h0kagg$13s...@digitalmars.com...
Saaa wrote:
I just finished my array parser but I can't support just any depth
because each depth needs its own code the way I am doing it now :(
Recursion?
static if (is (U A : A[])) will give
meant this:
which of course also fails,
but I hope you get the jist
void setLength (T)( ref T array, int depth , int index[])
{
if(depth 0)
{
depth--;
setLength (array[index[0]], depth, index[1..$]);
}
else
{
if(array.length index[0]) array.length = array.length * 2;
}
}
Looks interesting, but unfortunately it's still useless to me since it
doesn't seem to support arrays of varying depth, nor boolean arrays I
believe.
ps. Isn't this throw statement unreachable? (throw new
Exception(Identifier not found)
erm.. yes.. should have been commented out.
pps.
Saaa wrote:
Is there a function to check whether some string is a legal identifier?
Sure.
static if(is(typeof({ /* code to be checked for validity goes here */ })))
...
That is a compile time check, right?
I meant a runtime check.
How does that piece of code work anyways :D
static
I know use this (in the ddata thread above):
foreach(char c; identifier)
{
if( !inPattern( c, `_a-zA-Z0-9`) )
{
return false;
}
}
That's not correct. http://digitalmars.com/d/1.0/lex.html#identifier
Which is why I asked for it here :)
It isn't extremely important as it is just a
Hello Saaa,
static if(is(typeof({ /* code to be checked for validity goes here */
}))) ...
How does that piece of code work anyways :D
that checks to see if the {...} is a valid delegate literal by using is()
to see if semantic checks fail.
Ah, I see. Can this be done at runtime?
You have to write it yourself. Here's a good starting point:
http://www.digitalmars.com/d/1.0/lex.html#identifier
Yes, that was my starting point and it seemed quite complex, thus my
question :)
I think I'll stay with my simple check for now as it isn't really necessary
to be as strict as
Hello Saaa,
if you are only working with ASCII: use the regex
`_A-Za-z[_A-Za-z0-9]*`
Is that better than the inPattern way?
yes, it correctly rejects numbers at the start and should be faster as
well.
Of course, should have looked longer at the regex line, thanks!
Templated !!
This is the first time I use templates.
please comment
module ddata.ddata;
import std.stdarg;
import std.stdio;
import std.regexp;
import std2.string;
import std2.traits;
import std2.conv;
private char[][] _file;
private char[] _identifier;
private TypeInfo _type;
private int
Is there a function to check whether some string is a legal identifier?
Attached my first attempt to load int and int[] from a D-styled data file.
Adding the functions to support the other types is trivial (hope to be using
templates :)
but supporting an arbitrary deep array isn't that obvious to me yet.
Please comment :)
ps. it uses std2 because of the possible
What did those optlink errors mean again ? :D
--
module ddata.main;
import std2.conv;
void main()
{
}
--
bud -full -cleanup -inline -O
OPTLINK (R) for Win32 Release 8.00.1
Copyright (C) Digital Mars 1989-2004 All rights reserved.
main.obj(main)
Error 42: Symbol Undefined
Nevermind.. this is what happens when you try and place std2 in phobos next
to std :)
What did those optlink errors mean again ? :D
--
module ddata.main;
import std2.conv;
void main()
{
}
--
bud -full -cleanup -inline -O
OPTLINK (R) for Win32 Release 8.00.1
Copyright (C) Digital
I probably should have phrased my question better with the array, what I
was
wondering is if it was safe for say two threads to right to the array at
the same
time as long as I'm sure they're not writing to the same index of the
array?
You can do anything you want without thread
I probably should have phrased my question better with the array, what
I
was
wondering is if it was safe for say two threads to right to the array
at
the same
time as long as I'm sure they're not writing to the same index of the
array?
You can do anything you want without thread
import std.stdarg;
assert( _arguments[0] is typeid(int*) );
auto arg = va_arg!(int*)(_argptr);
*arg = 10;
Probably.
-- Daniel
Calling the following returns an Access Violation Error after
correctly writing the two lines.
void main()
{
int i;
get( file, `i`, i);
}
public void get(in
Georg Wrede georg.wr...@iki.fi wrote in message
news:guc6ep$2im...@digitalmars.com...
Saaa wrote:
Steven Schveighoffer wrote:
i.e. I want thread 1 to initialize elements 0, 1, and 2, and thread 2 to
initialize elements 3, 4, and 5:
thread1 = new ProcessingThread(arrayToInit[0..3
How do I return a variant type in D1?
After assessing that a variadic argument is an array, how do I check its
depth?
How do I set the variable given to me through the _arguments array?
thanks :)
In D1/Phobos, you can use std.boxer.Box, which can work with variadic
arguments.
Ah, I see. boxer saves the typeinfo along the data.
Sorry to ask, but do you have an answer to my other question as well?
Passing variadic arguments as ref I think is what I am asking for :)
1 - 100 of 145 matches
Mail list logo