Re: Static arrays passed by value..?

2010-08-07 Thread Simen kjaeraas
simendsjo wrote: The spec for array says: Static arrays are value types. Unlike in C and D version 1, static arrays are passed to functions by value. Static arrays can also be returned by functions. I don't get the "static arrays are passed to functions by value" part. Here I am passing

Re: Is "is" the same as ptr == ptr for arrays?

2010-08-07 Thread Simen kjaeraas
simendsjo wrote: Ok, thanks. Does this mean this equivalent then? int[] a = [1,2,3]; int[] b = a[0..1]; assert(a !is b); assert(a.ptr == b.ptr && a.length == b.length); Well, no. But what you probably mean, is. ( a is b ) == ( a.ptr == b.ptr && a.length == b.length ) -- Simen

Re: inheriting ctors?

2010-08-05 Thread Simen kjaeraas
dcoder wrote: Suppose I have a base class with many ctors(). I want to inherit from the base class and make one slight alteration to it, but I don't want to write X times the following: this(args) { super(args); } Does D have an easy way for the derived class to 'inherit' all or some

Re: Recursive templated structs disallowed?

2010-08-04 Thread Simen kjaeraas
Steven Schveighoffer wrote: On Wed, 04 Aug 2010 15:37:32 -0400, Simen kjaeraas wrote: struct bar( T ) { auto baz( U )( U arg ) { bar!( typeof( this ) ) tmp; return tmp; } } void main( ) { bar!int n; n.baz( 3 ); } This code fails with Error

Recursive templated structs disallowed?

2010-08-04 Thread Simen kjaeraas
struct bar( T ) { auto baz( U )( U arg ) { bar!( typeof( this ) ) tmp; return tmp; } } void main( ) { bar!int n; n.baz( 3 ); } This code fails with Error: recursive template expansion for template argument bar!(int) Now, I agree it is recursive, but it is not infi

Re: Calling ShellExecute to open a URL in the default browser

2010-08-04 Thread Simen kjaeraas
Daniel Worthington wrote: import std.c.windows.windows; int main(string[] args) { extern (Windows) HINSTANCE ShellExecuteW(HWND, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, INT); HINSTANCE i = ShellExecuteW(null, "open", "http://www.example.com";, null, null, SW_SHOW); return 0; } Err

Re: running pure functions in parallel

2010-08-03 Thread Simen kjaeraas
Justin wrote: I'm designing an application which needs to process a lot of data as quickly as possible. I've found that I can engineer the processing algorithms into pure functions which can operate on different segments of my data. I would like to run these functions in parallel but: sp

Re: Casting an expression to bool means testing for 0 or !=0 for arithmetic types

2010-07-31 Thread Simen kjaeraas
Pluto wrote: == Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article Pluto wrote: > This part has always bothered me. Could somebody please explain to me the > rationale behind limiting functions to one usable error code? Well, traditionally it was done because testing

Re: Casting an expression to bool means testing for 0 or !=0 for arithmetic types

2010-07-31 Thread Simen kjaeraas
Pluto wrote: This part has always bothered me. Could somebody please explain to me the rationale behind limiting functions to one usable error code? Well, traditionally it was done because testing for 0/non-0 is a simple and fast operation. Also, boolean logic can be thought of as simple math

Re: Type literal of pure function pointer

2010-07-25 Thread Simen kjaeraas
On Sun, 25 Jul 2010 01:10:54 +0200, bearophile wrote: In the following D2 the D type system is strong enough to allow foo1() to be pure because sqr() is a pointer to a pure function. In foo2() I have tried to do the same thing avoiding templates, and it works. In foo3() I have tried to w

Re: Single "alias this"

2010-07-25 Thread Simen kjaeraas
Deokjae Lee wrote: Is there any particular reason to disallow multiple "alias this" ? Yes - the fact that it's not yet implemented. (it's on the drawing board , just not quite there yet.) I can implement "multiple" interfaces and extend "single" base class in Java like this: class C exte

Re: Newbie questions on memory allocation

2010-07-24 Thread Simen kjaeraas
bearophile wrote: Deokjae Lee: What's the meaning of the line A? It creates on the stack a 2-word structure, puts unsigned 3 in one word and in the other word puts a pointer to a newly allocated area on the GC-managed heap, that can contain 3 integers (plus one bookkeeping byte), so t

Re: Newbie questions on memory allocation

2010-07-24 Thread Simen kjaeraas
Deokjae Lee wrote: Hi there, I have some questions on the following code. import std.stdio; struct S { int x; } void main() { int[3] a = new int[3];//A S* b = new S();//B delete b;//C } What's the meaning of the line A? Create a static array on the stack, a

Re: Is there a way to create compile-time delegates?

2010-07-21 Thread Simen kjaeraas
Sean Kelly wrote: Don Wrote: Philippe Sigaud wrote: > On Mon, Jul 19, 2010 at 22:01, torhu wrote: > > > > I wasn't able to make it work. > > > Me too :( > > > The compiler probably sees delegates as something that just can't be > created at compile time, since no runtime conte

Re: Detecting a property setter?

2010-07-19 Thread Simen kjaeraas
Rory McGuire wrote: Does anyone know how to detect if there is a setter for a property? The code below prints the same thing for both the setter and the getter of "front": == import std.traits; class Foo { uint num; @property ref uint front() {

Is there a way to create compile-time delegates?

2010-07-19 Thread Simen kjaeraas
Yeah, what the subject says. I want to have a default delegate for a struct, and without a default constructor, this has to be a compile-time constant. Now, logically, there should be nothing wrong with storing the function pointer and a null context pointer at compile-time, but it seems there is

Re: CT usage only in executable

2010-07-16 Thread Simen kjaeraas
Daniel Murphy wrote: Sorry, I don't have D1 installed. Can you use enum to declare manifest constants in D1 or is it a D2 thing? It's a D2 thing. I believe the D1 way to do it is with static const. If the string is left in the executable from const char[] CT_STRING = "blah blah"; void mai

Re: Recommended way to do RAII cleanly

2010-07-12 Thread Simen kjaeraas
Jonathan M Davis wrote: Except that that's two statements and it's no longer RAII. The beauty of doing it entirely in the constructor and destructor is that you only need one statement and the whole thing takes care of itself. With scope, you have to worry about remembering to use scope, an

Re: Grokking concurrency, message passing and Co

2010-07-11 Thread Simen kjaeraas
Philippe Sigaud wrote: - Why is a 2 threads version repeatedly thrice as fast as a no thread version? I thought it'd be only twice as fast. No idea. - 1024 threads are OK, but I cannot reach 2048. Why? What is the limit for the number of spawn I can do? Would that be different if each t

Re: d compiler, Windows 7, and the new iX intel chips.

2010-07-11 Thread Simen kjaeraas
On Sun, 11 Jul 2010 10:49:34 +0200, dcoder wrote: Hello. Probably a stupid question, but does the dmd v2 compiler work with Windows 7, and the new intel chips like the i7? Since the download page on digitalmars references i386 and Win32, I'm assuming it doesn't? I'm thinking about gett

Re: Multi dimensional array question.

2010-07-11 Thread Simen kjaeraas
dcoder wrote: I'm wondering why in D if you declare a fixed multi dimensional array, you have to reverse the index order to access an element. I know it has something to do with how tightly [] bind, but the consequence is that it seems so different to other languages, it makes it error pro

Re: const and immutable

2010-07-06 Thread Simen kjaeraas
Tim Verweij wrote: http://www.digitalmars.com/d/2.0/const3.html includes D examples like: void foo(const int* x, int* y) Is the information on the first page not updated for D2? That seems correct. Is the following correct? (this confuses me) immutable int somefunc(); means the same

Re: Is there a way to get the list of names of a class' member variables?

2010-07-04 Thread Simen kjaeraas
Simen kjaeraas wrote: Jonathan M Davis wrote: MemberFunctionsTuple() from std.traits will return the list of names of member function, and FieldTypeTuple from std.traits will return the list of the _types_ of the member variables. But I don't see a function that returns the list o

Re: Is there a way to get the list of names of a class' member variables?

2010-07-04 Thread Simen kjaeraas
Jonathan M Davis wrote: MemberFunctionsTuple() from std.traits will return the list of names of member function, and FieldTypeTuple from std.traits will return the list of the _types_ of the member variables. But I don't see a function that returns the list of the _names_ of the member var

Re: Structs and CTFE

2010-07-04 Thread Simen kjaeraas
Jonathan M Davis wrote: Is it not presently possible to use structs for enums I believe this is the case, yes. There are ways to do things that are similar, of course: struct E { //Namespace, as D lacks those struct S { this( string phrase, int num ) { this.phrase =

Re: Templates with strings

2010-07-03 Thread Simen kjaeraas
Mike Linford wrote: 2. The reason I don't use CTFE is because I don't know how to be certain its been called at compile time. Apparently using a result in a template like you did will accomplish that, but is there a way I can be sure without making up bogus empty templates? Anything that is s

Re: throwing a RangeError in non-release mode

2010-07-02 Thread Simen kjaeraas
Steven Schveighoffer wrote: When not in release mode, accessing an out-of-bounds element in an array throws a RangeError. I would like to do the same thing in dcollections when indexing, but the only tool I know of that enables throwing an error in non-release mode is assert, and that onl

Re: Is the memory address of classinfo the same for all instances of a class?

2010-07-02 Thread Simen kjaeraas
Heywood Floyd wrote: I noted that the classinfo.name-strings typically looks like this: classtype.Foo classtype.Bar classtype.Cat classtype.Dog Doesn't this first "classtype."-part introduce overhead when these strings are used as keys in an AA? The string co

Re: How to call receiveTimout? (std.concurrency)

2010-06-29 Thread Simen kjaeraas
Simen kjaeraas wrote: Heywood Floyd wrote: ops = ops[1 .. $]; // <=== line 335 Well, this looks like a bug to me. Should be Ops = ops[1 .. $]; Oh, and you could probably make this change yourself. -- Simen

Re: How to call receiveTimout? (std.concurrency)

2010-06-29 Thread Simen kjaeraas
Heywood Floyd wrote: ops = ops[1 .. $]; // <=== line 335 Well, this looks like a bug to me. Should be Ops = ops[1 .. $]; -- Simen

Re: C# Indexers. how to implement them in D.. also property related.

2010-06-29 Thread Simen kjaeraas
BLS wrote: On 29/06/2010 15:27, Steven Schveighoffer wrote: string opIndex(string columnName); yeah this is what I did, too.. However defined as ; interface I1 { string opIndex(string columnName); } is a no go. Hm. That should have worked. So can we say operator overloading within in

Re: How do I make an extern function?

2010-06-29 Thread Simen kjaeraas
BCS wrote: The issue is that the function called from module a is _D1a3fooFZv where the function defined in module b is _D1b3fooFZv ('a' <-> 'b') so they aren't the same function. extern(C) works because C doesn't mangle names so the function is foo in both cases. I know. I just react to

How do I make an extern function?

2010-06-28 Thread Simen kjaeraas
module a; extern void foo( ); void bar( ) { foo( ); } module b; import std.stdio; void foo( ) { writeln( "Hi!" ); } The above does not work (Error 42: Symbol Undefined _D1a3fooFZv). Adding extern to foo in module b changes

Re: @porperty problem..

2010-06-28 Thread Simen kjaeraas
BLS wrote: Hm, this snippet does not compile : class Server { private string _name, _id; @property servername(string name) { _name = name; } @property string servername() { return _name; } } remove string from @property

Re: @porperty problem..

2010-06-28 Thread Simen kjaeraas
BLS wrote: Hi I have a forward reference pb in conjunction with @property. Err msg is : forward refrence to inferred return type of function call s1.servername. any ideas ? No line number? If so, file it in bugzilla. You might also want to file a bug for the forward reference problems. b

Re: A module comprehensive template-specialization

2010-06-27 Thread Simen kjaeraas
Matthias Walter wrote: Can I handle this in another way (like making the template a conditional one)? Template constraints[1] sounds like what you want. Basically, you want the following: == Module a == | module a; | | template Base (T) if (!is(T t : t*)) | { | alias T Base; | } == Modul

Re: Why doesn't this work in D2?

2010-06-27 Thread Simen kjaeraas
Jacob Carlborg wrote: Why doesn't the following code work in D2 (it works in D1)? void foo (T) (in T[] a, T b) { } void main () { "asd".foo('s'); } The error I get is: main.d(10): Error: template main.foo(T) does not match any function template declaration main.d(10): Err

Re: What are delimited string, heredoc and D token strings?

2010-06-27 Thread Simen kjaeraas
Pierre Rouleau wrote: Hi all, The D2.0 lexical page describes delimited string and token string literals. Is there any example of how these are used and why, somewhere? Token strings are added for the specific use case of string mixins[1]. They must contain valid D code. mixin( q{ a = b;

Weird error on nested map

2010-06-27 Thread Simen kjaeraas
auto fn1 = ( string s ) { return s; }; auto fn2 = ( string s ) { return map!fn1( [""] ); }; auto idirs = map!fn2( [""] ); The above code gives the following errors: foo.d(114): Error: struct foo.main.Map!(fn2,string[]).Map inner struct Map cannot be a field foo.d(114): Error: st

Re: std.file bug? std.regex bug?

2010-06-26 Thread Simen kjaeraas
div0 wrote: Not after I changed what was actually the problem - trailing spaces. Still, the error I got gave absolutely no indication that that might be it. Yes it did. It told you exactly what was wrong. Awright, I agree I overstated things there. My point however, was that the error me

Re: std.file bug? std.regex bug?

2010-06-26 Thread Simen kjaeraas
Daniel Murphy wrote: It could be that the string returned from the regex looks the same as the hardcoded string but contains characters that don't show up when you print it. Does adding assert(regexResult == expectedFilename); throw? Not after I changed what was actually the problem - trai

std.file bug? std.regex bug?

2010-06-26 Thread Simen kjaeraas
I have this weirdest bug. I'm extracting a list of files from a file, using std.regex. Then, I try to open each of these, using std.file.readText. This gives me this error: std.file.FileException: In std\file.d(198), data file data: The filename, directory name, or volume label syntax is incorrec

Re: Object removing own last reference.

2010-06-25 Thread Simen kjaeraas
strtr wrote: void externalFunc(){} class C { .. int index_; int yay; void removeMe() { //remove last reference to this object objects[_index] = null; //other critical code memberFunc(); externalFunc(); } void memberFunc(){yay++} } Is there anything unsafe a

Re: alias function this - limitations

2010-06-24 Thread Simen kjaeraas
div0 wrote: I've been having a play and as far as I can tell it looks like aliasing this to a method just doesn't work at all; I think the alias this is being completely ignored. It would seem you're right. Just that assignment made me think it did work. Now why does the assignment work? I

Re: alias function this - limitations

2010-06-24 Thread Simen kjaeraas
div0 wrote: This code fails on the line 'int b = f;'. Is it supposed to? I think so. 'alias this' is used to forward stuff that appears to the right of a dot onto the named member. Not only. Assignment of the wrapped type will also work. In c++ to get what you are doing to work, you'd

alias function this - limitations

2010-06-24 Thread Simen kjaeraas
struct Ref( T ) { T* payload; @property ref T getThis( ) { return *payload; } @property ref T getThis( ref T value ) { payload = &value; return *payload; } alias getThis this; } void bar( ) { Ref!int f; int n; f = n; int b = f; } This code fails on the line 'int b

Re: Class/struct invariants

2010-06-16 Thread Simen kjaeraas
Steven Schveighoffer wrote: During default struct construction, no constructors are run (they aren't allowed anyways) and no invariants are run. What would be the point of running an invariant during default construction? The only think it could possibly do is make code like this: S s;

Re: Minimize lock time

2010-06-10 Thread Simen kjaeraas
Kagamin wrote: Let's consider the following code: synchronized(syncRoot) { if(condition)opSuccess(); else writeln(possibly,slow); } Suppose the else close doesn't need to be executed in lock domain and can be slow. How to minimize lock time here? synchronized(syncRoot) { if(conditio

Re: template specialization

2010-06-08 Thread Simen kjaeraas
Larry Luther wrote: get (T:ubyte)(T[] buffer) get (T:ubyte)(T[] buffer) get (T)(T[] buffer) Q: Is this the way it's supposed to be? Looks very much correct, yes. Is there a problem? -- Simen

Re: Tuple to tuple conversion

2010-06-08 Thread Simen kjaeraas
Lars T. Kyllingstad wrote: That's consistent with my experiences too. It seems to be triggered by a Phobos unittest. Still, I can't reproduce it with your test case. Which DMD version are you using? 2.045. Actually, I can't reproduce it now either. Ah, found the problem. "dmd a b -unittest"

Re: Tuple to tuple conversion

2010-06-08 Thread Simen kjaeraas
Lars T. Kyllingstad wrote: I'm not sure I understand this. Do you then import a and b into another module to reproduce the error? This doesn't do it for me... As the bug report says: "dmd -unittest a b" -- Simen

Re: Tuple to tuple conversion

2010-06-08 Thread Simen kjaeraas
Simen kjaeraas wrote: Lars T. Kyllingstad wrote: FWIW, I've run across the same error, while writing code that had nothing to do with tuples. And I've seen others complaining about it too. It seems to be a rather elusive bug in Phobos. This has now been tracked down to the

Re: Tuple to tuple conversion

2010-06-08 Thread Simen kjaeraas
Lars T. Kyllingstad wrote: FWIW, I've run across the same error, while writing code that had nothing to do with tuples. And I've seen others complaining about it too. It seems to be a rather elusive bug in Phobos. This has now been tracked down to the importing of std.typecons in two includ

Re: Tuple to tuple conversion

2010-06-07 Thread Simen kjaeraas
Simen kjaeraas wrote: I guess what I'm asking for here is, is there a way to do what I want? Hm, it seems the problem was not where I thought it was. However, this is getting curiouser and curiouser. -- Simen

Tuple to tuple conversion

2010-06-07 Thread Simen kjaeraas
Sounds stupid, don't it? 123456789012345678901234567890123456789012345678901234567890123456789012 Carrying in my hat my trusty foo, a std.typecons.Tuple!(float), I want to use it as a parameter to a function taking non-tuple parameters, i.e. a single float. foo.tupleof gives me an unwieldy conglom

Re: Handy templates

2010-06-07 Thread Simen kjaeraas
Simen kjaeraas wrote: Another few that showed up now with my work on combinatorial products of ranges: /** Determines whether a template parameter is a type of value (alias). Example: template foo( T... ) if (allSatisfy!( isAlias, T ) {...} */ template isAlias( alias T

Re: delegates with C linkage

2010-06-06 Thread Simen kjaeraas
dennis luehring wrote: D still won't accept an delegat in an extern C because this type does not exists in the C world Nor do classes, and those certainly can be passed to a C-linkage function. Also, pointers to delegates can be passed to C-linkage functions. A delegate is nothing but a str

Re: delegates with C linkage

2010-06-05 Thread Simen kjaeraas
Mike Parker wrote: For starters, your first delegate is declared in an extern(C) block, meaning it has C linkage. The second is declared outside of the block, meaning it has D linkage. So they are two different types of delegates. If this is correct, the problem should be fixable by writin

Re: D and a bazillion of small objects

2010-06-02 Thread Simen kjaeraas
Yao G. wrote: Thanks bearophile. With respect to passing structs as reference, I also have this problem. In the widget, I have a opIndex method, that returns a ListViewItem given an index (like an array). When opIndex return the instance I'm looking for, and then I modify some property (

Re: Parallel ranges, how?

2010-05-30 Thread Simen kjaeraas
Philippe Sigaud wrote: I don't know if that'd help you, but did you have a look at David Simcha's parallelFuture module? http://cis.jhu.edu/~dsimcha/parallelFuture.html Looked at it now. It's not exactly what I was thinking. parallelFuture foes the foreach in one thread, and work in others,

Re: Parallel ranges, how?

2010-05-30 Thread Simen kjaeraas
Philippe Sigaud wrote: I don't know if that'd help you, but did you have a look at David Simcha's parallelFuture module? http://cis.jhu.edu/~dsimcha/parallelFuture.html Gosh, dsimcha just made a post on it in the Phobos mailing list.Th

Re: Parallel ranges, how?

2010-05-30 Thread Simen kjaeraas
Simen kjaeraas wrote: How does the current range system accommodate parallel iteration? As far as I can see, a context switch could happen between calls to popFront and front, thus popping a value off the range before we're able to get its value. Anyone? It seems to me the system i

Re: noob Q: declaring string variables

2010-05-29 Thread Simen kjaeraas
Duke Normandin wrote: char[] password = "sesame"; didn't work on my MacOS X box. Why? As others have said, in D2, strings are immutable by default, so string password = "sesame"; or immutable(char)[] password = "sesame"; Would be the correct way. [sidebar] Why is every D tutorial I've to

Re: noob Q: array out-of-range

2010-05-29 Thread Simen kjaeraas
Steven Schveighoffer wrote: I wonder if someone recalls the feature set of the dmd compiler from July, 2005. That would be http://ftp.digitalmars.com/dmd.128.zip Tested the example given with that compiler, and got ArrayBoundsError. Just as expected. -- Simen

Re: noob Q: array out-of-range

2010-05-28 Thread Simen kjaeraas
Duke Normandin wrote: So these two paragraphs in the tutorial are flat out wrong? Absolutely. -- Simen

Handy templates

2010-05-26 Thread Simen kjaeraas
Here's a collection of templates I have created and use often. Some of these may be fit for inclusion in Phobos, others maybe not as much. Please critique, and post your own indispensable snippets. /** Checks if one tuple contains another. Example: static assert(Contained!(int).In!(float,

Re: Comparing mixed expression and type tuples. How?

2010-05-26 Thread Simen kjaeraas
bearophile wrote: Looks nice. There are many small bits of functionality like that that are missing still in Phobos and can be added. I suggest you to put that code in a bugzilla entry (otherwise I can do it myself) with a good unittest{} and if you want a ddoc comment too. Done: http://

Re: Comparing mixed expression and type tuples. How?

2010-05-26 Thread Simen kjaeraas
Simen kjaeraas wrote: if ( SameTuple!( int, "a" ).As( int, "a" ) ) {} Now if only someone would fix http://d.puremagic.com/issues/show_bug.cgi?id=242 -- Simen

Re: Comparing mixed expression and type tuples. How?

2010-05-26 Thread Simen kjaeraas
bearophile wrote: Simen kjaeraas Wrote: static assert( is( TypeTuple!( int, "a" ) == TypeTuple!( int, "a" ) ); Look for this problem in the digitalmars.D.learn group, because I have seen this problem recently solved here (I don't remember the solution, it was

Comparing mixed expression and type tuples. How?

2010-05-25 Thread Simen kjaeraas
import std.typetuple; static assert( is( TypeTuple!( int, "a" ) == TypeTuple!( int, "a" ) ); The above code asserts. Is there some other way to compare mixed tuples, or should i roll my own comparison function? -- Simen

Re: enum overloading

2010-05-23 Thread Simen kjaeraas
Ellery Newcomer wrote: I tried telling walter that enums don't and won't suffer from this problem. True. However, treating enums as special for this means another special case in the language. And special cases are bad. -- Simen

Parallel ranges, how?

2010-05-22 Thread Simen kjaeraas
How does the current range system accommodate parallel iteration? As far as I can see, a context switch could happen between calls to popFront and front, thus popping a value off the range before we're able to get its value. -- Simen

Re: Newbie: copy, assignment of class instances

2010-05-20 Thread Simen kjaeraas
bearophile wrote: Generally in D it's not a good idea to reassign the reference to a scoped class You can see it with this little D2 program: import std.stdio: printf; class Foo { int x; this(int xx) { this.x = xx; } ~this() { printf("Foo(%d) destructor\n", this.x); } } void ma

Re: Newbie: copy, assignment of class instances

2010-05-20 Thread Simen kjaeraas
Larry Luther wrote: Given: class A { int x, y; } class B : A { int z; } B foo = new B, bar = new B; scope B alpha = new B; Q1: How do I copy the member variables contributed by base class A from "foo" to "bar"? In C++: (A &) bar = foo; You can'

Re: Questions about syntax decisions

2010-05-19 Thread Simen kjaeraas
F. Almeida wrote: I have a few questions about syntax. 1) Operator overloading First of all, I find the operator overloading weird. This is because I'm used to C++'s syntax "operator+" and "operator+=", for example, instead of "opAdd" and "opAddAssign". While I understand that it gives plenty

Re: Loop optimization

2010-05-15 Thread Simen kjaeraas
Ali Çehreli wrote: Steven Schveighoffer wrote: > double [] foo = new double [cast(int)1e6]; > foo[] = 0; I've discovered that this is the equivalent of the last line above: foo = 0; I don't see it in the spec. Is that an old or an unintended feature? Looks unintended to me.

Re: c function as parameter

2010-05-15 Thread Simen kjaeraas
useo6 wrote: Hello everyone, I'm trying to create a function which awaits a C function as parameter... like this: void myfunction(void C function(uint, void*)) { } But... when I try to compile it, I get the follwing error: "found 'function' when expecting ')'". Does anyone knwo what'

Re: Example in the overview

2010-05-14 Thread Simen kjaeraas
Walter Bright wrote: bearophile wrote: Walter Bright: Are you sure? What's the mistake in the code? This is the code in the Overview, it prints 1899: http://codepad.org/lzRtggEL This is the code I have suggested in bugzilla, it prints 1027: http://ideone.com/D9ZqQ Wolfram Alpha says they

Re: Yet more OPTLINK woes

2010-05-12 Thread Simen kjaeraas
Daniel Keep wrote: That's right, it's time for everyone's favourite [1] game: guess why OPTLINK's not working! [2] [...] Does anyone have any idea, any idea at all, on what could be causing this? I've tried everything myself and several others on #d could think of. Please reduce this to

Re: opAddAssign still works

2010-05-11 Thread Simen kjaeraas
Steven Schveighoffer wrote: But this function never gets called. I found out recently that template functions are not allowed in interfaces, which makes it impossible to use the new operator overloads on interfaces. The problem is however, that template functions can't be virtual, and thu

Re: What's the diff between immutable and const?

2010-04-22 Thread Simen kjaeraas
XCPPCoder wrote: What's the diff between immutable and const? Basically, const means 'I can't change this', while immutable means 'nobody will change this'. The idea is that const is a guarantee given by a function, while immutable is a guarantee for the whole program. Also, immutable opens u

Re: Newsgroups, off-topic

2010-04-18 Thread Simen kjaeraas
Jérôme M. Berger wrote: Actually, gcc doesn't require Walter to give away all rights to his work just to use it as a backend (or else the gdc project wouldn't exist). It would require ceding the rights only if Walter wanted D to be part of the official gcc distribution. You're right,

Re: Newsgroups, off-topic

2010-04-18 Thread Simen kjaeraas
Joseph Wakeling wrote: Maybe true, but I was thinking of it from a different angle -- why the main D2 development does not switch backends. So which do you suggest be used instead - the one that doesn't work on Windows (no exceptions) or the one that requires Walter to give away all rights to

Re: String literal arguments

2010-04-07 Thread Simen kjaeraas
Yao G. wrote: Hello. Greetings. foo( "Hello World", first, second ); --- You can notice that the first argument is a string literal. What I want to know is: If a function argument is declared as a string literal, it can be accessed at compile time? And if the answer is yes, how can I d

Re: Comparing Two Type Tuples

2010-04-04 Thread Simen kjaeraas
Simen kjaeraas wrote: Daniel Ribeiro Maciel wrote: Heya ppl! I was wondering how could I write a function that takes two Type Tuples as arguments and returns true if they are match. Could anyone help me with this? Thanks! This should work, but doesn't (filing a bugzilla about i

Re: Comparing Two Type Tuples

2010-04-04 Thread Simen kjaeraas
Daniel Ribeiro Maciel wrote: Heya ppl! I was wondering how could I write a function that takes two Type Tuples as arguments and returns true if they are match. Could anyone help me with this? Thanks! This should work, but doesn't (filing a bugzilla about it now): template compareTuple( T.

Re: gc

2010-03-28 Thread Simen kjaeraas
sclytrack wrote: gc1thread1 thread2 thread3 gc2thread4 thread5 when the gc1 cycles it does not block the gc2 threads. Would that be of any use? Or possible. And only use communication like between two processes, some interprocess communication message passing t

Re: initializing immutable structs

2010-03-27 Thread Simen kjaeraas
On Fri, 26 Mar 2010 06:35:29 +0100, Paul D. Anderson wrote: I want to initialize an immutable struct but I'm encountering two difficulties and I can't find the answer in the documentation. (Wouldn't it be nice if someone wrote a book?) You mean like this? http://www.amazon.com/dp/032163536

Re: how to get timestamp in compile-time?

2010-03-23 Thread Simen kjaeraas
On Tue, 23 Mar 2010 08:35:54 +0100, Zólyomi Istvan wrote: Hi, recently I've been experimenting with metaprogramming in D. I've been trying to create a simple compiler benchmark that can be used like the following oversimplified code: const time starttime = gettime(); mixin(code); // or

Re: default opAssign(string) behaviour

2010-01-28 Thread Simen kjaeraas
On Thu, 28 Jan 2010 09:02:12 +0100, Simen kjaeraas wrote: On Thu, 28 Jan 2010 02:32:20 +0100, strtr wrote: Personally, I use (D1)std2.conv a lot to get values from strings and thus would love the following default behaviour for all types: int i = "0"; // i = 0 i = cast( int )

Re: default opAssign(string) behaviour

2010-01-28 Thread Simen kjaeraas
On Thu, 28 Jan 2010 02:32:20 +0100, strtr wrote: Personally, I use (D1)std2.conv a lot to get values from strings and thus would love the following default behaviour for all types: int i = "0"; // i = 0 i = cast( int ) "0"; // i = 48 ( If I read the utf8 table correctly ) What keeps this fr

Re: boolean over multiple variables

2010-01-25 Thread Simen kjaeraas
Pelle Månsson wrote: Interesting solution! Very clever! Thank you. I still think opIn_r should be defined for arrays, though. :) Yeah, but currently, 'a in b' means '(∃b[a])', that is, 'is a a valid index in b'. This means having 'a in b' mean '(∃i)( b[i] = a )', that is, 'is there such a

Re: boolean over multiple variables

2010-01-25 Thread Simen kjaeraas
On Mon, 25 Jan 2010 09:59:42 +0100, Pelle Månsson wrote: On 01/23/2010 12:29 AM, strtr wrote: Simen kjaeraas Wrote: Not tested, but they should work: if ( anySame( var, a, b, c, d ) ) { } if ( allSame( var, a, b, c, d ) ) { } A lot prettier. I thought there would be a generic (basic

Re: Confused by struct constructors

2010-01-23 Thread Simen kjaeraas
On Sat, 23 Jan 2010 18:09:26 +0100, Philippe Sigaud wrote: On Sat, Jan 23, 2010 at 14:44, Simen kjaeraas wrote: In attempting to create a function to initialize any array of structs in a simple manner, I created this code: void fillArr( uint n, T, U... )( ref T[] arr, U args ) { arr

Confused by struct constructors

2010-01-23 Thread Simen kjaeraas
In attempting to create a function to initialize any array of structs in a simple manner, I created this code: void fillArr( uint n, T, U... )( ref T[] arr, U args ) { arr[0] = T( U[0..n] ); static if ( U.length > n ) { fillArr!( n )( arr[ 1..$ ], args[ n..$ ] ); } } T[] initArray( T

Re: boolean over multiple variables

2010-01-22 Thread Simen kjaeraas
On Fri, 22 Jan 2010 22:55:45 +0100, strtr wrote: This may be is a very basic question, but is there a way to let me omit a repeating variable when doing multiple boolean operations? if ( var == a || var == b || var == c || var == d) if ( var == (a || b || c || d) ) bool anySame( T, U... )(

Re: Why it doesn't compile in D 2.0?

2010-01-17 Thread Simen kjaeraas
aarti_pl wrote: Well, I don't get it... IMHO .dup makes mutable copy of data (so copy of "test") in mutable area of memory. And it should mean that every pointer points to different area of memory... Am I wrong? You're mostly right. However, this happens at compile time, so the mutable

Re: Find if keys are in two dimensional associative array

2010-01-17 Thread Simen kjaeraas
Michal Minich wrote: This is great! I was thinking such generic template would be good, but I did not have need for it right now. This should be definitely posted to bugzilla as enhancement for Phobos, and also for Tango. Thank you. I have now improved the code to also work for normal arrays

Re: What function am I in?

2010-01-17 Thread Simen kjaeraas
On Sun, 17 Jan 2010 19:42:00 +0100, Tomek Sowiński wrote: Is there a generic way to get the name of the function I'm currently in? Basically I want something working like __FILE__ or __LINE__. Tomek Nope. I believe someone made a template that creates this somehow, though. -- Simen

Re: Find if keys are in two dimensional associative array

2010-01-17 Thread Simen kjaeraas
Michal Minich wrote: Is there more elegant way / built in into D? As far as I know, there is no built-in way. A more general solution than yours can be created with templates, however: template elementTypeOfDepth( T : V[ K ], int depth, V, K ) { static if ( depth == 0 ) { alia

<    1   2   3   4   5   6   >