Re: string[] enumerations

2011-05-10 Thread Tomek Sowiński
Nrgyzer napisał: > I need enumerations with string[] as base type. What for? -- Tomek

Re: full ident name without mangle/demange?

2011-03-09 Thread Tomek Sowiński
Nick Sabalausky napisał: > Is there a way to get the fully-qualified name of an identifier without > doing "demange( mangledName!(foo) )"? Heh, looks like there isn't. It may be worth filing an enhancement request for __traits(fullyQualifiedName, foo). BTW, what do you need it for? -- Tomek

Re: assert(expression, error)

2011-02-12 Thread Tomek Sowiński
spir napisał: > Is there a way to specify what error to throw using (a variant of) assert: > assert(n > 0, new ValueError("...")); > > (Sure, one can write: > if (n <= 0) > throw new ValueError("...")); > but the same remark applies to plain assert: the whole point of assert is

Re: std.concurrency & immutable classes...

2011-02-11 Thread Tomek Sowiński
Steven Schveighoffer napisał: > > It would be much easier if he provided the specific case(s) which broke > > his teeth. Then we'll all know where's the problem. If it's soluble, > > it'll open the door to tail type modifiers in general, not just in > > classes. It's a burning issue e.g. wit

Re: Assert compilation failure with certain message

2011-02-11 Thread Tomek Sowiński
Andrej Mitrovic napisał: > I've managed to screw up the colon placement though, here's a quick fix: > > import std.stdio; > import std.conv; > > void staticAssert(alias exp, string message, string file = __FILE__, > int line = __LINE__)() > { > static if (!exp) > { > pragma(msg,

Re: Assert compilation failure with certain message

2011-02-10 Thread Tomek Sowiński
bearophile napisał: > > Is there a way to statically assert compilation of an expression failed > > *with a certain message*? I want to check > > my static asserts trip when they should. > > I have asked something like this a lot of time ago, but I don't know a way to > do it. You are able to

Assert compilation failure with certain message

2011-02-10 Thread Tomek Sowiński
Is there a way to statically assert compilation of an expression failed *with a certain message*? I want to check my static asserts trip when they should. -- Tomek

Re: std.concurrency & immutable classes...

2011-02-10 Thread Tomek Sowiński
Michel Fortin napisał: > > Thanks for doing this. Is it approved by Walter? > > Depends on what you mean by "approved". > > He commented once on the newsgroup after I posted an earlier version of > the patch, saying I should add tests for type deduction and some other > stuff. This change hi

Re: std.concurrency & immutable classes...

2011-02-07 Thread Tomek Sowiński
Michel Fortin napisał: > I just made this pull request today: > > > If you want to test it, you're very welcome. Here is my development > branch for this feature: > Thanks for doing this

std.concurrency & immutable classes...

2011-02-06 Thread Tomek Sowiński
... doesn't work. class C {} thisTid.send(new immutable(C)()); receive((immutable C) { writeln("got it!"); }); This throws: core.exception.AssertError@/usr/include/d/dmd/phobos/std/variant.d(285): immutable(C) And when I go for Rebindable, I get "Aliases to mutable thread-local data not allow

Re: General unicode category

2011-01-30 Thread Tomek Sowiński
spir spir napisał: > DUnicode has such functionality: https://bitbucket.org/stephan/dunicode/src > Watch inside unicodedata.d, search for "general category". Thanks. Any word of moving some of it into Phobos? It's jarring to see a Unicode-compliant language have so few tools to work with the sta

General unicode category

2011-01-29 Thread Tomek Sowiński
How can I get the general unicode category (Lu, Nd, Pc, etc.) of a dchar? std.uni contains barely anything useful. -- Tomek

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-29 Thread Tomek Sowiński
Tom napisał: > I am learning D for some time. I come from background of C, C# and Python. > When I saw the ways to use std.algorithem's functions, I have noticed that the > input lambda's can be writen as strings. Somewhat like the pythonic "exec". I > went to the source of this feature in functio

Re: Nested function declarations

2011-01-29 Thread Tomek Sowiński
Tomek Sowiński napisał: > > What is the purpose of nested function declarations in D? Is it a good idea > > to just disallow them? > > 1. Helper functions don't clutter the namespace. > 2. Nested functions can access the outer function's stack frame. OK,

Re: Nested function declarations

2011-01-29 Thread Tomek Sowiński
bearophile napisał: > What is the purpose of nested function declarations in D? Is it a good idea > to just disallow them? 1. Helper functions don't clutter the namespace. 2. Nested functions can access the outer function's stack frame. -- Tomek

Re: What's wrong with this code?

2011-01-08 Thread Tomek Sowiński
Sean Eskapp napisał(a): I had some code that was segfaulting, so I rewrote the basic idea as a fibonacci function, and lo and behold, it still segfaults. Why, and how to fix? This looks fishy: class Fib { private const Fib* left, right; ... this(in Fib left, in Fib right)

Re: list of anything

2010-12-18 Thread Tomek Sowiński
spir napisał: > In Lisp-like languages, a list can hold anything: > (1 "a" (1 "a")) > I do not find it trivial to simulate this in D. Using a linked list or an > array: the issue is not with the kind of > collection but with elements. In either case, I guess, elements should > actually be

Re: Problems with Reflection in Static library

2010-12-18 Thread Tomek Sowiński
Mandeep Singh Brar napisał: > I have a class A in module testD as follows > > module testD; > import std.stdio; > public class A { > public this() { > writeln("const"); > } > public void a(string l, int k) { > writeln("Hello B.a", l, k); > } > }

Re: why no implicit convertion?

2010-11-17 Thread Tomek Sowiński
Dnia 17-11-2010 o 22:38:50 Jonathan M Davis napisał(a): There is no way (as far as I know) to convert that to a dynamic array of dynamic arrays. As such, the compiler can't do it implicitly or explicitly. You can probably create a dynamic array of dynamic arrays and assign each of the int

Re: why no implicit convertion?

2010-11-17 Thread Tomek Sowiński
Dnia 17-11-2010 o 22:32:21 Tomek Sowiński napisał(a): What's best to pass such multidimensional arrays? Good question. Maybe new char[][](4) and point the inner arrays to the chunks of the static array? Correction, it can be allocated on the stack: char[4][4] b; cha

Re: why no implicit convertion?

2010-11-17 Thread Tomek Sowiński
Matthias Pleh napisał(a): void foo(char[] a) {} void bar(char[][] b) {} int main(string[] args) { char[4] a; char[4][4] b; foo(a);// OK: implicit convertion bar(b);// Error: cannot implicitly convert //char[4u][4u] to char[][] }

Re: method chaining

2010-11-08 Thread Tomek Sowiński
spir napisał: > Hello, > > I don't understand why the compiler refuses the code below, with the error > __trials__.d(33): found '.' when expecting ';' following statement > (Note that method set returns this.) > > class C { > int i,j; > this (int i) { > this.i = i; > } >

Re: subclass instance construction

2010-11-05 Thread Tomek Sowiński
spir napisał: > I have a weird bug related to class instance construction. My guess is > that it seems a superclass's this() is implicitely called (before the > subclass's one, if any), even if overriden and without any use of "super". > In my case, I have schematically: > > === super class === >

Re: Sorting after map

2010-10-23 Thread Tomek Sowiński
Dnia 20-10-2010 o 08:26:12 clueless napisał(a): Hi. I want to have a sorted result of map-function, that is (in pseudocode): sorted(map!(fun)(arr)) How can I do that? I have tried something like: auto s = map!(fun)(arr); //sort(s); //sort(s[]); //sort(s.dup); writeln(s); but without succe

Re: toString(char*)?

2010-10-11 Thread Tomek Sowiński
Lars T. Kyllingstad napisał: > I don't think it works the other way, though, you still have to use > std.string.toStringz(). Most (all?) conversions in std.conv implement the whole round-trip, there's no reason for string <-> char* to be any different. File a bug and see what happens. -- Tome

ditto in DDoc

2010-10-08 Thread Tomek Sowiński
More of an English question... dunno <- don't know ditto <- ? -- Tomek

Re: foreach over enums?

2010-10-05 Thread Tomek Sowiński
Simen kjaeraas napisał: > enum X { A=3, B=1, C } > > void main( ) { > foreach( e; __traits(allMembers, X) ) { > writeln( "X.", e, " = ", mixin( "X."~e ) ); > } > } mixin("X."~e) => __traits(getMember, X, e) For mixin-allergics. -- Tomek

D IDE: Eclipse & mmrnmhrm plugin problems

2010-09-13 Thread Tomek Sowiński
Has anyone succeeded in making mmrnmhrm work on linux/ubuntu (or anywhere else)? I've run into problems: http://www.dsource.org/forums/viewtopic.php?t=5615 Seen anything like it? -- Tomek

Re: Duck typing and safety.

2010-08-13 Thread Tomek Sowiński
simendsjo napisał: > While reading std.range, I though that a ducktyping design without > language/library support can be quite fragile. > > Consider the following example: > > import std.stdio; > > struct S > { > void shittyNameThatProbablyGetsRefactored() { }; > } > > void process(T)(T s) >

Re: string initialization question.

2010-07-30 Thread Tomek Sowiński
Dnia 30-07-2010 o 22:15:50 Tomek Sowiński napisał(a): writeln('-'.repeat.take(5)); Oh, and if repeat had slicing (as it should)... '-'.repeat[0..5] Still, it's far cry from Python's '-' * 5 Tomek

Re: string initialization question.

2010-07-30 Thread Tomek Sowiński
Dnia 30-07-2010 o 17:24:41 dcoder napisał(a): Is there anyway in D to convenient fill a string variable with a char say X times? If you need to only print, you can: import std.stdio; import std.range; void main() { foreach (c; take(repeat('-'), 5)) write(c); } I know, I know,

Re: Single "alias this"

2010-07-25 Thread Tomek Sowiński
Deokjae Lee wrote: > But I can't do it using D. Code like the following does not be compiled. > > > class C : BaseClass, Interface1, Interface2, ... > > > Is there any particular reason? What's the difference between Java's > approach and single "alias this"? Huh? This compiles: class Foo :

Re: Parsing with ranges

2010-07-23 Thread Tomek Sowiński
Dnia 22-07-2010 o 15:22:14 %u napisał(a): How to parse a simple format with ranges? For example a query string format: string[string] params = parse("foo=1&bar=1%202&baz=1+2+3"); assert(params["foo"] == "1"); assert(params["bar"] == "1 2"); assert(params["baz"] == "1 2 3"); parse() should a

Re: Class knowing its own Class

2010-06-30 Thread Tomek Sowiński
Dnia 30-06-2010 o 00:13:28 strtr napisał(a): == Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article On Tue, 29 Jun 2010 17:59:37 -0400, strtr wrote: > What is the pretty way to do something like this? > > Class C > { > void makeNew() > { > new typeof(this); > } > } As ed

Re: Why assert is in the language?

2010-06-24 Thread Tomek Sowiński
Dnia 24-06-2010 o 01:39:35 Jonathan M Davis napisał(a): Tomek Sowiński wrote: There's a better way: void assert_(string file = __FILE__, uint line = __LINE__)(bool pred, lazy string msg = null) { version(unittest) if (!pred) throw new AssertError(msg,

Re: Why assert is in the language?

2010-06-23 Thread Tomek Sowiński
Dnia 23-06-2010 o 07:05:42 dennis luehring napisał(a): Am 22.06.2010 23:07, schrieb Tomek Sowiñski: Yes, why? It could be implemented in object.d in a similar fashion as std.contracts.enforce. Does it do anything special that a library function couldn't? Tomek what about static assert?

Re: Why assert is in the language?

2010-06-23 Thread Tomek Sowiński
Dnia 22-06-2010 o 23:55:29 Michal Minich napisał(a): On Tue, 22 Jun 2010 17:30:23 -0400, Steven Schveighoffer wrote: On Tue, 22 Jun 2010 17:07:02 -0400, Tomek Sowiński wrote: Yes, why? It could be implemented in object.d in a similar fashion as std.contracts.enforce. Does it do anything

Why assert is in the language?

2010-06-22 Thread Tomek Sowiński
Yes, why? It could be implemented in object.d in a similar fashion as std.contracts.enforce. Does it do anything special that a library function couldn't? Tomek

Re: Synchronized const methods

2010-06-12 Thread Tomek Sowiński
Dnia 12-06-2010 o 09:28:58 Jérôme M. Berger napisał(a): Daniel Keep wrote: immutable means "no one can modify this." const means "someone might be able to modify this, but not you can't." So? Basically, what the OP said, is that we need readers-writer locks [1]. A const syn

Synchronized const methods

2010-06-11 Thread Tomek Sowiński
If a synchronized method call sees that someone's already partying with its object, it waits. So far so good. Now here's something I don't quite get: if a *const* synchronized method call sees that another const synchronized method call is holding the lock, then why it needs to be held up?

Alias parameters in nested templates

2010-02-11 Thread Tomek Sowiński
I've been playing with templates recently and there's something I don't quite get. template Outer() { template Inner(alias param) { alias param Inner; } } void main() { long d; Outer!().Inner!(d) = 4; // fails } Error: template instance cannot use local 'd' as paramete

Re: template specialization question

2010-01-31 Thread Tomek Sowiński
Dnia 31-01-2010 o 21:39:21 Ali Çehreli napisał(a): � wrote: Dnia 31-01-2010 o 20:59:47 Tomek Sowi�ski napisa�(a): // specialization needed to limit matching types void print(T:int)(T thing) To be clear -- I did this to silence the compiler saying the call with array matches more than one

Re: template specialization question

2010-01-31 Thread Tomek Sowiński
Dnia 31-01-2010 o 20:59:47 Tomek Sowiński napisał(a): // specialization needed to limit matching types void print(T:int)(T thing) To be clear -- I did this to silence the compiler saying the call with array matches more than one function template declaration. I'm not sure whethe

Re: template specialization question

2010-01-31 Thread Tomek Sowiński
Dnia 31-01-2010 o 19:49:44 daoryn napisał(a): import std.stdio; void print(T)(T thing) { writeln("Calling print(T)"); writeln(T.stringof); } void print(T:T[])(T[] things) { writeln("Calling print(T[])"); writeln(T.stringof); } void main() { print(3);

What function am I in?

2010-01-17 Thread Tomek Sowiński
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

Searching the std.algorithm.BinaryHeap

2010-01-06 Thread Tomek Sowiński
Dumb question: how do I find an element in a BinaryHeap (or in general traverse it)? It's not a range, so std.algorithm.find won't work. I don't want BinaryHeap.release() because it clears the heap. Tomek

Re: Immutable & circular imports

2009-12-17 Thread Tomek Sowiński
Dnia 17-12-2009 o 01:14:53 grauzone napisał(a): There are a _lot_ of circular dependency bugs, and there are a lot of immutable related bugs. Combine both together and you get... probably even more bugs. So I'm noticing... BTW, what is your approach to avoid such woes when writing in D2?

Immutable & circular imports

2009-12-16 Thread Tomek Sowiński
Amusing things happen when immutable arguments and circular imports are put together: -- module hello; import test; struct Strukt { Staly* s; } -- module test; import hello; immutable struct Staly {

Re: Anonymous nested class of problems

2009-12-12 Thread Tomek Sowiński
Dnia 13-12-2009 o 00:44:56 Tomek Sowiński napisał(a): Dnia 12-12-2009 o 13:09:49 Tomek Sowiński napisał(a): But that's not all, when I mark my class immutable... immutable class M { this(byte a) { _a = a; } byte _a; byte a() { return _a; }; } void main() { auto m

Re: Anonymous nested class of problems

2009-12-12 Thread Tomek Sowiński
Dnia 12-12-2009 o 13:09:49 Tomek Sowiński napisał(a): But that's not all, when I mark my class immutable... immutable class M { this(byte a) { _a = a; } byte _a; byte a() { return _a; }; } void main() { auto m = new class(4) M { this(byte a) { su

Re: Anonymous nested class of problems

2009-12-12 Thread Tomek Sowiński
Dnia 12-12-2009 o 15:00:56 div0 napisał(a): -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Tomek Sowiñski wrote: Dnia 12-12-2009 o 13:09:49 Tomek Sowiñski napisa³(a): Error: no constructor for __anonclass10 This one seems to be unrelated to anonymous stuff. class M { this(byte a) { _

Re: Anonymous nested class of problems

2009-12-12 Thread Tomek Sowiński
Dnia 12-12-2009 o 13:09:49 Tomek Sowiński napisał(a): Error: no constructor for __anonclass10 This one seems to be unrelated to anonymous stuff. class M { this(byte a) { _a = a; } byte _a; byte a() { return _a; }; static m = new M(3); } I get: Error: no constructor for M

Anonymous nested class of problems

2009-12-12 Thread Tomek Sowiński
I was playing with what makes the Javists proud, but stumbled over this: class M { this(byte a) { _a = a; } byte _a; byte a() { return _a; }; static m = new class(4) M { this(byte a) { super(a); } override byte a() { return 3+_a; } }; } Error: class test.M.__

Re: Immutable data not copied

2009-12-09 Thread Tomek Sowiński
Dnia 09-12-2009 o 09:54:33 Lutger napisał(a): Tomek Sowiński wrote: const(FAQ) says: "When doing a deep copy of a data structure, the invariant portions need not be copied." I'm trying to imagine what code would benefit from such optimization. immutable struct Large { w

Immutable data not copied

2009-12-08 Thread Tomek Sowiński
const(FAQ) says: "When doing a deep copy of a data structure, the invariant portions need not be copied." I'm trying to imagine what code would benefit from such optimization. immutable struct Large { whole lotta data... } struct Other { Large l; } void funkcja(Large s); // no reference anno

Re: Static functions in immutable types...

2009-12-07 Thread Tomek Sowiński
Dnia 07-12-2009 o 11:34:52 Michal Minich napisał(a): Hello Tomek, ... don't make sense. So is there a reason why they aren't excluded from the "everything in an immutable is immutable" rule? Tomek Immutable static member function could be useful... marking struct or class as const or

Static functions in immutable types...

2009-12-06 Thread Tomek Sowiński
... don't make sense. So is there a reason why they aren't excluded from the "everything in an immutable is immutable" rule? Tomek

Explicit ordering with std.format

2009-12-04 Thread Tomek Sowiński
An extract from java.util.Formatter docs: // Explicit argument indices may be used to re-order output. formatter.format("%4$2s %3$2s %2$2s %1$2s", "a", "b", "c", "d") // -> " d c b a" How do I achieve this with std.format? The ddocs only say that "variadic arguments are consumed in order".