Re: Why does 'string' alias immutable(char)[] and not immutable(char[]) ?

2010-12-01 Thread spir
On Wed, 1 Dec 2010 03:25:24 -0800 Jonathan M Davis wrote: > On Wednesday 01 December 2010 03:17:48 spir wrote: > > Well, nearly everything is in the title... I would intuitively opt for the > > second type if I had to define an immutable string type. > > > > Answers

Re: 2 little enigmas with is() & Unqual!

2010-12-01 Thread spir
On Wed, 01 Dec 2010 10:03:57 -0500 vincent picaud wrote: > spir Wrote: > > > Hello, > > > > 1. Why isn't Unqual!(char) == char? > > writeln( is( Unqual!(typeof('c')) == char ) ); // false > > writeln( is( Unqual!(char) == char ) );

'in' for plain arrays?

2010-12-02 Thread spir
Hello, Is there an equivalent of 'in' for (non-associative) arrays? Cannot find any 'contains' function. (Wouldn't it be nice to have in work for all arrays? What is the reason why it only works with AAs?) Denis -- -- -- -- -- -- -- vit esse estrany ☣ spir.wikidot.com

Re: 'in' for plain arrays?

2010-12-03 Thread spir
On Thu, 02 Dec 2010 08:54:43 -0800 Ali Çehreli wrote: > bearophile wrote: > > Pelle M.: > > > >> It doesn't exist for performance reasons, I think. > > > > It's not a matter of performance. Walter thinks that "in" on > > AAs searches on keys. And the "keys" of a dynamic array are its > > i

Re: casting int to uint and vice versa - performance

2010-12-03 Thread spir
On Fri, 03 Dec 2010 17:49:47 -0500 "Steven Schveighoffer" wrote: > > just that i + i generates different instructions than ui + ui where int > > i; uint ui; > > > > Not really important, because I'm currently interested in cast only. > > > > Thank you. > > That is odd, I would think that i+i g

Where can I find how string == is performed in dmd2 source?

2010-12-06 Thread spir
Hello, Nearly all is in title. I found dmd2/src/phobos/std/string.cmp in string.d. But this performs string comp with positive/negative/zero result, not equality test with boolean result. denis -- -- -- -- -- -- -- vit esse estrany ☣ spir.wikidot.com

Re: How to exit a process?

2010-12-06 Thread spir
On Mon, 6 Dec 2010 19:11:59 + (UTC) Adam Ruppe wrote: > Is there a thing like C's exit() for a D program? Is > simply using C's function good enough? I use: import core.stdc.stdlib : exit; // debug tool func void stop () {exit(0);} denis -- -- -- -- -- -- -- vit esse

inlining

2010-12-07 Thread spir
Hello, Does dmd inline when appropriate (eg single-line func)? or is there a hint keyword? or what else? Eg how to have this inlined: private bool isPrecomposedHangulSylable (Code code) { /** whether code is a precomposed Hangul syllable ;-) */ return (code >= FIRST_HANGUL_SYLLABLE) && (

Re: inlining

2010-12-07 Thread spir
On Tue, 07 Dec 2010 13:44:18 +0100 Lutger Blijdestijn wrote: > There are some other conditions that prevent inlining, it's best to check > for it. iirc also functions with loops, delegate and ref parameters cannot > be inlined for example. I'm not so sure about ref, that may have been > improv

unpacking

2010-12-07 Thread spir
Hello D people, Is there a way to unpack an array into local vars, as: auto x = [1,2,3]; a,b,c = x; Denis -- -- -- -- -- -- -- vit esse estrany ☣ spir.wikidot.com

free function on arrays & language operations

2010-12-07 Thread spir
Hello again, I started to be found of defining types which basically are arrays with free functions, instead of creating a struct or class with methods. Not only we still have pseudo-method syntax (for arrays only), but this allows customizing the type when needed. But: is there a way to define

Re: inlining

2010-12-07 Thread spir
On Tue, 07 Dec 2010 16:20:45 +0100 Lutger Blijdestijn wrote: > Lutger Blijdestijn wrote: > > > spir wrote: > > > >> On Tue, 07 Dec 2010 13:44:18 +0100 > >> Lutger Blijdestijn wrote: > >> > >>> There are some other conditions that pre

Re: Facing problems with Class Properties

2010-12-10 Thread spir
On Sat, 11 Dec 2010 06:11:43 +0530 d coder wrote: > > if(false) { > >    for (size_t j = 0; j < f.length...) > >    ... > > } > > > > Semantically this code is wrong as you can't take the length of f which is > > class Bar. The static if forces the compiler to not generate this code as > > it i

cannot make opDollar work

2010-12-12 Thread spir
Hello, Test case: struct S { int[] ints; int opDollar () {return this.ints.length;} int opIndex (int i) {return this.ints[i];} int[] opSlice (int i, int j) {return this.ints[i..j];} } unittest { S s = S([3,2,1]); // _link_ error on each line: // Error: undefined ident

_indexed_ iteration using opApply or range

2010-12-12 Thread spir
Hello, Had a nice time figuring out how to let opApply allow index iteration like: foreach (i, x ; collection) {} Finally managed to do it adding 'i' everywhere: struct S1 { private int[] elements = []; int opApply (int delegate (ref uint, ref int) block) { foreach (uint i, in

Re: _indexed_ iteration using opApply or range -- PS

2010-12-12 Thread spir
On Sun, 12 Dec 2010 20:47:04 +0100 spir wrote: > Hello, > > Had a nice time figuring out how to let opApply allow index iteration like: > foreach (i, x ; collection) {} > Finally managed to do it adding 'i' everywhere: > > struct S1 { > private int[

Re: _indexed_ iteration using opApply or range

2010-12-12 Thread spir
On Sun, 12 Dec 2010 21:15:00 +0100 "Simen kjaeraas" wrote: > The trick to ranges is that they modify themselves. For a simple array > wrapper > range this may be a way: > > struct wrapper( T ) { > T[] data; > void popFront( ) { > data = data[1..$]; > } > ref T fron

funny bug with input range interface and toString

2010-12-13 Thread spir
Hello, I have a strange bug with an input range interface. Initially, I had a (rather big) struct called Text with loads of working unittests. When adding a range interface, noting worked anymore, any test ran into an infinite loop (the terminal writes pages of '[') ending with segfault. After

Re: Removing an object from a range

2010-12-13 Thread spir
On Sun, 12 Dec 2010 20:43:12 -0500 "Andrej M." wrote: > I can't seem to find an easy remove method in std.algorithm that takes an > object and a range (an array in this case) and removes any matches from the > range. I'm using this snippet for now: > > private DrawingElement[] elements; > > p

Re: funny bug with input range interface and toString

2010-12-13 Thread spir
On Mon, 13 Dec 2010 17:37:19 +0300 "Nick Voronin" wrote: > On Mon, 13 Dec 2010 11:24:48 +0300, spir wrote: > > > I have a strange bug with an input range interface. Initially, I had a > > (rather big) struct called Text with loads of working unittests. When

Re: _indexed_ iteration using opApply or range

2010-12-13 Thread spir
On Mon, 13 Dec 2010 09:47:39 -0500 "Steven Schveighoffer" wrote: > What's wrong with using opApply? You should be able to define both range > primitives and opApply and opApply will be used when foreach is used, and > the range primitives will be used by things like std.algorithm. Hope opAp

random access-range without lower-power range kinds?

2010-12-14 Thread spir
Hello, It seems impossible to define a random-access range (opIndex + length) alone. In fact, I cannot have it used by the language. Am I missing something? Random-access looks enough to provide fonctionality for both input and bidirectional ranges without any additional method. "Lowering" for f

Re: random access-range without lower-power range kinds?

2010-12-14 Thread spir
On Tue, 14 Dec 2010 14:15:20 + (UTC) "Lars T. Kyllingstad" wrote: > On Tue, 14 Dec 2010 09:09:33 +0100, spir wrote: > > > Hello, > > > > It seems impossible to define a random-access range (opIndex + length) > > alone. In fact, I cannot ha

helpful runtime error messages

2010-12-14 Thread spir
Hello, Am I the only one who gets, as only kind of runtime errors, spectacularly helpful messages like: int f () {return 0;} void main () { assert (f() == 1); } ==> s...@o:~/prog/d/Text$ ./__trials__ core.exception.asserter...@__trials__(44): Assertion failure ./__trials__(

Re: helpful runtime error messages

2010-12-15 Thread spir
On Tue, 14 Dec 2010 10:13:03 -0800 Jonathan M Davis wrote: > On Tuesday, December 14, 2010 09:48:14 spir wrote: > > Hello, > > > > > > Am I the only one who gets, as only kind of runtime errors, spectacularly > > helpful messages like: > >

Re: helpful runtime error messages

2010-12-15 Thread spir
On Tue, 14 Dec 2010 13:44:27 -0500 Jesse Phillips wrote: > spir Wrote: > > > Hello, > > > > > > Am I the only one who gets, as only kind of runtime errors, spectacularly > > helpful messages like: > > > > int f () {return 0;} > > void ma

Re: helpful runtime error messages

2010-12-15 Thread spir
On Wed, 15 Dec 2010 11:54:28 -0500 Jesse Phillips wrote: > spir Wrote: > > > For the following prog, I get: > > > > int element(int[] elements, uint i) {return elements[i];} > > void main () { > > int[] elements = [3,2,1]; > > auto e = elemen

list of anything

2010-12-18 Thread spir
Hello, 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 void* pointers. B

opAssign work not with initialisation?

2010-12-18 Thread spir
Hello, struct S { int value; void opAssign(int value) { this.value = value; } } unittest { S s1; s1 = 3; // OK S s2 = 3; // _build_ error } ==> Element.d(105): Error: cannot implicitly convert expression (3) of type int to S Do I miss something? And why not

define methods apart

2010-12-18 Thread spir
Hello, I cannot find a way to define methods (I mean "member functions) outside the main type-definition body: struct X {} void X.say () {writeln("I say!");} ==> Element.d(85): semicolon expected, not '.' Do I overlook anything, or is this simply impossible? In the latter case, what is the pr

Re: Problems with Reflection in Static library

2010-12-18 Thread spir
On Sat, 18 Dec 2010 13:07:41 +0100 Tomek Sowiński wrote: > BTW, am I the only one to think Object.factory is a bad name? It doesn't > return a factory. Sure, one can get used to it, but why not Object.make or > .create or .instance? You're not the only one ;-) Similar to index(ing) not returni

Re: list of anything

2010-12-18 Thread spir
On Sat, 18 Dec 2010 13:35:21 +0100 David Nadlinger wrote: > > But I could not find a way to do that, instead get weird error messages > > like eg 'int' is not a value (so, what else?). > It is a type, and as such a compile-time entity rather than a runtime > value. You might want to have a lo

Re: opAssign work not with initialisation?

2010-12-18 Thread spir
On Sat, 18 Dec 2010 13:08:14 + Adam Burton wrote: > > struct S { > > int value; > > void opAssign(int value) { > > this.value = value; > > } > > } > > unittest { > > S s1; > > s1 = 3; // OK > > S s2 = 3; // _build_ error > > } > > ==> > > Element.d(105): Err

Re: define methods apart

2010-12-19 Thread spir
On Sun, 19 Dec 2010 03:37:37 -0600 Christopher Nicholson-Sauls wrote: > On 12/18/10 07:19, spir wrote: > > Hello, > > > > > > I cannot find a way to define methods (I mean "member functions) outside > > the main type-definition body: > > >

Re: rdmd bug?

2010-12-20 Thread spir
On Mon, 20 Dec 2010 04:27:33 +0300 Nick Voronin wrote: > On Mon, 20 Dec 2010 01:24:02 +0100 > CrypticMetaphor wrote: > > > Anyway, the problem is, if I call rdmd from outside the folder in which > > the main source resides in, and main includes another file in that > > folder, I get an error.

Re: Classes or stucts :: Newbie

2010-12-20 Thread spir
On Sun, 19 Dec 2010 21:33:56 -0500 bearophile wrote: > >So, putting classes on the stack kind of negates the whole point of having > >both structs and classes in the first place.< > > This is false, the definition of D class instance doesn't specify where the > instance memory is allocated.

Re: Classes or stucts :: Newbie

2010-12-20 Thread spir
On Mon, 20 Dec 2010 01:29:13 -0800 Jonathan M Davis wrote: > > For me, the important difference is that classes are referenced, while > > structs are plain values. This is a semantic distinction of highest > > importance. I would like structs to be subtype-able and to implement > > (runtime-type-

Re: Classes or stucts :: Newbie

2010-12-20 Thread spir
On Mon, 20 Dec 2010 03:11:49 -0800 Jonathan M Davis wrote: > Now, you could conceivably have a language where all of its objects were > actually pointers, but they were treated as value types. So, > > B b; > A a = b; > > would actually be declaring > > B* b; > A* a = b; > > underneath the ho

Re: is expression for template structs/classes instances?

2010-12-21 Thread spir
On Tue, 21 Dec 2010 09:53:49 +0530 d coder wrote: > Greetings > > I want to find if a given struct type is instantiated from a > particular template struct type. For example: > > struct S (T) { > alias T Type; > T t; > } > > And later I want to find out if a given type is of type S(*) > (

Re: string comparison

2010-12-21 Thread spir
On Tue, 21 Dec 2010 11:49:42 -0500 "Steven Schveighoffer" wrote: > Hm... I always use a newsgroup client, so maybe. But in any case, I've > never known anyone to have been blocked from posting, and the newsgroup > interface does not have any moderation on it. I'd be surprised if anyone >

Re: is this the expected output

2010-12-22 Thread spir
On Wed, 22 Dec 2010 19:40:16 -0500 g g wrote: > Thanks for the answers > what I did is this ( i feel that it is quite clumsy): > >Node* x = cast(Node*) (GC.malloc(Node.sizeof)); > *x = xa; > x.up = curnode; > ... This is not that clumsy (except for you naming!).

Re: double -> double[]... | feature or bug?

2010-12-23 Thread spir
On Thu, 23 Dec 2010 00:34:41 -0600 Christopher Nicholson-Sauls wrote: > On 12/22/10 15:06, Andrej Mitrovic wrote: > > Oooh. That cought me off guard, sorry. > > > > Thanks Steve. > > > > I'll concede that the syntax can be odd at first, but it also enables > some interesting things. For examp

import from subdir

2010-12-23 Thread spir
Hello, Say I have a project with the following tree structure: [app] app.d util.d [test] test.d [data] data.d Is there a way to import util & data from test? Denis -- -- -- -- -- -- -- vit esse estrany ☣ spir.wikidot.com

Re: import from subdir

2010-12-23 Thread spir
On Thu, 23 Dec 2010 05:26:57 -0800 Jonathan M Davis wrote: > On Thursday 23 December 2010 04:38:56 spir wrote: > > Hello, > > > > Say I have a project with the following tree structure: > > > > [app] > > app.d > > util.d > &

Re: double -> double[]... | feature or bug?

2010-12-23 Thread spir
On Thu, 23 Dec 2010 13:38:30 -0500 "Steven Schveighoffer" wrote: > I think it's intentional, and I agree that I've never used or thought > "gee, I wish D did this". I wouldn't be sorry to see it go. In fact, I'd > advocate for getting rid of it. It creates a hidden allocation, which I'm

Re: import from subdir

2010-12-23 Thread spir
On Thu, 23 Dec 2010 12:54:42 -0800 Jonathan M Davis wrote: > What you're trying to do is pretty abnormal really, as far as your average > module goes. I assume that you're writing a test app which needs access to > the > main body of code and are trying to find a way to point it to that code

Re: std.encoding Usage

2010-12-24 Thread spir
On Fri, 24 Dec 2010 18:33:04 + (UTC) Mandeep Singh Brar wrote: > Hi, > > Can you please help me/point me to the usage for std.encoding > package.I think i was successfully able to encode a string into > byte array using the following code: > string x = "test"; > ubyte[] buffe

testing bits in sequence

2010-12-26 Thread spir
Hello, I need to test in sequence the bits of an unsigned int (see below more precision), and move in a tree accordingly. Since there are 2 possible branches at every step, they are encoded in a [2] array, indexed by bit. I am looking for the fastest way to get that bit. To run backwards (MSB

Re: testing bits in sequence

2010-12-26 Thread spir
On Sun, 26 Dec 2010 13:40:22 +0100 "Simen kjaeraas" wrote: > > foreach (i ; 0..BIT_SIZE) { > > mask = MASKS[i]; > > bit = !!(code & mask); > > node = node.nodes[bit]; > > } > > But as you see masking that way lets a value of 2^i, not 1, in the > > 'true' case, wh

subclassing templated class

2010-12-26 Thread spir
Hello, If I have class Node (Element) {...} can I subtype it like with class Leaf (Element) : Node (Element) {...} or such? Denis -- -- -- -- -- -- -- vit esse estrany ☣ spir.wikidot.com

Re: subclassing templated class

2010-12-26 Thread spir
On Sun, 26 Dec 2010 17:54:22 +0300 Stanislav Blinov wrote: > > Hello, > > > > If I have > > class Node (Element) {...} > > can I subtype it like with > > class Leaf (Element) : Node (Element) {...} > > or such? > > > > Denis > > Absolutely: > > class Leaf(Element) : Node!Element {...}

Re: Creating an array of unique elements

2010-12-27 Thread spir
On Mon, 27 Dec 2010 05:22:14 -0200 Guilherme Vieira wrote: > Right now I'm wondering how's the best way to create a dynamic array object > which will only accept "unique" elements (i.e., elements != from the > existing elements in the array). (Take my words with precaution because I don not know

dynamic array capacity

2010-12-29 Thread spir
Hello, Is there a common idiom to pre-allocate a dynamic array. I mean allocating to avoid numerous re-allocations in loop, not setting length & filling content. The differences are: (0) no content --> no init (1) one can simply append, instead of setting elements at defined indices (2) one can a

Re: dynamic array capacity

2010-12-29 Thread spir
On Wed, 29 Dec 2010 11:24:01 -0500 "Steven Schveighoffer" wrote: > On Wed, 29 Dec 2010 07:29:29 -0500, spir wrote: > > > Hello, > > > > Is there a common idiom to pre-allocate a dynamic array. I mean > > allocating to avoid numerous re-allocations in

Re: dynamic array capacity

2010-12-29 Thread spir
On Wed, 29 Dec 2010 11:24:01 -0500 "Steven Schveighoffer" wrote: > On Wed, 29 Dec 2010 07:29:29 -0500, spir wrote: > > > Hello, > > > > Is there a common idiom to pre-allocate a dynamic array. I mean > > allocating to avoid numerous re-allocations in

Re: dynamic array capacity

2010-12-29 Thread spir
On Wed, 29 Dec 2010 13:48:48 -0500 "Steven Schveighoffer" wrote: > On Wed, 29 Dec 2010 13:14:29 -0500, spir wrote: > > > I've done some timings using reserve and Appender. Seems not to work on > > my use case (decomposition of a string [actually a sequence o

Re: ChainImpl save method

2010-12-29 Thread spir
On Wed, 29 Dec 2010 15:35:31 -0500 "Steven Schveighoffer" wrote: > Yes. Inside a template, the name of the template is synonymous with the > template instance being instantiated. > > So for example: > > struct S(T) > { > void foo(){ S s; // this is of type S!T > } > } Good to know ;

Re: Examples using Tango

2010-12-30 Thread spir
On Thu, 30 Dec 2010 01:42:27 -0500 bearophile wrote: > > Overall, it sounds like no one should be using D2 yet unless they have a > > fetish for arrowhead wounds in their back. Well, I don't have this impression in practice. Sure, on D lists, we discuss only the issues. But I use D2 everyda

discrimination of constructors with same number of parameters

2010-12-30 Thread spir
Hello, When 2 constructors (*) accept the same number of parameters, the only remaining discrimination is type. Right? But some language types (or machine types) can have very diverse _human_ semantics, and thus be used for various purposes which should, but cannot, be considered different:

Re: discrimination of constructors with same number of parameters

2010-12-30 Thread spir
On Thu, 30 Dec 2010 03:01:52 -0800 Jonathan M Davis wrote: > On Thursday 30 December 2010 02:50:55 spir wrote: > > Hello, > > > > > > When 2 constructors (*) accept the same number of parameters, the only > > remaining discrimination is type. Right? But so

Re: discrimination of constructors with same number of parameters

2010-12-30 Thread spir
> nothing concrete has come out yet. I hope to see something to solve problems > > like spir ones. > > > > > > > and it would be a pretty fragile one IMHO anyway. > > > > Please, explain better. > > > > Bye, > > bearophile > > > >

Re: discrimination of constructors with same number of parameters

2010-12-30 Thread spir
>> Phobos-based typedef replacement (based on structs + alias this), but > >> nothing concrete has come out yet. I hope to see something to solve > >> problems like spir ones. > >> > >> > >> > and it would be a pretty fragile one IMHO anyway. &

Re: discrimination of constructors with same number of parameters

2010-12-30 Thread spir
On Thu, 30 Dec 2010 08:04:29 -0500 sybrandy wrote: > Why not have something like this: > > this (int[] data, string text, bool isMessage = false) {...} > > Then, if you just pass in two parameters you treat it as a filename and > if you pass in a "true" for the third parameter, it's a message.

Re: discrimination of constructors with same number of parameters

2010-12-30 Thread spir
On Thu, 30 Dec 2010 08:15:51 -0500 bearophile wrote: > > But some language types (or machine types) can have very diverse _human_ > > semantics, and thus be used for various purposes which should, but cannot, > > be considered different: > > You may wrap your data in a struct. Yes, thank yo

Re: discrimination of constructors with same number of parameters

2010-12-30 Thread spir
On Thu, 30 Dec 2010 17:10:00 +0100 "Jérôme M. Berger" wrote: > Steven Schveighoffer wrote: > > What I would suggest is static factory methods. The issue with any kind > > of typedef (be it with the soon-to-be-deprecated typedef keyword or with > > a proxy struct), is that what does this mean? >

Re: discrimination of constructors with same number of parameters

2010-12-30 Thread spir
On Thu, 30 Dec 2010 16:33:39 -0200 Guilherme Vieira wrote: > When I create factory methods like those proposed in this thread, I feel > like I'm hijacking a core aspect of the language. Goddamn it, it's the > constructor! IMHO, everybody expects to construct things.. using > constructors (unless

Re: discrimination of constructors with same number of parameters

2010-12-30 Thread spir
On Thu, 30 Dec 2010 14:26:21 -0500 "Steven Schveighoffer" wrote: > On Thu, 30 Dec 2010 14:08:49 -0500, spir wrote: > > > On Thu, 30 Dec 2010 16:33:39 -0200 > > Guilherme Vieira wrote: > > > >> When I create factory methods like those proposed in th

Re: dmd compile with imported modules

2011-01-01 Thread spir
On Sat, 1 Jan 2011 13:34:47 + (UTC) useo wrote: > Hey guys, > > I've the following problem... when I write a simple class, for > example: > > ... > module myclasses.exampleClass; > > class exampleClass { > void writeHelloWorld() { > writeln("Hello World"); > } > > And import myclasses.exa

terminology: "l-value" & "r-value"

2011-01-04 Thread spir
Hello, I'm bluffed by the 2 terms "l-value" & "r-value" used in C-line language common terminologies. I think I guess what they mean, but I don't understand the need for such absconse idioms. Why not: l-value <-> variable r-value <-> value (or expression) ? I guess (*p) is consi

Re: terminology: "l-value" & "r-value"

2011-01-04 Thread spir
On Tue, 4 Jan 2011 17:56:53 + (UTC) "Manfred_Nowak" wrote: > > They describe which side of the equation they are on > > arg, no! please replace "equation" by "assignExpression". lol, great! this is one of the reasons why in my dream language, assignment would be denoted by any other sign

Re: File.size() is a ulong

2011-01-09 Thread spir
On Sun, 09 Jan 2011 08:29:47 -0500 bearophile wrote: > From a recent update in File I've seen that size() returns an ulong, given by > seek(): > http://www.dsource.org/projects/phobos/browser/trunk/phobos/std/stdio.d?rev=2284#L585 > http://www.dsource.org/projects/phobos/browser/trunk/phobos/std

use of regex

2011-01-09 Thread spir
Hello, After getting a MatchResult by calling match(source, engine): Seems that, if match has failed, calling result.hit() throws an assertion error. Then, how can I know whether match was successful? As there is always a matchResult object returned. I'm looking for a kind of success.failure fl

use of regex -- PS

2011-01-09 Thread spir
Hello again, I also have an issue with the func 'match': instead of simply trying to match and fail if not found, it seems to search for a matching snippet all along the source: what a method 'find' or 'search' usually does, as opposed to 'match' precisely. Thus, i'm forced to prefix all regex

Re: What's wrong with this code?

2011-01-11 Thread spir
On 01/11/2011 01:11 PM, bearophile wrote: Dmitry Olshansky: Or more precisely, in Phobos. There is no such requirement in D, I may suggest you stop using such a general and assertive posts, so not to confuse anyone. Let's create ecosystem-wide name requirements for D code, then! :-) The Phob

about float & double

2011-01-18 Thread spir
Hello, Is there somewhere a (clear) doc about float/double internals? Some more particuliar questions: What is the internal bit layout? (mantissa, sign, exponent) Can I assume the "integral range" is [-2^(m-1) .. 2^⁽m-1)-1], where m is the number of mantissa bits? What are the values used t

Re: Why we need scope(success) if I can write at the end?

2011-01-21 Thread spir
On 01/21/2011 02:18 PM, tamir wrote: or what's the differents between theese two: void transactionalCreate(string filename) { string tempFilename = filename - ".fragment"; scope(success) { std.file.rename(tempFilename, filename); } auto f = File(tempFilename, "w"); } and: void tr

Re: Why we need scope(success) if I can write at the end?

2011-01-21 Thread spir
On 01/21/2011 09:56 PM, Jonathan M Davis wrote: On Friday, January 21, 2011 05:18:15 tamir wrote: or what's the differents between theese two: void transactionalCreate(string filename) { string tempFilename = filename - ".fragment"; scope(success) { std.file.rename(tempFilename, filen

throws(statement, ErrorType)

2011-01-22 Thread spir
How to write a predicate like: assert( throws(someStatement, ErrorType) ); ? Meaning a kind of builtin shortcut for: try: someStatement; throw new SomeCustomError(); catch (ErrorType _) {} that would also have the advantage of beeing usable as assert

Re: throws(statement, ErrorType)

2011-01-22 Thread spir
On 01/23/2011 05:45 AM, Andrej Mitrovic wrote: *There are several of those, like assertExcThrown, etc. Try searching the newsgroups for std.unittest or std.datetime and there should be a link to the source if you want it right now. Thank you, Andrej. Denis _ vita es estrany spi

Re: throws(statement, ErrorType)

2011-01-23 Thread spir
On 01/23/2011 09:47 AM, bearophile wrote: spir: How to write a predicate like: assert( throws(someStatement, ErrorType) ); Are you using Design By Contract a lot? Contracts need to contain asserts only... Bye, bearophile No, not yet. I don't see your point.

Re: throws(statement, ErrorType)

2011-01-23 Thread spir
e current name of the function that spir is looking for. Thank all for your answers. Seems I'll have to wait a bit. Pointer to the current code? (I'm very curious of how assertThrown works, actually asked about throws(statement, ErrorType) because I have no idea how to craft it myself

Re: Naming Conventions & Style Guide?

2011-01-23 Thread spir
On 01/23/2011 06:05 AM, %u wrote: Hmm.. I thought naming enums with capital letters was a standard thing in D land. I prefer them that way since they're constants, and since I almost always use a tag for an enum I never mistake it for anything else. YMMV. Huh, I guess now I see why they are the

Re: Naming Conventions & Style Guide?

2011-01-23 Thread spir
On 01/23/2011 06:28 AM, Jonathan M Davis wrote: The problem is that constants are used all over the place in D - far more than you'd use in most other languages (primarily because of CTFE, I belive). If you use all-caps for stuff like enums, then you're constantly using variables which are all in

Re: throws(statement, ErrorType)

2011-01-23 Thread spir
On 01/23/2011 12:36 PM, Jonathan M Davis wrote: On Sunday 23 January 2011 03:14:48 spir wrote: On 01/23/2011 06:32 AM, Jonathan M Davis wrote: On Saturday 22 January 2011 20:45:14 Andrej Mitrovic wrote: *There are several of those, like assertExcThrown, etc. Try searching the newsgroups for

Re: throws(statement, ErrorType)

2011-01-23 Thread spir
On 01/23/2011 12:36 PM, Jonathan M Davis wrote: On Sunday 23 January 2011 03:14:48 spir wrote: On 01/23/2011 06:32 AM, Jonathan M Davis wrote: On Saturday 22 January 2011 20:45:14 Andrej Mitrovic wrote: *There are several of those, like assertExcThrown, etc. Try searching the newsgroups for

Re: non-constant error for module AA"s

2011-01-24 Thread spir
On 01/24/2011 04:45 PM, Andrej Mitrovic wrote: Is this a bug? import std.stdio; string[string] values = ["abc":"abc", "def":"def"]; void main() { string[string] values2 = ["abc":"abc", "def":"def"]; } test.d(3): Error: non-constant expression ["abc":"abc","def":"def"] What's non-consta

Re: non-constant error for module AA"s

2011-01-25 Thread spir
On 01/25/2011 08:54 AM, bearophile wrote: Andrej Mitrovic: It's interesting that enum works but immutable doesn't. enum will do, Thanks. But there are some problems with enum AAs. Take a look at this little program: enum int[int] aa = [1:2, 3:4]; int foo(int x) { return aa[x]; } void ma

Re: non-constant error for module AA"s

2011-01-25 Thread spir
On 01/25/2011 09:13 AM, Lars T. Kyllingstad wrote: On Mon, 24 Jan 2011 10:45:03 -0500, Andrej Mitrovic wrote: Is this a bug? import std.stdio; string[string] values = ["abc":"abc", "def":"def"]; void main() { string[string] values2 = ["abc":"abc", "def":"def"]; } test.d(3): Error: non

template magic

2011-01-25 Thread spir
Hello, This post is about the various roles D templates can play. I had to write a higher-order function (hof) that takes as parameter a func which itself returns any kind of type. Thus, the hof is also templated. (Below the simplest case I could find as example.) Unlike in functional style,

Re: template magic

2011-01-25 Thread spir
On 01/25/2011 06:03 PM, Simen kjaeraas wrote: Of course, given a non-template function, it is impossible to safely pass a function to it. Dont you count this as typesafe function passing? void writeRounding (int function (float) roundingScheme) {...} Denis -- _ vita es

override '.' member access

2011-01-25 Thread spir
Hello, Cannot find corresponding opSomething method, if any. (opDispatch seems to specialise for method call.) Else, how to catch obj.member? Denis -- _ vita es estrany spir.wikidot.com

Re: override '.' member access

2011-01-25 Thread spir
On 01/25/2011 10:29 PM, Simen kjaeraas wrote: spir wrote: Hello, Cannot find corresponding opSomething method, if any. (opDispatch seems to specialise for method call.) Else, how to catch obj.member? opDispatch is likely what you want. with the @property annotation, it will readily support

Re: override '.' member access

2011-01-25 Thread spir
On 01/25/2011 08:44 PM, Jonathan M Davis wrote: On Tuesday, January 25, 2011 11:33:24 spir wrote: Hello, Cannot find corresponding opSomething method, if any. (opDispatch seems to specialise for method call.) Else, how to catch obj.member? [...] You can overload a number of operators, but

Re: override '.' member access

2011-01-26 Thread spir
On 01/26/2011 12:05 AM, spir wrote: On 01/25/2011 10:29 PM, Simen kjaeraas wrote: spir wrote: Hello, Cannot find corresponding opSomething method, if any. (opDispatch seems to specialise for method call.) Else, how to catch obj.member? opDispatch is likely what you want. with the

Re: override '.' member access

2011-01-26 Thread spir
On 01/26/2011 01:06 AM, Simen kjaeraas wrote: spir wrote: On 01/25/2011 10:29 PM, Simen kjaeraas wrote: spir wrote: Hello, Cannot find corresponding opSomething method, if any. (opDispatch seems to specialise for method call.) Else, how to catch obj.member? opDispatch is likely what

array of elements of various sybtypes

2011-01-26 Thread spir
Hello, This fails: class T0 {} class T1 : T0 {} class T2 : T0 {} unittest { auto t1 = new T1(); auto t2 = new T2(); T0[] ts = [t1, t2]; } Error: cannot implicitly convert expression (t1) of type __trials__.T0 to __trials__.T2 Error: cannot implicitly convert expression ([(__error

Re: array of elements of various sybtypes

2011-01-26 Thread spir
On 01/26/2011 06:27 PM, spir wrote: Hello, This fails: class T0 {} class T1 : T0 {} class T2 : T0 {} unittest { auto t1 = new T1(); auto t2 = new T2(); T0[] ts = [t1, t2]; } Error: cannot implicitly convert expression (t1) of type __trials__.T0 to __trials__.T2 Error: cannot implicitly

Re: array of elements of various sybtypes

2011-01-26 Thread spir
On 01/26/2011 07:32 PM, Jonathan M Davis wrote: On Wednesday, January 26, 2011 09:30:17 spir wrote: On 01/26/2011 06:27 PM, spir wrote: Hello, This fails: class T0 {} class T1 : T0 {} class T2 : T0 {} unittest { auto t1 = new T1(); auto t2 = new T2(); T0[] ts = [t1, t2]; } Error: cannot

Re: array of elements of various sybtypes

2011-01-26 Thread spir
On 01/26/2011 07:26 PM, Steven Schveighoffer wrote: On Wed, 26 Jan 2011 12:30:17 -0500, spir wrote: On 01/26/2011 06:27 PM, spir wrote: Hello, This fails: class T0 {} class T1 : T0 {} class T2 : T0 {} unittest { auto t1 = new T1(); auto t2 = new T2(); T0[] ts = [t1, t2]; } Error: cannot

Re: array of elements of various sybtypes

2011-01-26 Thread spir
On 01/26/2011 07:23 PM, Steven Schveighoffer wrote: On Wed, 26 Jan 2011 12:27:37 -0500, spir wrote: Hello, This fails: class T0 {} class T1 : T0 {} class T2 : T0 {} unittest { auto t1 = new T1(); auto t2 = new T2(); T0[] ts = [t1, t2]; } Error: cannot implicitly convert expression (t1) of

<    1   2   3   4   5   >