Re: alias overloading strange error
On Friday, 31 July 2015 at 10:56:33 UTC, vitus wrote: //Why expression 'foobar(1);' doesn't work? void foo()(){} void bar(int){} alias foobar = foo; alias foobar = bar; void main(){ .foobar(1); //OK foobar(1); //Error: overload alias 'foo' is not a variable } foo is a template, while bar is a function. I would have thought the `.foobar(1)` should have failed too... Must be some strange lookup rules I don't know about (or a dmd bug). `alias foobar = foo!();` should make it work in both cases though.
No Unix socket support?
Is there no Unix socket support in Phobos? Or vibe? Or any other library? I've found some discussions: * https://issues.dlang.org/show_bug.cgi?id=9384 * http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/10870/ , but it seems there are no support yet.
Re: GC stats
On Sunday, 26 July 2015 at 14:16:46 UTC, Gary Willoughby wrote: On Saturday, 25 July 2015 at 17:43:44 UTC, Martin Nowak wrote: On Saturday, 25 July 2015 at 17:34:26 UTC, Márcio Martins wrote: What I want is a clean non-intrusive way to log when a collection happened, how long my threads were stopped, how much total memory and how many blocks were recovered. i.e. how much garbage was created in between collections. Are there any hooks on the runtime? http://dlang.org/changelog.html#gc-options https://github.com/D-Programming-Language/druntime/blob/1e25749cd01ad08dc08319a3853fbe86356c3e62/src/rt/config.d#L14 I thought there is a recently added compiler option that profiles the GC and creates a report now? Should be included in 2.068 I think: https://github.com/D-Programming-Language/druntime/blob/1e25749cd01ad08dc08319a3853fbe86356c3e62/src/rt/profilegc.d#L3
Why hide a trusted function as safe?
Is there a reason why you would hide the fact that a function is trusted rather than safe? Technically it doesn't matter, right? To me, it seems like this would give wrong assumptions to the caller. The reason I ask is because I found the following in std.concurrency: @property Tid thisTid() @safe { // TODO: remove when concurrency is safe auto trus = delegate() @trusted { if( thisInfo.ident != Tid.init ) return thisInfo.ident; thisInfo.ident = Tid( new MessageBox ); return thisInfo.ident; }; return trus(); }
std.stdio.tmpfile() return shared(_IO_FILE)* and not File
Using DMD 2.066 on GNU/Linux x86_64. This is strange: import std.stdio; void main() { auto f = tmpfile(); pragma(msg, typeof(f)); // shared(_IO_FILE)* } But stdio.d looks like the following: static File tmpfile() @safe What is going on here?
Re: std.stdio.tmpfile() return shared(_IO_FILE)* and not File
On 08/24/2014 07:56 PM, simendsjo wrote: Using DMD 2.066 on GNU/Linux x86_64. This is strange: import std.stdio; void main() { auto f = tmpfile(); pragma(msg, typeof(f)); // shared(_IO_FILE)* } But stdio.d looks like the following: static File tmpfile() @safe What is going on here? Oh, and ldc 0.14 and gdc 4.9.1 has the same result, so it's not a backend thing at least.
Re: std.stdio.tmpfile() return shared(_IO_FILE)* and not File
On 08/24/2014 08:09 PM, anonymous wrote: On Sunday, 24 August 2014 at 17:55:05 UTC, simendsjo wrote: Using DMD 2.066 on GNU/Linux x86_64. This is strange: import std.stdio; void main() { auto f = tmpfile(); pragma(msg, typeof(f)); // shared(_IO_FILE)* } But stdio.d looks like the following: static File tmpfile() @safe What is going on here? You're calling `core.stdc.stdio.tmpfile`. There is no `std.stdio.tmpfile`, it's `std.stdio.File.tmpfile`. Thanks. So std.stdio.tmpfile() returns shared(_IO_FILE)* and std.stdio.File.tmpfile() returns File. Talk about confusing. If I want something from pure C libraries, I would use core.stdc.
File.tmpfile() cannot be used as a pipe?
I don't know the arguments for my process before reading some of stdin. I was thinking I could solve this by creating a temporary file as a stdin buffer while I found out the correct argument and could launch the process. Unfortunately, this fails. Error: 'object.Exception@std/stdio.d(2070): Enforcement failed'. The enforcment that fails: enforce(f._p f._p.handle); in LockingTextWriters ctor where f is the passed in File. Test code: import std.stdio, std.process; void main() { auto f = File.tmpfile(); f.write(works); auto pid = spawnProcess([echo], f); f.write(fails); }
Re: File.tmpfile() cannot be used as a pipe?
On 08/24/2014 09:03 PM, simendsjo wrote: I don't know the arguments for my process before reading some of stdin. I was thinking I could solve this by creating a temporary file as a stdin buffer while I found out the correct argument and could launch the process. Unfortunately, this fails. Error: 'object.Exception@std/stdio.d(2070): Enforcement failed'. The enforcment that fails: enforce(f._p f._p.handle); in LockingTextWriters ctor where f is the passed in File. Test code: import std.stdio, std.process; void main() { auto f = File.tmpfile(); f.write(works); auto pid = spawnProcess([echo], f); f.write(fails); } Never mind. I just found that I can set up a pipe auto f = pipe() and then use f.readEnd
safe pure unittest
This is the first time I've seen attributes on unittests: https://github.com/D-Programming-Language/phobos/pull/2349/files#diff-ba05e420ac1da65db044e79304d641b6R179 Has this always been supported? I guess it's good practice to add these on unittests too, but does people even know about this feature? And are there any cons to doing this?
Re: safe pure unittest
On 08/13/2014 02:50 PM, Dicebot wrote: On Wednesday, 13 August 2014 at 12:26:02 UTC, simendsjo wrote: This is the first time I've seen attributes on unittests: https://github.com/D-Programming-Language/phobos/pull/2349/files#diff-ba05e420ac1da65db044e79304d641b6R179 Has this always been supported? I guess it's good practice to add these on unittests too, but does people even know about this feature? And are there any cons to doing this? unittest block is effectively just a special function declaration so all function attributes are applicable and act in a similar way. It is an extremely important idiom when you wan't to ensure specific properties of templated function that may be valid or not depending on template arguments. For example, function with output range may be @nogc or not depending if used output range type triggers GC. But you can mark with @nogc unittest that uses it with dummy output range to ensure that _nothing else_ allocated. Thanks. The unittest documentation notes that unittests are functions in one of the sentences, but nothing regarding attributes (except for private) is mentioned: http://dlang.org/unittest.html
Re: Best practices for testing functions that opens files
On 08/06/2014 01:22 AM, splatterdash wrote: Hi all, Is there a recommended way to test functions that opens and iterates over files? The unittest block seems more suited for testing functions whose input and output can be defined in the program itself. I'm wondering if there is a better way to test functions that open files with specific formats. Thanks before :). Split it to several functions: ubyte[] readFile(string file) {...} MyFormat parseData(ubyte[] data) { ... } This way you have very little logic where the files are read, and you can easily unittest your parsing.
Re: monodevelop mono-d versions
On 08/01/2014 03:15 PM, Dicebot wrote: (...) or use /opt/ bundle by simendsjo By Alexander Bothe. The files are just hosted at my domain.
Re: Concatenates int
On 07/10/2014 02:22 PM, Rikki Cattermole wrote: On 11/07/2014 12:11 a.m., Sean Campbell wrote: i have the ints 4, 7, 0 and 1 how can i Concatenate them into four thousand seven hundred and one. If we talking at compile time definition: int myint = 4_7_0_1; Would work. However I'll assume its at runtime you really want this. I.e. converting a string to an integer. int myint = to!int(4 ~ 7 ~ 0 ~ 1); Now they are not strings, and the positions of 10^ doesn't change then: int myint = (1000 * 4) + (100 * 7) + 1; D also has the pow operator, so you can write this as: int i = 4*10^^3 + 7*10^^2 + 0*10^^1 + 1*10^^0;
Re: Insert a char in string
On 07/10/2014 06:05 PM, Alexandre wrote: I have a string X and I need to insert a char in that string... auto X = 100; And I need to inser a ',' in position 3 of this string..., I try to use the array.insertInPlace, but, not work... I try this: auto X = 100; auto N = X.insertInPlace(1,'0'); Do you really want to insert a comma in the string, or do you want to format a number as 100,000,000,000.00?
Re: Insert a char in string
On 07/10/2014 09:58 PM, Alexandre wrote: basically format I read a cobol struct file... From pos X to Y I have a money value... but, this value don't have any format.. 0041415 The 15 is the cents... bascally I need to put the ( comma ), we use comma to separate the cents, here in Brazil... On Thursday, 10 July 2014 at 19:33:15 UTC, simendsjo wrote: On 07/10/2014 06:05 PM, Alexandre wrote: I have a string X and I need to insert a char in that string... auto X = 100; And I need to inser a ',' in position 3 of this string..., I try to use the array.insertInPlace, but, not work... I try this: auto X = 100; auto N = X.insertInPlace(1,'0'); Do you really want to insert a comma in the string, or do you want to format a number as 100,000,000,000.00? I'm not sure what you're trying to do though. Do you need to fix the file by adding a comma at appropriate places? Or read it into D and write it to the console with your currency format? This is one way of reading in the values using slices and std.conv: import std.stdio, std.conv; void main() { immutable input = 0041415; double amount = input[0..$-2].to!double(); amount += input[$-2..$].to!double() / 100; writeln(amount); }
Re: Using enum constant from different modules
On 07/10/2014 10:47 PM, Marc Schütz schue...@gmx.net wrote: On Thursday, 10 July 2014 at 20:27:39 UTC, Jacob Carlborg wrote: Here's a code example: module main; import foo; enum Get = GET; void bar (string a) { assert(a is Get); } void main () { asd(); } module foo; import main; void asd() { bar(Get); } Running the above code will cause an assert error in the function bar. But if I move the function asd into the main module and completely skip the foo module the assert passes. I don't know if I'm thinking completely wrong here but this seems like a bug to me. No, this is equivalent to: void bar (string a) { assert(a is GET); } void asd() { bar(GET); } Enums behave as if their values are copy-n-pasted everywhere they are used (you probably know that). The compiler probably conflates the two identical strings when they're in the same module. This is safe for immutable data. I'm sure there's something in the spec about it... Strings behaves a bit odd with is(). The following passes: import std.stdio; void f(string a, string b) { assert(a is b); // also true } void main() { string a = aoeu; string b = aoeu; assert(a is b); // true f(a, b); writeln(passed); } changing a and b to enum gives the same results.
Re: Using enum constant from different modules
On 07/11/2014 01:08 AM, sigod wrote: On Thursday, 10 July 2014 at 20:59:17 UTC, simendsjo wrote: Strings behaves a bit odd with is(). The following passes: import std.stdio; void f(string a, string b) { assert(a is b); // also true } void main() { string a = aoeu; string b = aoeu; assert(a is b); // true f(a, b); writeln(passed); } ```d import std.stdio; void f(string a, string b) { writeln(a: , a.ptr, , b: , b.ptr); assert(a is b); // also true } void main() { string a = aoeu; string b = aoeu; writeln(a: , a.ptr, , b: , b.ptr); assert(a is b); // true f(a, b); writeln(passed); } ``` Output: ``` a: 4210A0, b: 4210A0 a: 4210A0, b: 4210A0 passed ``` Seems legit to me. I forgot to check for compiler optimizations (even without -O). immutable(int)[] a = [1]; immutable(int)[] b = [1]; assert(a is b); // fails as .ptr is different. So it looks like string literals is cached by the compiler and reused. Changing aoeu to 10.to!string for instance breaks this optimization. But the fact that immutable(char)[] behaves different from immutable(int)[] is a bit strange.
Re: rehabilitating Juno
On 06/21/2014 06:40 AM, Jesse Phillips wrote: On Thursday, 19 June 2014 at 15:24:41 UTC, Jesse Phillips wrote: Once I get some examples compiling again in 32bit, it should be easier for you to play around with COM in D. I've pushed changes which get the library building and examples working. Let me know if there is any other direction I can provide. And if your curious you can check the commit history to see what changes where needed. https://github.com/JesseKPhillips/Juno-Windows-Class-Library This is great. I used Juno back in 2007 for working with Excel, and it worked great. Nice to see the library getting an update for D2. I remember seeing some slides on another COM library for D2 a while ago. Was that effort ever open-sourced?
Re: Basics of calling C from D
On 06/11/2014 03:54 PM, Adam D. Ruppe wrote: On Wednesday, 11 June 2014 at 13:52:09 UTC, belkin wrote: Question: How do I use it from D? Write the prototype in your D file with extern(C): extern(C) int factorial(int n); then just call the function normally in D. Make sure you include all the C object files when you compile the D program too so it all links together. I believe the correct answer should be Buy my book!.
Re: Basics of calling C from D
On 06/11/2014 04:22 PM, Adam D. Ruppe wrote: On Wednesday, 11 June 2014 at 14:11:04 UTC, simendsjo wrote: I believe the correct answer should be Buy my book!. ah, of course! I should just make a .sig file lol http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book chapter 4 talks about this kind of thing :P Yeah, I was skimming through that chapter just minutes before I saw this post :) I must say I really like your writing-style as well as the down-to-earth and precise and concise presentation of the material. So kudos to you! Really looking forward to reading some of the more advanced material as well as seeing your dconf presentation.
Re: Separate Piping of dmd stdout and stderr through ddemangle
On 05/22/2014 11:29 AM, Nordlöw wrote: Is there a Bash way to pipe stdout and stderr *separately* through ddemangle? I'm aware of 21 but this removes separation of stdout and stderr. 21 means redirect file handle 2 to the same as file handle 1. So it will redirect stderr to stdout. I'm not exactly sure what you want to do though, so this might not be the answer you are looking for.
Re: Do equality checks for dynamic arrays attempt to shortcut with pointer comparison
On 04/03/2014 09:03 AM, dnspies wrote: If two dynamic arrays point to the same place in memory, is it fast to compare them for equality? or does every element still have to be compared? Equals will first check for memory location. This is from the runtime: bool opEquals(Object lhs, Object rhs) { // If aliased to the same object or both null = equal if (lhs is rhs) return true; // If either is null = non-equal if (lhs is null || rhs is null) return false; // If same exact type = one call to method opEquals if (typeid(lhs) is typeid(rhs) || typeid(lhs).opEquals(typeid(rhs))) return lhs.opEquals(rhs); // General case = symmetric calls to method opEquals return lhs.opEquals(rhs) rhs.opEquals(lhs); }
Re: Do equality checks for dynamic arrays attempt to shortcut with pointer comparison
On 04/03/2014 09:23 AM, dnspies wrote: On Thursday, 3 April 2014 at 07:16:53 UTC, simendsjo wrote: On 04/03/2014 09:03 AM, dnspies wrote: If two dynamic arrays point to the same place in memory, is it fast to compare them for equality? or does every element still have to be compared? Equals will first check for memory location. This is from the runtime: bool opEquals(Object lhs, Object rhs) { // If aliased to the same object or both null = equal if (lhs is rhs) return true; // If either is null = non-equal if (lhs is null || rhs is null) return false; // If same exact type = one call to method opEquals if (typeid(lhs) is typeid(rhs) || typeid(lhs).opEquals(typeid(rhs))) return lhs.opEquals(rhs); // General case = symmetric calls to method opEquals return lhs.opEquals(rhs) rhs.opEquals(lhs); } But this only applies to objects with a class type. A dynamic array isn't an object with a class type, it's a builtin type. Does it use this opEquals? Can a dynamic array even be cast to an Object? I don't see that lhs is rhs will return true since the array startptr-length pairs may still occupy different places in memory even if the contents of those arrays occupy the same place. If the arrays have different lengths, they are obviously not equal. Here's a quick test of the semantics of is on arrays. auto a = [1, 2]; auto b = a; assert(a is b); b = a[0..$]; assert(a is b); b = a[0..1]; assert(a !is b); assert(a.ptr == b.ptr);
Re: How to find documentation of hard-to-google keywords and symbols
On 04/03/2014 06:31 PM, dnspies wrote: On Thursday, 3 April 2014 at 16:10:45 UTC, bearophile wrote: dnspies: I still don't know where to find documentation for is (which I just found out in another forum post is overloaded for dynamic arrays). Can users overload the meaning of is themselves? Here you find info on the D language: http://dlang.org/spec.html is is an operator, so it's an expression, so you find it here: http://dlang.org/expression Bye, bearophile I don't see where it talks about how to compare dynamic arrays with is. It says: The forms of the IsExpression are: 1.is ( Type ) ... 2.is ( Type : TypeSpecialization ) ... 3.is ( Type == TypeSpecialization ) ... 4.is ( Type Identifier ) ... 5.is ( Type Identifier : TypeSpecialization ) ... 6.is ( Type Identifier == TypeSpecialization ) ... 7.is ( Type : TypeSpecialization , TemplateParameterList ) is ( Type == TypeSpecialization , TemplateParameterList ) is ( Type Identifier : TypeSpecialization , TemplateParameterList ) is ( Type Identifier == TypeSpecialization , TemplateParameterList ) ... This doesn't explain a is b where a and b are both dynamic arrays. `a is b` is called the Identity expressions and is very different from the is expression. http://dlang.org/expression.html#IdentityExpression
Re: How to find documentation of hard-to-google keywords and symbols
On 04/03/2014 06:50 PM, dnspies wrote: On Thursday, 3 April 2014 at 16:39:02 UTC, simendsjo wrote: On 04/03/2014 06:31 PM, dnspies wrote: On Thursday, 3 April 2014 at 16:10:45 UTC, bearophile wrote: dnspies: I still don't know where to find documentation for is (which I just found out in another forum post is overloaded for dynamic arrays). Can users overload the meaning of is themselves? Here you find info on the D language: http://dlang.org/spec.html is is an operator, so it's an expression, so you find it here: http://dlang.org/expression Bye, bearophile I don't see where it talks about how to compare dynamic arrays with is. It says: The forms of the IsExpression are: 1.is ( Type ) ... 2.is ( Type : TypeSpecialization ) ... 3.is ( Type == TypeSpecialization ) ... 4.is ( Type Identifier ) ... 5.is ( Type Identifier : TypeSpecialization ) ... 6.is ( Type Identifier == TypeSpecialization ) ... 7.is ( Type : TypeSpecialization , TemplateParameterList ) is ( Type == TypeSpecialization , TemplateParameterList ) is ( Type Identifier : TypeSpecialization , TemplateParameterList ) is ( Type Identifier == TypeSpecialization , TemplateParameterList ) ... This doesn't explain a is b where a and b are both dynamic arrays. `a is b` is called the Identity expressions and is very different from the is expression. http://dlang.org/expression.html#IdentityExpression Oh sorry. I wouldn't have guessed there would be two different areas of the page dealing with different uses of the is keyword. And it's not something I can search, because just searching the word is isn't much help. What about Tuple. I try to use a Tuple in my code, but get: source/app.d(10): Error: template instance Tuple!(int, int) template 'Tuple' is not defined So I google dlang Tuple to find out which module I can find it in. The first link I get http://dlang.org/tuple.html; has all this great information on how to construct and use tuples... except it fails to mention which module the standard tuple definition is in (anywhere on the entire page). Let's look at the list of D standard modules. Searching the page for tuple reveals std.typetuple which seems promising. Nope, no Tuple objects here... Does no one else see a need for an ALPHABETICAL listing of functions and keywords? In my mind, the problems with navigating the documentation is a HUGE barrier to using D effectively. I can't argue with difficulties finding information. Here's a couple of links that might help: The new layout (with clickable links): http://dlang.org/library/std/typecons/tuple.html Search: http://dpldocs.info/ There's also a search function on the top that uses google. But none of these are as advanced as Find keyword or Find symbol definition as you want.
Re: reflection over templates
On 03/19/2014 05:34 PM, Adam D. Ruppe wrote: On Wednesday, 19 March 2014 at 16:10:52 UTC, Dicebot wrote: Wait just a bit more https://github.com/D-Programming-Language/dmd/pull/3380 :) megarox. Make it so. Nice. I have some ugly hacks that's probably full of bugs for this (look at the bottom): template isLValue(T) { enum isLValue = false; } /// ditto template isLValue(alias T) { enum isLValue = !isType!T isAddressable!T __traits(compiles, { Unqual!(TypeOf!T) t = TypeOf!(T).init; }); } /// ditto template isRValue(T) { enum isRValue = false; } /// ditto template isRValue(alias T) { static if(isType!T) enum isRValue = false; else enum isRValue = __traits(compiles, { typeof(T) t = T; }) !isAddressable!T; } template isValue(T) { enum isValue = false; } /// ditto template isValue(alias T) { enum isValue = isLValue!T || isRValue!T; } /// ditto template isType(T) { enum isType = is(T); } /// ditto template isType(alias T) { enum isType = is(T) || isCallable!T; } template isTemplate(T) { enum isTemplate = !(isValue!T || isType!T); } template isTemplate(alias T) { enum isTemplate = !(isValue!T || isType!T); }
Re: getopt example please
On 02/26/2014 11:06 AM, Tobias Pankrath wrote: On Wednesday, 26 February 2014 at 09:57:19 UTC, Andrew Edwards wrote: Request a small example of how to use getopt to accomplish the following: [1] program subcommand //process subcommand with default arguments if any [2] program -h subcommand //output help information about subcommand [3] program subcommand --option1 --option2 true option3=log.txt // process subcommand with user specified options Thanks, Andrew This is not fully automated with getopt. You could use getopt to parse all non-positional arguments and than parse the rest by hand. -- getopt(args, ...); -- Now, args[1] (or [0]?) should be subcommand. args[0] is the program itself. As Tobias mention, you can check the first subcommand and use a different getopt strategy for each. It's possible to say to getopt that it should not throw an error when it encounters unknown parameters so you can parse them yourself.
Re: Non-Initialized Dynamic Arrays Construction
On 02/24/2014 01:08 PM, Nordlöw wrote: On Monday, 24 February 2014 at 11:29:39 UTC, bearophile wrote: TheFlyingFiddle: http://dlang.org/phobos/std_array.html#.uninitializedArray is what you want. Wouldn't it be nice to have some kind of syntactic sugar for this similar to what we have for static arrays? BTW: Why isn't simply the following allowed? int n = 3; int[n] = void; Is it too easy to confuse with static array syntax? Seems very dangerous. If n is available at compile-time it's a static array, else it's dynamic..?
Re: hiding a class property behind a method
On 02/22/2014 06:21 PM, luka8088 wrote: import std.stdio; class A { string x () { return A; }; } class B : A { override string x () { return B; }; } class C : A { string x = C; // should this be illegal? } void main () { A o1 = new B(); writeln(o1.x); // B A o2 = new C(); writeln(o2.x); // A } Just an addition. The following line shows the problem: writeln((cast(C)o2).x); // C
Re: hiding a class property behind a method
On 02/22/2014 09:43 PM, Ali Çehreli wrote: It looks like name hiding, which I am familiar from C++. Name hiding does not differentiate between functions and variables. Ali The problem is that hiding a name *is* a problem. When you are hiding a name, then a class would no longer behave as you would expect. It breaks LSP in a pretty awful way, and suddenly the *type* of a symbol changes based on what superclass you happened to use for a reference. class A { void f() {} } class B : A { int f; } A b = new B(); writeln(typeof(b.f).stringof); // void() B veryB = cast(B)b; writeln(typeof(veryB.f).stringof); // int Now suddenly, it's very important to use B as the type for a reference. This is very dangerous behavior in my opinion, and I think I've only used it *once* in C# - which requires you to be explicit about it - and I still feel dirty. Now what if a superclass implements a symbol that you are using in a subclass? I say we force it to be explicit as we finally did with `override`, which is shows some of the same issues, although not nearly as dangerous and hidden. I think member hiding is nearly always a bug, and we should be very explicit about it.
Re: hiding a class property behind a method
On 02/22/2014 11:33 PM, Francesco Cattoglio wrote: On Saturday, 22 February 2014 at 17:21:50 UTC, luka8088 wrote: It seems to me that the following code should be illegal, but I am uncertain of it so I am posting here for a confirmation before I post it on bug tracker: [snip] Nice find. I guess we could add this to the list of ugly code caused by calling functions without parenthesis. If parenthesis were not optional, I don't think that the code would behave in such a horrible way, right? The problem isn't about optional parenthesis or properties. It's the fact that you can redefine a symbol to be something entierly different, and that this difference will only be seen if you are looking at the symbol through the correct type. C# also allows has this feature, but you have to state explicitly that you are hiding an existing symbol. D as a safe-by-default language should also require this.
Re: [video tutorial] Defensive programming with Design By Contract basics
On Friday, 21 February 2014 at 09:46:20 UTC, Mengu wrote: On Thursday, 20 February 2014 at 10:28:45 UTC, simendsjo wrote: http://youtu.be/wFqHTCBt72M enjoyed it, thanks! what are you going to talk about next? I only have a rough outline in my head that will probably change as I go: * Split the project in two DUB packages (preparing for web frontend) * Calling the existing CLI app using std.process * Web frontend * Reusable game code - both CLI and web interface use the library rather than web using std.process * Unittesting * DDoc and ddox * Publishing to code.dlang.org
Re: DMD exit code -9
On Wednesday, 19 February 2014 at 22:15:47 UTC, Craig Dillabaugh wrote: (...) I just realized that I tried to build this on my Linode, where DMD tends to choke and die with anything Vibe-d related (basic Linodes have very little RAM). To many terminals open! Same code/build config work fine at my workstation. (...) Just a little heads up in case you begin experiencing the same issues as me. I've also choked my Linode and found out it's better to compile from my desktop. One problem though is that I'm running x86_64 on my desktop and x86 on my Linode. The compiled x86 program crashes on my desktop, but runs fine in my Linode. Took some time before I actually tried running the crashing program on Linode...
[video tutorial] Defensive programming with Design By Contract basics
http://youtu.be/wFqHTCBt72M
Re: [video tutorial] Defensive programming with Design By Contract basics
On Thursday, 20 February 2014 at 14:32:40 UTC, Craig Dillabaugh wrote: On Thursday, 20 February 2014 at 10:28:45 UTC, simendsjo wrote: http://youtu.be/wFqHTCBt72M Thanks for posting these. They are well done. What text editor are you using, emacs? Vim with dcd and syntastic for some D support.
Re: How to resume iteration from previous point in associative array
On Wednesday, 19 February 2014 at 09:21:48 UTC, Tarman wrote: Hi, We're doing some super computing big data style stuff with D. We have a system where we're comparing associative arrays with billions of entries. However in this system we need to fairly consider possible solutions for many units at a time within a single thread. So we'd like to... say, first iterate over the first 10 million for each unit then iterate over the next 10 million for the next unit so that each unit gets a fair share of CPU time. However in this case we can't: int count = 0; foreach (item; associativeArray) { if (++count == 10_000_000) { // here we wish to somehow save the iteration state } } Then on the next iteration: foreach (resume from previous iteration point) { } We've tried copying the keys into a non-associative array and sure this works, but it is far far far less optimal than an equivalent C++ solution we wrote where we use an std::unordered_set and can simply store the iterator. Probably not an answer to your question, but if possible, you can use a fiber and yield when you should give control to another fiber. http://dlang.org/phobos/core_thread.html#.Fiber
[video tutorial] Command line arguments with std.getopt
http://youtu.be/mNQqtauO9IM The entire playlist: http://www.youtube.com/playlist?list=PLqABwcsDQUo59iBOM5DFtqbwrMhL4PWcQ I wont be maintaining the old channel anymore. New videos are uploaded here: http://www.youtube.com/channel/UCz3NlrGpjV9NlJAhKJLu_-w
Re: [video tutorial] Cleaning up our command line argument parsing code
On Wednesday, 19 February 2014 at 21:55:35 UTC, Brad Anderson wrote: On Wednesday, 19 February 2014 at 14:46:57 UTC, simendsjo wrote: Spam spam http://youtu.be/ZRUcTJC0D7M Good stuff. Are you going to upload the older videos to this same channel? Is that necessary? The playlist includes the previous videos too. The only difference is that the analytics is split across several accounts..?
[video tutorial] Refactoring the number guessing game
http://youtu.be/yhK7zvnWmiU
Re: [video tutorial] Implementing a simple number guessing game
On Tuesday, 18 February 2014 at 13:39:38 UTC, John Colvin wrote: On Tuesday, 18 February 2014 at 07:19:05 UTC, simendsjo wrote: On Tuesday, 18 February 2014 at 07:06:11 UTC, Suliman wrote: On Monday, 17 February 2014 at 13:35:34 UTC, simendsjo wrote: http://youtu.be/2Co65Ftxfdo Thanks! But could you use bigger fonts and more contrast color scheme for better view in next videos? I'll increase the font size, but I think 30 lines on the screen would be too big (it's almost there in that video). The contrast is another issue.. I have tweaked urxvt, tmux and vim in order to get these colors. Trying to change just the colorscheme in vim doesn't give the expected results I'm afraid. You could always just alter the contrast/color-balance in the video. I've never done any video editing, so I have no idea how. I tried pressing around on the YouTube enhance video settings, but it looks like an LSD trip no matter what I do.
Re: [video tutorial] Implementing a simple number guessing game
On Tuesday, 18 February 2014 at 13:46:11 UTC, simendsjo wrote: On Tuesday, 18 February 2014 at 13:39:38 UTC, John Colvin wrote: On Tuesday, 18 February 2014 at 07:19:05 UTC, simendsjo wrote: On Tuesday, 18 February 2014 at 07:06:11 UTC, Suliman wrote: On Monday, 17 February 2014 at 13:35:34 UTC, simendsjo wrote: http://youtu.be/2Co65Ftxfdo Thanks! But could you use bigger fonts and more contrast color scheme for better view in next videos? I'll increase the font size, but I think 30 lines on the screen would be too big (it's almost there in that video). The contrast is another issue.. I have tweaked urxvt, tmux and vim in order to get these colors. Trying to change just the colorscheme in vim doesn't give the expected results I'm afraid. You could always just alter the contrast/color-balance in the video. I've never done any video editing, so I have no idea how. I tried pressing around on the YouTube enhance video settings, but it looks like an LSD trip no matter what I do. But is the contrast really that bad? I find my settings easy on the eyes. Clown colors makes me dizzy.
Re: [video tutorial] Refactoring the number guessing game
On Tuesday, 18 February 2014 at 14:16:27 UTC, Rikki Cattermole wrote: On Tuesday, 18 February 2014 at 13:00:09 UTC, simendsjo wrote: http://youtu.be/yhK7zvnWmiU Would you be interested in doing a Lets make series on ApplyYourDLang? As this falls under this heading. Combining efforts is always good, but I'm not sure if creating video tutorials can keep my interest for very long. It also sounds like you have plans to make this a lot more professional: planning content and editing videos. I just press record and upload :/
Re: [video tutorial] Implementing a simple number guessing game
On Tuesday, 18 February 2014 at 14:04:50 UTC, John Colvin wrote: On Tuesday, 18 February 2014 at 13:47:22 UTC, simendsjo wrote: On Tuesday, 18 February 2014 at 13:46:11 UTC, simendsjo wrote: On Tuesday, 18 February 2014 at 13:39:38 UTC, John Colvin wrote: On Tuesday, 18 February 2014 at 07:19:05 UTC, simendsjo wrote: On Tuesday, 18 February 2014 at 07:06:11 UTC, Suliman wrote: On Monday, 17 February 2014 at 13:35:34 UTC, simendsjo wrote: http://youtu.be/2Co65Ftxfdo Thanks! But could you use bigger fonts and more contrast color scheme for better view in next videos? I'll increase the font size, but I think 30 lines on the screen would be too big (it's almost there in that video). The contrast is another issue.. I have tweaked urxvt, tmux and vim in order to get these colors. Trying to change just the colorscheme in vim doesn't give the expected results I'm afraid. You could always just alter the contrast/color-balance in the video. I've never done any video editing, so I have no idea how. I tried pressing around on the YouTube enhance video settings, but it looks like an LSD trip no matter what I do. But is the contrast really that bad? I find my settings easy on the eyes. Clown colors makes me dizzy. It's fine in my opinion, but it's a matter of taste. I'll leave it as-is. If more people complain, I'll google around and try to fix them.
Re: [video tutorial] Refactoring the number guessing game
On Tuesday, 18 February 2014 at 14:20:44 UTC, Rikki Cattermole wrote: On Tuesday, 18 February 2014 at 14:19:47 UTC, simendsjo wrote: On Tuesday, 18 February 2014 at 14:16:27 UTC, Rikki Cattermole wrote: On Tuesday, 18 February 2014 at 13:00:09 UTC, simendsjo wrote: http://youtu.be/yhK7zvnWmiU Would you be interested in doing a Lets make series on ApplyYourDLang? As this falls under this heading. Combining efforts is always good, but I'm not sure if creating video tutorials can keep my interest for very long. It also sounds like you have plans to make this a lot more professional: planning content and editing videos. I just press record and upload :/ Don't worry about that. We can sort out making things higher quality as series goes :) Have you written a plan/schedule for the videos somewhere? And I cannot see a way to move the videos to other users in YouTube.
Re: [video tutorial] Refactoring the number guessing game
On Tuesday, 18 February 2014 at 14:36:17 UTC, simendsjo wrote: On Tuesday, 18 February 2014 at 14:27:19 UTC, Rikki Cattermole wrote: On Tuesday, 18 February 2014 at 14:25:33 UTC, simendsjo wrote: On Tuesday, 18 February 2014 at 14:20:44 UTC, Rikki Cattermole wrote: On Tuesday, 18 February 2014 at 14:19:47 UTC, simendsjo wrote: On Tuesday, 18 February 2014 at 14:16:27 UTC, Rikki Cattermole wrote: On Tuesday, 18 February 2014 at 13:00:09 UTC, simendsjo wrote: http://youtu.be/yhK7zvnWmiU Would you be interested in doing a Lets make series on ApplyYourDLang? As this falls under this heading. Combining efforts is always good, but I'm not sure if creating video tutorials can keep my interest for very long. It also sounds like you have plans to make this a lot more professional: planning content and editing videos. I just press record and upload :/ Don't worry about that. We can sort out making things higher quality as series goes :) Have you written a plan/schedule for the videos somewhere? And I cannot see a way to move the videos to other users in YouTube. I haven't yet made a plan. Its mostly in my head at the current point in time. However we can do something, perhaps on a repo. You don't need to move them. You can add any video to a playlist, given a url. I'll be more than happy to place the videos elsewhere, but I don't want to commit to a large ongoing project as I'm pretty busy with school too. Posting your ideas somewhere would be nice though. I've posted the code so far on bitbucket, but moving to another repo (github?) and changing links in the videos is trivial if you think my videos would fit your playlist - even though they're nothing more than live coding videos :) Oh, and I thought of making perhaps 3 more videos: std.getopt, splitting a project into subprojects with dub, and another vibe.d demo. All just as extensions to the simple number guessing game. We'll see if I ever get this far.
Re: [video tutorial] Refactoring the number guessing game
On Tuesday, 18 February 2014 at 14:42:22 UTC, Rikki Cattermole wrote: On Tuesday, 18 February 2014 at 14:36:17 UTC, simendsjo wrote: I'll be more than happy to place the videos elsewhere, but I don't want to commit to a large ongoing project as I'm pretty busy with school too. Posting your ideas somewhere would be nice though. What I was thinking was, for a smaller set of projects grouped together. In one series. This way you're not committed. I've posted the code so far on bitbucket, but moving to another repo (github?) and changing links in the videos is trivial if you think my videos would fit your playlist - even though they're nothing more than live coding videos :) Seeing how others develop while learning is a very important thing while learning. So yes it very much fits. I've sent you an invite to manage it. You'll be able to do e.g. upload video or add playlists ext. As well as work on the Google+ page [0]. [0] https://plus.google.com/u/0/b/115883286620259563734/ Not sure I'm able to connect.. When pressing the link, it turns up for my G+ user. If I log in as the YouTube user and go to that link, I still turn up as the G+ user. Why on earth won't Google let me merge the accounts?...
Re: [video tutorial] Refactoring the number guessing game
On Tuesday, 18 February 2014 at 14:51:28 UTC, Rikki Cattermole wrote: On Tuesday, 18 February 2014 at 14:48:53 UTC, simendsjo wrote: Not sure I'm able to connect.. When pressing the link, it turns up for my G+ user. If I log in as the YouTube user and go to that link, I still turn up as the G+ user. Why on earth won't Google let me merge the accounts?... I don't know. But you do need to accept the manager invite. I sent it to the one you subscribed to the channel as. From there you can switch to it if you want. Ah, I'm in. You'll have to dictate what to do next. Maybe we should continue this by mail? My gmail is simendsjo.
Re: What learning resources are available?
On Tuesday, 18 February 2014 at 19:17:55 UTC, Mark Isaacson wrote: Hi everyone - I'm a D newbie with a very strong C++ background looking to get started. I've read The D Programming Language a couple of times now, but I've heard rumblings at several points in time from several people that some if its contents are now out of date or no longer reflect best practices. What would be the best way to bridge the learning gap between TDPL's publication and now? What other resources would be most useful in establishing a working knowledge of idiomatic D? What's the best way to stay informed about such changes in the future? (Is there a mailing list, or should I just be reading dmd changelogs?) Thanks in advance! I can just speak for myself, but I've been learning D by following the newsgroups and reading the phobos and druntime code. Not sure if there are quicker ways to get up to date.
Re: Timer
On Monday, 17 February 2014 at 11:20:05 UTC, Chris wrote: On Monday, 17 February 2014 at 11:11:06 UTC, simendsjo wrote: On Monday, 17 February 2014 at 11:08:16 UTC, Chris wrote: The D way of implementing a timer? I need to (automatically) execute a function that performs a clean up, say every hour. if (file.older than 1 hour) { remove; } Vibe.d can be used for this to get an OS agnostic solution. Haven't used it myself, but this function seems to be what you are looking for: https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/core/core.d#L342 Great, it's for a vibe.d project anyway, it might do the trick. Out of interest, if there's a phobos way, let me know. You could have a separate thread used just for this that sleeps most of the time.
[video tutorial] Implementing a simple number guessing game
http://youtu.be/2Co65Ftxfdo
Re: [video tutorial] Implementing a simple number guessing game
On Monday, 17 February 2014 at 13:42:28 UTC, Dicebot wrote: On Monday, 17 February 2014 at 13:35:34 UTC, simendsjo wrote: http://youtu.be/2Co65Ftxfdo Slightly OT: hm, does D have own YouTube community channel? I'd subscribe to one ;) I don't think so. The closest is Andrei Alexandrescus account posting videos from the previous conference. Found this one too: http://www.youtube.com/playlist?list=PL4EvMyUrlAJmEfs8l6oW2BlnALiDu7kGy
Re: [video tutorial] Implementing a simple number guessing game
On Monday, 17 February 2014 at 14:00:06 UTC, Rikki Cattermole wrote: On Monday, 17 February 2014 at 13:42:28 UTC, Dicebot wrote: On Monday, 17 February 2014 at 13:35:34 UTC, simendsjo wrote: http://youtu.be/2Co65Ftxfdo Slightly OT: hm, does D have own YouTube community channel? I'd subscribe to one ;) I'm working towards a channel specifically [0]. It will house two types of series of videos. Firstly Lets learn, basically learning D. Secondly Lets make, as you can guess its about applying D in some format. I'll mention that the Lets learn type will be pretty much limited to one file and executable on dpaste. However its slow going as I'm learning blender to act as a very fancy video editor. If anybody is interested in contributing to this, I'll be happy to add you as a manager. [0] http://www.youtube.com/channel/UCz3NlrGpjV9NlJAhKJLu_-w Sounds good, but I think a common channel for everything D would be a better move. A dlang channel that includes every talk, tutorial etc. I don't know much of how YouTube works, so I don't know if such an aggregated channel is possible. If it is, someone should create it and gather all YouTube videos.
Re: foreach/iota countdown
On Monday, 17 February 2014 at 19:30:38 UTC, Timon Gehr wrote: On 02/17/2014 08:22 PM, simendsjo wrote: Should the following two uses be a compile-time error? foreach(i; 10 .. 0) // Never executes foreach(i; iota(10, 0)) // .. neither does this I would like the second to either be a compile-time error or automagically use a negative step. So we need to use a negative step in iota() or use a for loop foreach(i; iota(10, 0, -1)) // as expected The parameters can be runtime values. Auto-magically using a negative step would hence be a bad idea. Why would it be a bad idea? And I don't see where the runtime aspect comes in. There would be a very small setup performance hit when using runtime variables for choosing the step direction.
foreach/iota countdown
Should the following two uses be a compile-time error? foreach(i; 10 .. 0) // Never executes foreach(i; iota(10, 0)) // .. neither does this I would like the second to either be a compile-time error or automagically use a negative step. So we need to use a negative step in iota() or use a for loop foreach(i; iota(10, 0, -1)) // as expected
Re: foreach/iota countdown
On Monday, 17 February 2014 at 20:03:32 UTC, Timon Gehr wrote: On 02/17/2014 08:33 PM, simendsjo wrote: On Monday, 17 February 2014 at 19:30:38 UTC, Timon Gehr wrote: On 02/17/2014 08:22 PM, simendsjo wrote: Should the following two uses be a compile-time error? foreach(i; 10 .. 0) // Never executes foreach(i; iota(10, 0)) // .. neither does this I would like the second to either be a compile-time error or automagically use a negative step. So we need to use a negative step in iota() or use a for loop foreach(i; iota(10, 0, -1)) // as expected The parameters can be runtime values. Auto-magically using a negative step would hence be a bad idea. Why would it be a bad idea? The step direction shouldn't randomly change. I wouldn't call it randomly. In that case you should call it randomly that it suddenly doesn't run once you try to step downward. And I don't see where the runtime aspect comes in. It was just to illustrate the issue more clearly. Eg. it means one and the same iota expression can sometimes iterate in one direction and in the other direction at other times. That's simply not useful behaviour. I'm not sure what I find more confusing. Ok if it's a deliberate choice never to change the step direction, but is it deliberate that it's not an error to have a greater lower bound than upper bound? Or is this just the way it happened to be implemented?
Re: foreach/iota countdown
On Monday, 17 February 2014 at 21:06:50 UTC, Timon Gehr wrote: On 02/17/2014 09:21 PM, simendsjo wrote: On Monday, 17 February 2014 at 20:03:32 UTC, Timon Gehr wrote: ... It was just to illustrate the issue more clearly. Eg. it means one and the same iota expression can sometimes iterate in one direction and in the other direction at other times. That's simply not useful behaviour. I'm not sure what I find more confusing. Ok if it's a deliberate choice never to change the step direction, but is it deliberate that it's not an error to have a greater lower bound than upper bound? Or is this just the way it happened to be implemented? That's deliberate. I don't really understand how it is confusing. To draw an analogy, given (low ∈ ℕ) and (high ∈ ℕ), { x ∈ ℕ | low ≤ x ∧ x high } is just the empty set if low high. It is not illegal or unusual. Ok, I yield. I just happened to write foreach(i; 10 .. 0) and was suprised that it didn't give any warnings or errors. But I still somewhat stand by my point: Dead code is illegal in D, and this is code that will never run, hence dead code.
Re: [video tutorial] Implementing a simple number guessing game
On Tuesday, 18 February 2014 at 07:06:11 UTC, Suliman wrote: On Monday, 17 February 2014 at 13:35:34 UTC, simendsjo wrote: http://youtu.be/2Co65Ftxfdo Thanks! But could you use bigger fonts and more contrast color scheme for better view in next videos? I'll increase the font size, but I think 30 lines on the screen would be too big (it's almost there in that video). The contrast is another issue.. I have tweaked urxvt, tmux and vim in order to get these colors. Trying to change just the colorscheme in vim doesn't give the expected results I'm afraid.
Re: [video tutorial] hello world using dmd, rdmd, dub and vibe.d
On Sunday, 16 February 2014 at 22:57:44 UTC, Brad Anderson wrote: (...) Nicely done. It's a bit quiet (I had to max out my volume and put on headphones to hear). Thanks. I'll crank up the volume for the next one.
[video tutorial] hello world using dmd, rdmd, dub and vibe.d
http://youtu.be/8TV9ZZteYEU The content wasn't planned, and English is not my native tongue. Hopefully it can still be useful for newbies. This is pretty much a response to a recent discussion on the lack of documentation/tutorials: http://forum.dlang.org/post/spdddifmaacihlcum...@forum.dlang.org PS: The many delays are X going black, forcing me to switch to a different terminal and back again.
Re: [video tutorial] hello world using dmd, rdmd, dub and vibe.d
On Saturday, 15 February 2014 at 15:33:55 UTC, Jakob Lundberg wrote: Nice video! It was very good. Is there any chance that you would be willing to share your Vim configuration? In particular the integration with DCD. let g:dcd_importPath=['/home/simendsjo/.dub/packages/vibe-d-master/source', '/home/simendsjo/.dub/packages/ncurses-master', '/usr/include/dlang/dmd', '/usr/include/dlang/dmd/druntime/import'] au BufNewFile,BufRead,BufEnter *.d set omnifunc=dcomplete#Complete autocmd Filetype jade call SetJadeFTOptions() function SetJadeFTOptions() setlocal ts=2 setlocal shiftwidth=2 setlocal softtabstop=2 endfunction vibe.d diet tamplates are pretty much jade files autocmd BufNewFile,BufReadPost *.dt set filetype=jade
Re: [video tutorial] hello world using dmd, rdmd, dub and vibe.d
On Saturday, 15 February 2014 at 15:35:41 UTC, simendsjo wrote: On Saturday, 15 February 2014 at 15:33:55 UTC, Jakob Lundberg wrote: Nice video! It was very good. Is there any chance that you would be willing to share your Vim configuration? In particular the integration with DCD. let (...) Oh, and I'm using pathogen and have a symlink in my bundle folder to the DCD/editors/vim folder. DCD includes more than what is available in the vim plugin, but I don't know enough vimscript to make pulls to update it.
Re: [video tutorial] hello world using dmd, rdmd, dub and vibe.d
On Saturday, 15 February 2014 at 15:46:26 UTC, Rikki Cattermole wrote: On Saturday, 15 February 2014 at 13:28:24 UTC, simendsjo wrote: http://youtu.be/8TV9ZZteYEU The content wasn't planned, and English is not my native tongue. Hopefully it can still be useful for newbies. This is pretty much a response to a recent discussion on the lack of documentation/tutorials: http://forum.dlang.org/post/spdddifmaacihlcum...@forum.dlang.org PS: The many delays are X going black, forcing me to switch to a different terminal and back again. Looks quite a bit better then my one that I have unlisted currently[0]. Actually goes through some development :) Although my plan was to make a bunch before saying anything (hasn't happened). [0] http://www.youtube.com/watch?v=yGf6VjlP96I I also thought I should make a plan and do-the-right-thing, but then I just thought what the hell. I probably won't be making many screencasts as I don't have any interest or incentive to do so, so a quick and dirty approach is better than nothing :) This video just took me ~30 minutes to make, where 24 is actually recording time and the rest is upload time. But a well planned series of tutorials would be a very nice to have. You probably shouldn't keep it unlisted though. Just make it public, and feedback will probably drive you to keep making more :) I just watched your video, and it goes into more details than what I did (it's also good to have an English speaker doing videos rather than my Norwenglish :)). The fact that you're using Windows is also important to reach a wider audience. I'll say just publish it! (and the rest of what you might have prepared)
Re: [video tutorial] hello world using dmd, rdmd, dub and vibe.d
On Saturday, 15 February 2014 at 15:39:51 UTC, Stanislav Blinov wrote: On Saturday, 15 February 2014 at 13:28:24 UTC, simendsjo wrote: http://youtu.be/8TV9ZZteYEU Concise and informative. Maybe a little rushed for total newcomers, but for people familiar with programming and wanting to jump into D - very well done! Yeah.. I didn't mean it to be applicable for inexperienced programmers, but I probably gave too little context for anyone brand new to the language. Hopefully someone else can fill the gaps :)
Re: Higher Order Type Tuple Predicate
On Thursday, 13 February 2014 at 11:25:09 UTC, Nordlöw wrote: Is there some trait in Phobos to check if each element of a type tuple fulfil a type predicate? I want this in a variadic function limiter to assert that all its arguments function fulfils a predicate. Something like: void f(T...)(T args) if (All!(T,SomePredicate)) { ... } You probably need std.typetuple: http://dlang.org/phobos/std_typetuple.html#.allSatisfy
Re: Thrift maintained..?
On Wednesday, 12 February 2014 at 02:27:51 UTC, David Eagen wrote: On Wednesday, 25 December 2013 at 17:14:17 UTC, David Eagen wrote: I've filed a bug: https://issues.apache.org/jira/browse/THRIFT-2294 So the Thrift guys are not too excited about fixing this. The bug was closed since it affected just the D library. Well, that seems quite unprofessional.. Not fixing bugs that makes parts of their repository unusable..
Re: Array as an argument, ambiguous behaviour.
On Wednesday, 29 January 2014 at 11:46:23 UTC, Cooler wrote: Thank you for detailed explanation. But the question is - Is that correct that language allows ambiguous behavior? Could you expand your example? fun(int[] a) {} is passing a by value, that is, the pointer and length is copied over to fun. Any changes to the elements of a will be visible, but if you reassign a directly or indirectly (expanding it so it needs to be copied to a new memory location), the changes are not visible.
Re: Array as an argument, ambiguous behaviour.
On Wednesday, 29 January 2014 at 13:15:30 UTC, Cooler wrote: On Wednesday, 29 January 2014 at 12:40:00 UTC, Tobias Pankrath wrote: On Wednesday, 29 January 2014 at 11:46:23 UTC, Cooler wrote: Thank you for detailed explanation. But the question is - Is that correct that language allows ambiguous behavior? Where is it ambiguous? Ambiguity is here... When I call fun1() or fun2() I know the behavior directly from function signature (read the comments in my first post). For fun3() case the caller side don't know the behavior directly from function signature. To know what will happen with array a, the caller must see to fun3() body. Ambiguity is - in first and second cases the caller knows what happens with a, but in third case the caller does not know what happens with a. 'in' is a shorthard for 'const scope'. 'const' means that the callee cannot change the passed in parameter in any way, including anything available through that type (for example x[0]) 'scope' means it cannot leave the scope of the callee - that it cannot be stored away anywhere. 'ref' means that the parameter is passed by reference, and thus might be reassigned or changed in any way. No parameters means that it's mutable, but the reference cannot change. I don't see any ambiguities here.
Re: How to skip permission denied exceptions if iterate through directories?
On Friday, 24 January 2014 at 23:46:04 UTC, Clas Onnebrink wrote: (...) I want work through a directory on my linux server but there are some directories I have no permissions to access so I get following: ~/Projects/cltools/smdups $ source/smdups -r -p=/media/clas/Elements2 -e=*.* std.file.FileException@../../../../src/libphobos/src/std/file.d(2353): /media/clas/Elements2/lost+found: Permission denied /home/clas/Projects/cltools/smdups/source/smdups() [0x43cb1d] /home/clas/Projects/cltools/smdups/source/smdups() [0x43eab4] /home/clas/Projects/cltools/smdups/source/smdups() [0x404768] /home/clas/Projects/cltools/smdups/source/smdups() [0x404116] /home/clas/Projects/cltools/smdups/source/smdups() [0x404d2d] /home/clas/Projects/cltools/smdups/source/smdups() [0x41a71f] /home/clas/Projects/cltools/smdups/source/smdups() [0x41ae7f] /home/clas/Projects/cltools/smdups/source/smdups() [0x41b0b0] /home/clas/Projects/cltools/smdups/source/smdups() [0x41ae7f] /home/clas/Projects/cltools/smdups/source/smdups() [0x41b018] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f66a29c8de5] /home/clas/Projects/cltools/smdups/source/smdups() [0x403e63] ~/Projects/cltools/smdups $ std.file.FileException@../../../../src/libphobos/src/std/file.d(2353): /media/clas/Elements2/lost+found: Permission denied std.file.FileException@../../../../src/libphobos/src/std/file.d(2353):: command not found My question: How to skip any exceptions in dirEntries. I tried it with filter. But no chance. Is there a way to do it like in C# with LINQ-Expressions? greets clas This seems more difficult than i thought. Catching the exception doesn't help as there is no way to skip the item in question. The exception is being fired on popFront(), but I think the correct way would be to fire the exception on calling front() instead so you're able to skip to the next item. import std.file, std.stdio; void main() { auto dit = dirEntries(/tmp, SpanMode.breadth, true); while(!dit.empty) { try dit.popFront(); // Fill front() catch(Exception ex) { writeln(OOPS: , ex); // We should be able to skip the file here } /* do something with dit.front */ } }
Re: Circular Buffer
On Friday, 20 December 2013 at 15:45:04 UTC, Frustrated wrote: I'm in need of a circular buffer/array. I am using std.container.array to avoid the GC. I suppose I could copy and modify the code but is there any easier way? It looks like it is defined as templates so could I somehow hijack the code and modify only what is needed rather than duplicate a lot of stuff? (or maybe someone could just add it to the library... circular arrays are useful ya know ;) Writing your own should be quite simple. I see others have already added some implementations, so I'll add mine too. Modifying it to use a static array shouldn't be too difficult, but you're probably better off using some of the others code as this is dynamic and haven't been used in production. https://gist.github.com/simendsjo/3b8a9c60bd92e16691d7
Red-Black tree storing color without additional memory requirements
Wikipedia states that the color bit can be stored without taking additional space: In many cases the additional bit of information can be stored at no additional memory cost. Looking at the Phobos implementation, it stores it as a regular byte: https://github.com/D-Programming-Language/phobos/blob/master/std/container.d#L4945 The only way I can see it storing a bit without taking additional space is by storing the color in the pointer to a node instead of in the node by using the tagged pointer trick: http://en.wikipedia.org/wiki/Pointer_tagging But I would think this trick would break the GC, as well as making code less portable. So.. Is the RBTree article a bit off here, or are there other techniques to reduce memory overhead?
Re: D game engine -- Any suggestions?
On Wednesday, 20 November 2013 at 07:48:21 UTC, Mineko wrote: (...) ..That and if I'm using the GPL right. _ Do you really plan on using 677 lines per file on the license header..?
Thrift maintained..?
I thrid compiling thrift 0.9.1 from github with d support, but there's a bug in the makefile it seems. $(addprefix.log: $(addprefix @p='$(addprefix'; \ b='$(addprefix'; \ $(am__check_pre) $(LOG_DRIVER) --test-name $$f \ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ $$tst $(AM_TESTS_FD_REDIRECT) The error is reported at the first line with the message: Makefile:1206: *** unterminated variable reference. Stop. Can anyone spot the error? (And preferably send a pull request so I don't take the credit :) )
Re: balancedParens is not nothrow bug, is this known?
On Friday, 8 November 2013 at 14:07:38 UTC, Gary Willoughby wrote: import std.path; void main(string[] args) { globMatch(foo.bar, *); } compile with: dmd -profile test.d Error: /usr/share/dmd/src/phobos/std/path.d(2187): Error: balancedParens is not nothrow /usr/share/dmd/src/phobos/std/path.d(2188): Error: balancedParens is not nothrow a). Is this bug known? b). Is this fixed in the latest release, i'm using 2.063.2. Can it be nothrow? It might encounter unicode exceptions.
Re: Limiting template functions to template instantiations of a struct
On Thursday, 7 November 2013 at 15:46:53 UTC, Marco Leise wrote: Am Wed, 06 Nov 2013 14:22:13 +0100 schrieb simendsjo simend...@gmail.com: template isFoo(T) { static if(is(T:Foo!U, int U)) enum isFoo = true; else enum isFoo = false; } enum isFoo(T) = is(T:Foo!U, int U); correct ? I haven't tried 2.064 yet, but that should be correct. I'll be able to shave away a whole lot of useless lines because of this. And the strange thing is that I didn't even know about this enhancement before reading the changelog.
Re: Limiting template functions to template instantiations of a struct
On Wednesday, 6 November 2013 at 13:00:17 UTC, Atila Neves wrote: The title isn't very clear but I wasn't sure how to phrase it without code. Basically what I want to do is this (won't compile): struct Foo(int N) { } void func(T)(T obj) if(is(T:Foo)) { } void func(T)(T obj) if(!is(T:Foo)) { } Foo by itself isn't a type, but I don't want to limit func instantiation in the 1st case to just e.g. Foo!3 but to _any_ Foo regardless of N. I came up with two workarouds: make Foo a class that derives from an empty FooBase (then is(T:FooBase) works), or adding a secret enum within Foo that I can check with std.traits.hasMember in a static if. I don't really like either of them. Is what I want to do possible? Atila Here's a couple of different ways to do this. import std.stdio; struct Foo(int N) { } void func(T)(T obj) if(is(T:Foo!U, int U)) { writeln(It's a Foo!); } void func(T)(T obj) if(!is(T:Foo!U, int U)) { writeln(No Foo :(); } template isFoo(T) { static if(is(T:Foo!U, int U)) enum isFoo = true; else enum isFoo = false; } void gunc(T)(T obj) if(isFoo!T) { writeln(Gunc isFoo); } void gunc(T)(T obj) if(!isFoo!T) { writeln(Gunc !isFoo); } void hunk(T)(T obj) { static if(isFoo!T) writeln(Hunk!); else writeln(No hunk!); } void main() { Foo!3 f; func(f); // It's a Foo! struct S {} S s; func(s); // No Foo :( gunc(f); // Gunc isFoo gunc(s); // Gunc !isFoo hunk(f); // Hunk! hunk(s); // No hunk! }
Re: How to iterate using foreach on a class?
On Friday, 1 November 2013 at 11:30:12 UTC, Gary Willoughby wrote: I have a class which contains an array as a core collection of data. I want to pass an instance of this class to a foreach loop and iterate through the enclosed array. How do i do this? I've asked this before and got an answer but i can't find anything now. alias this on the underlying array, or implement opApply: http://dlang.org/statement.html
Re: How to iterate using foreach on a class?
On Friday, 1 November 2013 at 11:41:52 UTC, Jonathan M Davis wrote: On Friday, November 01, 2013 12:30:10 Gary Willoughby wrote: I have a class which contains an array as a core collection of data. I want to pass an instance of this class to a foreach loop and iterate through the enclosed array. How do i do this? I've asked this before and got an answer but i can't find anything now. In general, if you want to make something work with foreach, you either make it a range, or you give it an opSlice which returns a range (another alternative would be define opApply, but in general, code should be using the range primitives rather than opApply). Given that you're looking to iterate an array, and you presumably don't want the array to be consumed when iterating, the simplest would be to simply declare an opSlice on the class returns the array. e.g. class C { int[] foo; auto opSlice() { return foo; } } Then when you use the class in a foreach loop, it'll be sliced, and the return value of opSlice (the array in this case) will then be iterated over. - Jonathan M Davis So we basically have 4 ways..? 1) popFront + front 2) opSlice 3) alias this 4) opApply
Re: Sql - Any tuto ?
On Friday, 25 October 2013 at 08:07:02 UTC, Gary Willoughby wrote: On Saturday, 10 August 2013 at 18:28:31 UTC, H. S. Teoh wrote: In that case, it should be written like this: ... command.prepare(); scope(exit) command.releaseStatement(); ulong rowsAffected; foreach ... This is exactly the kind of situation scope guards are designed for. So use them! :-) T It's sometimes not that simple if you are within try/catch blocks or re-using the command for other queries. Just a side-note: In the current version, the parameter packet is rebuilt on each request, so some of the advantages of reusing the statement might be lost if you only rebind a couple of the parameters. https://github.com/rejectedsoftware/mysql-native/blob/master/source/mysql/connection.d#L4169 In my rewrite, I'm modifying the packet in-place, so it might be more performant. https://github.com/simendsjo/mysqln/blob/master/source/mysql/protocol/packets.d#L782
Re: selectively running unittest functions
On Friday, 25 October 2013 at 14:14:39 UTC, Dicebot wrote: This will work starting with 2.064: module a; import std.stdio; struct ID { string data; } @ID(one) unittest { writeln(1); } @ID(two) unittest { writeln(2); } void main() { import std.typetuple; alias tests = TypeTuple!( __traits(getUnitTests, a) ); foreach (test; tests) { foreach (uda; __traits(getAttributes, test)) { static if (is(typeof(uda) == ID)) { if (uda == ID(two)) test(); } } } } It will print stuff twice though because I didn't suppress native unittest runner. Didn't actually dwell deep into runtime hooks so don't know what is best way to do it (maybe we need one more enhancement for it) This is great. I love the unittest blocks and UDAs. This way I can still have very easy-entry (as in just write unittest {}) unittests while gaining the power of unittest frameworks. It's a hell of a lot better than having some class with attributes containing methods with attributes, containing parameters with attributes :) I'm developing RSI when writing tests in other languages. (In Java I develop RSI just declaring variables...)
Re: running a command in a directory using std.process
On Thursday, 24 October 2013 at 06:25:40 UTC, Benjamin Thaut wrote: As far as I can tell std.process can only run commands in the working directory of the currently executing function. I want to execute a certain program inside a subdirectory on windows and can't get it to work: myproject |- subdir So my executable has myproject as working directory. And I want to execute dmd with subdir as working directory. Isn't it possible to execute a command like cd subdir dmd?
Templates with alias param instantiated with null cached by DMD..?
I've stumbled upon a strange bug, and I'm not sure what I should write in the bug report. Could someone explain what's going on here or file the bug for me? template A(alias T) { alias A = T; } void main() { struct S1 { S1* p; } static assert(is(typeof(A!(S1.init.p)) == S1*)); // ok pragma(msg, NULL: , typeof(A!(null))); // fail: S1* struct S2 { S2* p; } static assert(is(typeof(A!(S2.init.p)) == S2*)); // fail: S1* }
Re: Templates with alias param instantiated with null cached by DMD..?
On Wednesday, 23 October 2013 at 08:11:59 UTC, Kenji Hara wrote: On Wednesday, 23 October 2013 at 07:22:56 UTC, simendsjo wrote: I've stumbled upon a strange bug, and I'm not sure what I should write in the bug report. Could someone explain what's going on here or file the bug for me? template A(alias T) { alias A = T; } void main() { struct S1 { S1* p; } static assert(is(typeof(A!(S1.init.p)) == S1*)); // ok pragma(msg, NULL: , typeof(A!(null))); // fail: S1* struct S2 { S2* p; } static assert(is(typeof(A!(S2.init.p)) == S2*)); // fail: S1* } A!(S1.init.p) is mostly same as A!( cast(S1*)null ), because the expression S1.init.p is interpreted to a null value. 1. But current ABI does not support a typed null template value argument because all of null expression on template argument are mangled to 'n'. So the type of null value will be never encoded in the mangled name, and the three instantiations A!(S1.init.p), A!(null) and A!(S2.init.p) will have exactly same mangling. 2. However, the first instantiation A!(S1.init.p) wrongly caches the null value type (== S1*), and it appears in following instantiations during semantic analysis phase. #2 is definitely a front-end bug. However I'm not sure the current ABI definition issue (== #2) is a language spec bug or not... Kenji Hara Ok. Filed a bug. Probably not a good description, but I linked to your post: http://d.puremagic.com/issues/show_bug.cgi?id=11328
Allow illegal code in enum initialization?
Illegal code is accepted in static if, but not in enum declarations. This leads to having three lines when one is enough. Is this just an oversight, or by design? template T(alias A) { enum T = true; } void main() { struct S { } static if(__traits(compiles, S.a) T!(S.a)) // ok enum e1 = true; else enum e1 = false; enum e2 = __traits(compiles, S.a) T!(S.a); // No property S.a }
Re: Allow illegal code in enum initialization?
On Wednesday, 23 October 2013 at 16:27:47 UTC, Ali Çehreli wrote: On 10/23/2013 02:55 AM, simendsjo wrote: Illegal code is accepted in static if, but not in enum declarations. This leads to having three lines when one is enough. Is this just an oversight, or by design? template T(alias A) { enum T = true; } void main() { struct S { } static if(__traits(compiles, S.a) T!(S.a)) // ok enum e1 = true; else enum e1 = false; enum e2 = __traits(compiles, S.a) T!(S.a); // No property S.a } I don't know whether it is even specified but it feels like a feature to me. Just like the shortcut behavior of runtime if helps with avoiding illegal memory accesses, this helps with avoiding illegal code altogether: // null access avoided if ((p !is null) (p.member == 42)) // illegal code avoided static if (__traits(compiles, S.a) (S.a == 42)) Ali The question is if it would make sense to allow it for enum as well as static if. As enum is a compile-time constant I think it would be consistent.
Re: Cannot alias expression
On Monday, 21 October 2013 at 15:00:26 UTC, Dicebot wrote: On Monday, 21 October 2013 at 12:58:55 UTC, John Colvin wrote: I suspect I'm being very dumb here, but I can't get my head around this: template B(alias A) { alias B = A; } template C(A ...) { alias C = A[0]; } static assert(B!1 == 1); //fine static assert(C!1 == 1); //Error: cannot alias an expression 1 I think this is a good match for a gold collection of awkward mismatch of template alias vs normal alias. I am quite surprised former template work actually, aliases are not supposed to handle expressions at all. But magic of template alias parameter turns expression into symbol and here we go. I didn't know the B template would work... Is this correct semantics according to the spec?
Re: Cannot alias expression
On Monday, 21 October 2013 at 18:42:27 UTC, John Colvin wrote: On Monday, 21 October 2013 at 12:58:55 UTC, John Colvin wrote: I suspect I'm being very dumb here, but I can't get my head around this: template B(alias A) { alias B = A; } template C(A ...) { alias C = A[0]; } static assert(B!1 == 1); //fine static assert(C!1 == 1); //Error: cannot alias an expression 1 Also: struct S{} template B(alias A) { alias B = A; } template C(A ...) { alias C = A[0]; } pragma(msg, B!int); //Error: template instance B!(int) //does not match template declaration B(alias A) Alias doesn't take primitive types. I usually add a regular B(A) template overload too. Note that when you have a alias A overload, structs uses that rather than the basic A template. pragma(msg, B!S); // S pragma(msg, C!int); // int pragma(msg, C!S); // S
Re: Cannot alias expression
On Monday, 21 October 2013 at 16:51:02 UTC, simendsjo wrote: On Monday, 21 October 2013 at 15:00:26 UTC, Dicebot wrote: On Monday, 21 October 2013 at 12:58:55 UTC, John Colvin wrote: I suspect I'm being very dumb here, but I can't get my head around this: template B(alias A) { alias B = A; } template C(A ...) { alias C = A[0]; } static assert(B!1 == 1); //fine static assert(C!1 == 1); //Error: cannot alias an expression 1 I think this is a good match for a gold collection of awkward mismatch of template alias vs normal alias. I am quite surprised former template work actually, aliases are not supposed to handle expressions at all. But magic of template alias parameter turns expression into symbol and here we go. I didn't know the B template would work... Is this correct semantics according to the spec? I've used quite some T(A...), so I was used to literals not being aliasable. A bit strange that literals is symbols (or how I should phrase it) when using T(alias A), but not T(A...).
Re: Cannot alias expression
On Monday, 21 October 2013 at 16:51:02 UTC, simendsjo wrote: On Monday, 21 October 2013 at 15:00:26 UTC, Dicebot wrote: On Monday, 21 October 2013 at 12:58:55 UTC, John Colvin wrote: I suspect I'm being very dumb here, but I can't get my head around this: template B(alias A) { alias B = A; } template C(A ...) { alias C = A[0]; } static assert(B!1 == 1); //fine static assert(C!1 == 1); //Error: cannot alias an expression 1 I think this is a good match for a gold collection of awkward mismatch of template alias vs normal alias. I am quite surprised former template work actually, aliases are not supposed to handle expressions at all. But magic of template alias parameter turns expression into symbol and here we go. I didn't know the B template would work... Is this correct semantics according to the spec? I've used quite some T(A...), so I was used to literals not being aliasable. A bit strange that literals is symbols (or how I should phrase it) when using T(alias A), but not T(A...).
Collections
Last I heard, collection design was delayed while waiting for the allocator design. But I guess there are plenty of collection implementations already. So where are they? o Phobos: std.container - RedBlackTree, BinaryHeap, Array, SList, DList o DCollections: Not updated in 4 years - dead? o your library here And is the API description in Phobos stable, or is it expected to change a lot?
Re: Warnings/What should I know?
On Friday, 18 October 2013 at 06:56:49 UTC, monarch_dodra wrote: (...) struct S { this(int i = 5) {} } S s = S(); //Does *not* call the constructor with the value 5. I didn't know that. In that case, I think struct ctors with only optional parameters should be illegal - how is it possible to call it? Struct ctors without parameters is already illegal due to .init.
Error: cannot call public/export function someFunction from invariant
See topic. Why is this not allowed? The function in question is not virtual. struct S { void someFunction() const {} const invariant() { someFunction(); } } void main() { S s; }
Re: Warnings/What should I know?
On Friday, 18 October 2013 at 06:13:38 UTC, DDD wrote: I'm learning D. I'm curious about surprises I may get. I typically use C++, C# and javascript Some stuff from the top of my head. Remember that you're asking for gotchas and surprises rather than the nice features of D :) * D has built-in support for three different character types. UTF-8, 16 and 32. The default, char and string, is UTF-8. This means .length gives the number of bytes, not necessarily the number of symbols. * Private protection is private to the module, not to the type. This means a private class method can be called from anywhere in the module. * Array slices are great, but they require some understanding on how the underlying runtime handles them. See the array slice tutorial. * D has compile-time reflection rather than runtime. There are some features related to runtime reflection, but it's quite minimal. It's possible to get runtime reflection by using compile-time reflection though. * Templates in D is actually useful, so use them :) For example, in C#, generic type constraints isn't part of the signature, so you cannot overload generic functions. In D, this is not a problem. You can look at std.typecons to get a glimse of how powerful D is (warning: it still blows my mind, so it's not for the faint of hart, and you should probably delay this - most D code is actually very nice and readable and not at all this complex). * D doesn't have a preprocessor. You can solve much of the same stuff by using string mixins, template mixins and debug and version statements. Note that version statements is quite minimal and doesn't support stuff like or || by design. * The GC isn't as fast as in other languages (yet?), so if you are experiencing performance problems in a tight loop, try disabling the GC during that loop. * Not a gotcha, but you should look into D specific features like transitive const/immutable, pure, nothrow, safe, DbC, unittest, -cov, final switch, scope guards, templates, foreach etc. These change the way you code and is idiomatic D, so it's nice to learn them early on.
Re: Error: cannot call public/export function someFunction from invariant
On Friday, 18 October 2013 at 09:08:53 UTC, Jonathan M Davis wrote: On Friday, October 18, 2013 11:04:25 bearophile wrote: simendsjo: See topic. Why is this not allowed? The function in question is not virtual. struct S { void someFunction() const {} const invariant() { someFunction(); } } void main() { S s; } It being not virtual is not important. In what cases is invariant() called, simendsjo? I sense an infinite loop. Yeah, it's probably because someFunction calls the invariant before and after it's called. If you want to call a member function from an invariant, it should be static, or it should be a free function. Ah, good point - stupid me :) I'll rather move some checking to pre/post contracts.
Re: Starting D with a project in mind.
On Wednesday, 16 October 2013 at 19:18:53 UTC, Andrew wrote: I'm a very happy man ! Everything is built and working including dub and the http_server example from vibe.d. It's slow to build, but it executes quickly and strips down to about 3MB which is heavy but tolerable. Thanks to everybody for the help, now I can start learning D, exploring vibe.d and Pegged and hopefully make some good progress on my MUD. So to recap, to help anybody else building on ARM these are the steps I took :- mkdir gdc cd gdc wget http://gcc.igor.onlinedirect.bg/snapshots/LATEST-4.8/gcc-4.8-20131010.tar.bz2 tar xvf gcc-4.8-20131010.tar.bz2 git clone https://github.com/jpf91/GDC.git arm_gdc cd arm_gdc git checkout arm ./setup-gcc.sh ../gcc-4.8-20131010 cd ../ mkdir build cd build export C_INCLUDE_PATH=/usr/include/$(gcc -print-multiarch) export EXTRA_CONF=-mfloat-abi=hard --with-float=hard ../gcc-4.8-20131010/configure --enable-languages=d --disable-bootstrap --prefix=/usr/local/gdc --disable-multilib --disable-softfloat --with-float=hard make -j2 sudo make install sudo cp ../arm_gdc/libphobos/libdruntime/core/time.d /usr/local/gdc/include/d/4.8.2/armv7l-unknown-linux-gnueabihf/core sudo mv /usr/local/gdc/include/d/4.8.2/armv7l-unknown-linux-gnueabihf/core/time.di /usr/local/gdc/include/d/4.8.2/armv7l-unknown-linux-gnueabihf/core/time.di.old I don't know why that last step was necessary but dub and a few other things didn't build without it. After that dub built fine once I'd hacked the build file to use gdc. This is very cool. You should add it to the wiki so it doesn't get lost: http://wiki.dlang.org
Re: How to check for instantiation of specific template?
On Thursday, 10 October 2013 at 17:24:37 UTC, H. S. Teoh wrote: I have a template used for storing compile-time values: template Def(int x, string y) { alias impl = TypeTuple!(x,y); } How do I define a template isDef that, given some template alias A, evaluates to true if A is some instantiation of Def? template isDef(alias A) { enum A = ... /* what to put here? */ } The intent is to be able to write signature constraints like this: auto myFunc(alias def)(...) if (isDef!def) { ... } ... // Pass an instantiation of Def to myFunc auto x = myFunc!(Def!(1, abc))(args); I tried using std.traits.isInstanceOf but apparently it expects the second argument to be an actual type, which doesn't work in this case because Def is a typetuple of compile-time values, not an actual type. T I've used this horrible hack to solve this. Not very generic as you can see: else static if(T.stringof.length 13 T.stringof[0..13] == TupleWrapper!)
Re: Get unique id of a class type.
On Monday, 7 October 2013 at 18:55:58 UTC, Agustin wrote: I'm looking a way to get the unique id of a class. I'm able to do this in C++ using type_info::hash_code(). void function(T) { auto id = typeid(T).getHash(); // Something like this? // I know i could write this but seems ugly to me :/ auto id = typeid(string).getHash(typeid(T).name); // Or maybe even better. auto id = typeid(T).id; // ID is not a number but a class for storing } Have you tried toHash()? https://github.com/D-Programming-Language/druntime/blob/master/src/object_.d#L211
Re: Ddoc WEB function
On Thursday, 3 October 2013 at 10:46:00 UTC, Joseph Rushton Wakeling wrote: On 02/10/13 21:34, Jonathan M Davis wrote: It's not a bug at all. It's in https://github.com/D-Programming-Language/dlang.org/blob/master/std.ddoc ddoc is a macro language and does not at all restrict you to what comes with it, and the standard library uses quite a few macros that are specific to it (e.g. XREF for a link to another module in std). When you run dmd with -D, you can give it a .ddoc file which contains macros that you define (or redefine), and std.ddoc is the one that the standard library uses. Ahh, OK, thanks. If you to restrict yourself to the built-in ones in your code, then use the ones at http://dlang.org/ddoc.html And if you want to define more, then create your own .ddoc file with them in it. But Phobos uses std.ddoc, and we add new macros to it when we feel that it's appropriate. Fair enough, but ... , and is there any particular reason to favour WEB over, say, LINK2 ? It's less verbose. ... is there any difference between WEB and LINK2 apart from the length? And if so, why not just include WEB among the built-in macros? Doesn't WEB just add http://; before the first parameter? LINK2 = a href=$1$+/a WEB = a href=http://$1;$+/a I don't think there should be too many predefined macros. At least not all related to HTML. But it's possible to override them, right? There are probably plenty of nice-to-have macros that would be convenient to have always available, but it's pretty trivial to add them yourself - or just use the phobos ddoc.
Re: Bug again?
On Thursday, 3 October 2013 at 12:24:38 UTC, Zhouxuan wrote: mixin template test() { int next; } void foo(alias l, alias t)() { t.next = l.next; } void main() { struct A { int next; } A a; mixin test l1; mixin test l2; foo!(l1,a); //ok! foo!(l1,l2);//compilation error! } Local aliasing problems..? The error message is Error: function D main is a nested function and cannot be accessed from t.foo!(l1, l2).foo Moving the mixins out of main works.
Phobos - pure, const, safe, nothrow
What is the status of adding these annotations to phobos? It's difficult to use these until phobos gets them. E.g. to! and format is not pure.